| Halaman yang terkait dengan |
| Modul:Adjacent stations |
|---|
| (bicara | bak pasir | subhalaman) |
| {{Infobox station}} |
| (bicara | bak pasir | kasus uji) |
| {{Station link}} |
| (bicara | bak pasir | kasus uji) |
| {{Station icon link}} |
| (bicara | bak pasir | kasus uji) |
| {{Rail color}} |
| (bicara | bak pasir | kasus uji) |
| {{Line link}} |
| (bicara | bak pasir | kasus uji) |
| {{Short line link}} |
| (bicara | bak pasir | kasus uji) |
| {{Rail icon}} |
| (bicara | bak pasir | kasus uji) |
| {{Rail color box}} |
| (bicara | bak pasir | kasus uji) |
| {{Adjacent stations}} |
| (bicara | bak pasir | kasus uji) |
| {{Line terminus link}} |
| (bicara | bak pasir | kasus uji) |
| Modul ini menggunakan Lua: |
| Modul Lua ini digunakan pada 9.600+ halaman dan perubahannya kemungkinan memicu perubahan massal pada semua halaman yang menggunakannya. Uji cobalah di subhalaman /bak pasir atau /kasus uji Modul:Adjacent stations, atau bak pasir modul Anda. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya. |
| Modul ini dilindungi. Modul ini sangat mencolok yang digunakan oleh banyak halaman, atau sangat sering disubstitusikan. Karena vandalisme atau kesalahan akan mempengaruhi banyak halaman, dan suntingan kecil dapat memberi beban besar pada server, modul ini dilindungi dari penyuntingan. |
Modul ini mengimplementasikan {{Adjacent stations}}, {{Rail icon}}, {{Rail color box}}, {{Line link}}, {{Station link}} dan {{Rail color}}. Harap baca dokumentasi templatnya untuk informasi lebih lanjut. (Petunjuk fungsi konversi convert ada di dokumentasi {{Adjacent stations}}.)
Templat di atas bergantung pada data yang disimpan dalam subhalaman modul ini (list). Contoh, {{Rail icon}} menghasilkan
menggunakan Module:Adjacent stations/MTR.
Dapat membuat atau menyunting data dengan contoh yang ada, tetapi Anda setidaknya perlu sedikit pengetahuan tentang Lua. Jika Anda menjadi pemrogram Lua, Anda bisa melewatinya.
IstilahIstilah
Untuk pemahaman yang lebih mendalam tentang Lua, lihat mw:Extension:Scribunto/Lua reference manual.
- Jenis data Lua adalah boolean, string, number, dan table.
- Boolean:
trueataufalse. - Untaian teks, yang disebut string, disimpan sebagai karakter. Dalam Lua, string ditandai dalam tanda petik dua (
"Ini string"). - Number adalah data yang berupa bilangan real, seperti
0.5atau42. - Table adalah struktur yang mengandung objek lain, termasuk tabel yang lain
- Tabel kosong ditandai dengan
{} - Tabel biasanya memiliki keys dan values, biasanya seperti ini:
["key"] = value; tiap pasangannya dipisahkan oleh koma. {"text", "more text"}ekuivalen dengan{[1] = "text", [2] = "more text"}.
- Tabel kosong ditandai dengan
- Boolean:
- Variable:
local variable_name = "value". - Whitespace termasuk tab, spasi, ganti baris. Tidak masalah dalam Lua, tetapi sering kali tidak nyaman dibaca jika diabaikan.
- Return (seperti
return variable_name) membuat eksekusi fungsi tersebut diakhiri dan melaporkannya sebagaivariable_name.
Struktur dasarStruktur dasar
- Dua entri yang diperlukan adalah "station format" dan "lines".
- "system title" adalah teks yang ada di tengah tajuk.
- "station format" digunakan untuk menuliskan format stasiun dan pengecualiannya.
- "lines" berisi daftar nama jalur kereta apinya beserta stasiun sebelum dan sesudahnya
- "line title" adalah nama jalur kereta api; "left terminus" adalah nama stasiun terminus sebelah kiri, dan "right terminus" adalah nama stasiun terminus sebelah kanan.
- Each "color" entry is the colour of the line.
Di bawah ini contoh pemakaiannya dalam Module:Adjacent stations/Taiwan High Speed Rail:
localx="%1 station" localp={ ["system title"]="[[Taiwan High Speed Rail]]", ["system icon"]="[[File:Taiwan High Speed Rail Logo(Log Only).svg|18px|link=Taiwan High Speed Rail|alt=Taiwan High Speed Rail]]", ["system color"]="c35617", ["station format"]={ "%1 HSR station", ["Taipei"]="Taipei main station", ["Nangang"]=x, ["Banqiao"]=x }, ["lines"]={ ["_default"]={ ["title"]="[[Taiwan High Speed Rail|THSR]]", ["color"]="c35617", ["left terminus"]="Nangang", ["right terminus"]="Zuoying" } } } returnp
Dokumentasi di atas ditransklusikan dari Modul:Adjacent stations/doc. (sunting | riwayat)
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
require('strict') localp={} locallang='en-GB'-- local default language -- Below these comments: Internationalization table -- How to translate this module (for languages without variants): -- • Characters inside single and double quotation marks are called strings. -- The strings in this i18n table are used as output. -- • Strings within square brackets are keys. -- • Strings are concatenated (joined) with two dots. -- • Set the string after «local lang =» to your language's code. -- Change the first key after "i18n" (usually "en-GB") to the same thing. -- • For each string which is not inside a function, translate it directly. -- • Strings with keys named "format" are Lua regular expressions. -- «()» is a match; «.+» means all characters; «%s+» means all spaces. -- • For each string which is concatenated to the variable «var», -- translate the phrase assuming that «var» will be a noun. -- • Remove any unnecessary translations. locali18n=require("Module:Adjacent stations/i18n") localfunctiongetData(system,verify) ifverifythen localtitle=mw.title.new('Module:Adjacent stations/'..system-- .. '/sandbox' ) ifnot(titleandtitle.exists)thenreturnnilend end returnrequire('Module:Adjacent stations/'..system-- .. '/sandbox' ) end localfunctiongetLine(data,lineN) iflineNthen ifdata['aliases']then lineN=data['aliases'][mw.ustring.lower(lineN)]orlineN end localdefault=data['lines']['_default']or{} localline=data['lines'][lineN]or{} fork,vinpairs(default)do ifvthenline[k]=line[k]orvend end line['title']=line['title']andmw.ustring.gsub(line['title'],'%%1',lineN) returnline,lineN end end localfunctiongetColor(data,system,line,Type,frame) ifsystemthen iflinethenreturnframe:expandTemplate{title=system..' color',args={line,['branch']=Type}}end returnframe:expandTemplate{title=system..' color'} else line=(getLine(data,line)) localdefault=data['lines']['_default'] iflineordefaultthen default=defaultor{} ifnotlinethenline=mw.clone(default)end localcolor=line['color']orline['background color']ordefault['color']ordefault['background color']ordata['system color'] localType_value=Typeandline['types']and(line['types'][Type]andline['types'][Type]['color']) ifType_valuethencolor=Type_valueend returncolor end return(defaultand(default['color']ordefault['background color'])ordata['system color']or'') end end locallineN,typeN localfunctionsomethingMissing(name,key,formats) localformatKeys={} forkinpairs(formats)do table.insert(formatKeys,k) end returnname..' was "'..key..'" but neither an entry for it nor a default was found. Choices were: '..table.concat(formatKeys,', ') end localfunctiongetStation(station,_Format) iftype(_Format)=='table'then locallineNformats=_Format _Format=lineNformats[lineN]orlineNformats[1] ifnot_Formatthen error(somethingMissing('lineN',lineN,lineNformats)) elseiftype(_Format)=='table'then localtypeNformats=_Format _Format=typeNformats[typeN]ortypeNformats[1] ifnot_Formatthen error(somethingMissing('typeN',typeN,typeNformats)) end end end iftypeNthen_Format=mw.ustring.gsub(_Format,'%%3',typeN)end iflineNthen_Format=mw.ustring.gsub(_Format,'%%2',lineN)end return(mw.ustring.match(_Format,'%[%[.+%]%]'))and(mw.ustring.gsub(_Format,'%%1',station))ortable.concat({'[[',mw.ustring.gsub(_Format,'%%1',station),'|',station,']]'}) end localfunctiongetTerminusText(var,Format) localfunctionsubst(var1,var2) -- var1 is the terminus or table of termini; var2 is the key for the table of termini returntype(var1)=='string'andgetStation(var1,(Format[var1]orFormat[1])) ortype(var1)=='table'and#var1>0andgetStation(var1[var2],(Format[var1[var2]]orFormat[1])) or'' end ifFormatthen iftype(var)=='string'then returnsubst(var) elseiftype(var)=='table'and#var>0then localt={subst(var,1)} fori=2,#var-1do t[i]=i18n[lang]['comma'](subst(var,i)) end if#var>1thent[#var]=i18n[lang]['or'](subst(var,#var))end ifvar['via']then ifi18n[lang]['via-first']then table.insert(t,1,i18n[lang]['via'](subst(var,'via'))) else table.insert(t,i18n[lang]['via'](subst(var,'via'))) end end returntable.concat(t) else return'' end else returnvaror'' end end functionp._main(_args)-- Arguments are processed here instead of the main function localyesno=require('Module:Yesno') localtrimq=require('Module:Trim quotes')._trim localboolean={ ['oneway-left']=true, ['oneway-right']=true, ['reverse']=true, ['reverse-left']=true, ['reverse-right']=true } localargs={}-- Processed arguments localindex={}-- A list of addresses corresponding to number suffixes in the arguments fork,vinpairs(_args)do-- Maps each raw argument to processed arguments by string matching _args[k]=v:match('^%s*(.-)%s*$') if_args[k]and_args[k]~=''then locala=mw.ustring.match(k,'^(.*%D)%d+$')ork-- The parameter; address 1 can be omitted localb=tonumber(mw.ustring.match(k,'^.*%D(%d+)$'))or1-- The address for a given argument; address 1 can be omitted ifboolean[a]then v=yesno(v) end ifnotargs[b]then args[b]={[a]=v} table.insert(index,b) elseifargs[b][a]then returnerror(i18n[lang]['error_duplicate'](a..b)) else args[b][a]=v end end end table.sort(index) localfunctionsmall(s,italic) returnitalicand'<div class="isA">'..s..'</div>' or'<div class="smA">'..s..'</div>' end localstyle={-- Style for each cell type ['header cell']='class="hcA"|', ['header midcell']='colspan="3" class="hmA"|', ['body cell']='class="bcA"|', ['body banner']='class="bbA notheme" style="color:inherit;background-color:#', } localfunctionrgb(var) ifvar:len()==3then return{tonumber(var:sub(1,1),16)*17,tonumber(var:sub(2,2),16)*17,tonumber(var:sub(2,2),16)*17} elseifvar:len()==6then return{tonumber(var:sub(1,2),16),tonumber(var:sub(3,4),16),tonumber(var:sub(5,6),16)} end return{} end localdata={}-- A table of data modules for each address localnoclearclass=(((_args.noclearor'')~='')and' adjacent-stations-noclear'or'') localwikitable={'{| class="wikitable adjacent-stations'..noclearclass..'"'} fori,vinipairs(index)do -- If an address has a system argument, indexes the data module data[v]=args[v]['system']andgetData(args[v]['system']) -- If an address has no system, the row uses data from the previous address ordata[index[i-1]] or(args[v]['header']andgetData(args[index[i+1]]['system'])) orerror(i18n[lang]['error_unknown'](args[v]['system'])) locallang=data[v]['lang']orlang ifargs[v]['system']andnotargs[v]['hide-system']then-- Header row localstop_noun=data[v]['header stop noun']ori18n[lang]['stop_noun'] table.insert(wikitable,table.concat({'\n|-', '\n! scope="col" ',style['header cell'],i18n[lang]['preceding'](stop_noun), '\n! scope="col" ',style['header midcell'],(data[v]['system icon']anddata[v]['system icon']..' 'or''),(data[v]['system title']or('[['..args[v]['system']..']]')), '\n! scope="col" ',style['header cell'],i18n[lang]['following'](stop_noun) })) table.insert(wikitable,'') table.insert(wikitable,'') table.insert(wikitable,'') end ifargs[v]['header']then-- Subheader table.insert(wikitable,'\n|-\n!colspan="5" class="hmA"|'..args[v]['header']) table.insert(wikitable,'') table.insert(wikitable,'') table.insert(wikitable,'') end ifargs[v]['line']orargs[v]['left']orargs[v]['right']orargs[v]['nonstop']then ifnotargs[v]['line']andi>1andnotargs[v]['system']then args[v]['line']=args[index[i-1]]['line'] end lineN=args[v]['line']or'_default' typeN=args[v]['type'] ifdata[v]['aliases']then lineN=data[v]['aliases'][mw.ustring.lower(lineN)]orlineN iftypeNthentypeN=data[v]['aliases'][mw.ustring.lower(typeN)]ortypeNend end -- get the line table localline=data[v]['lines']and(mw.clone(data[v]['lines'][lineN])orerror(i18n[lang]['error_unknown'](args[v]['line'])))orerror(i18n[lang]['error_line']) localdefault=data[v]['lines']['_default']or{} line['title']=line['title']ordefault['title']or'' line['title']=mw.ustring.gsub(line['title'],'%%1',lineN) -- cell across row for non-stop service ifargs[v]['nonstop']then table.insert(wikitable, table.concat({'\n|-\n|colspan="5" ', style['body cell'], ((args[v]['nonstop']=='former')andi18n[lang]['nonstop_past']ori18n[lang]['nonstop_present'])(p._box({data=data[v],line=lineN,Type=typeN,inline='yes'})) }) ) table.insert(wikitable,'') table.insert(wikitable,'') table.insert(wikitable,'') else localFormat=data[v]['station format']ori18n[lang]['error_format'] localcolor,color_2,background_color,circular localType=line['types']andline['types'][typeN]-- get the line type table ifTypethen ifType['color']then -- line color is used as background if there is no background color in the line type table background_color=Type['background color']orline['color'] color=Type['color'] color_2=Type['color2']orcolor else background_color=Type['background color']orline['background color'] color=line['color']ordefault['color']or'' color_2=line['color2']orcolor end ifType['circular']then -- Type may override the circular status of the line circular=Type['circular'] end else background_color=line['background color'] color=line['color']ordefault['color']or'' color_2=line['color2']orcolor circular=line['circular'] end -- Alternate termini can be specified based on type localsideCell={true,true} fori,binipairs({'left','right'})do ifnotargs[v][b]then-- If no station is given on one side, the station is assumed to be the terminus on that side local_through=args[v]['through-'..b]orargs[v]['through'] local_through_data=getLine(data[v],_through) if_through_datathen_through=_through_data['title']or_throughend sideCell[i]=_throughand"''"..i18n[lang]['through'](trimq(_through)).."''" or"''"..trimq((args[v]['reverse-'..b] orargs[v]['reverse'])andi18n[lang]['reverse'] ori18n[lang]['terminus']).."''" else localterminusT localterminusN=TypeandType[b..' terminus']orline[b..' terminus'] -- If the terminus table has more than one numbered key or has the via key then the table shows only the default termini, since terminusN[2] cannot be used and terminusN[via] is reserved iftype(terminusN)=='string'or(type(terminusN)=='table'and(terminusN[2]orterminusN['via']))then ifargs[v]['to-'..b]then terminusT=args[v]['to-'..b] local_or=mw.ustring.match(terminusT,i18n[lang]['or-format']) if_orthen terminusT=mw.ustring.gsub(terminusT,i18n[lang]['or-format'],'\127_OR_\127') terminusT=mw.ustring.gsub(terminusT,i18n[lang]['comma-format'],'\127_OR_\127') end local_via=(mw.ustring.match(terminusT,i18n[lang]['via-format'])) if_viathen terminusT=mw.ustring.gsub(terminusT,i18n[lang]['via-format'],'') terminusT=mw.text.split(terminusT,'\127_OR_\127') terminusT['via']=_via elseif_orthen terminusT=mw.text.split(terminusT,'\127_OR_\127') end else terminusT=terminusN end elseiftype(terminusN)=='table'then terminusT=terminusN[args[v]['to-'..b]]orterminusN[args[v]['to']]orterminusN[1] end localmainText=args[v]['note-'..b]andgetTerminusText(args[v][b],Format)..small(args[v]['note-'..b])orgetTerminusText(args[v][b],Format) localsubText=(args[v]['oneway-'..b]orline['oneway-'..b])andi18n[lang]['oneway'] orargs[v][b]==terminusTandi18n[lang]['terminus'] orcircularandterminusT ori18n[lang]['towards'](getTerminusText(terminusT,Format)) subText=small(subText,true) sideCell[i]=mainText..subText end end table.insert(wikitable,'\n|-') table.insert(wikitable,'\n|'..style['body cell']..sideCell[1]) table.insert(wikitable,table.concat({'\n|',style['body banner'],color,'"|', '\n|',(background_colorand'class="bcA" style="background-color:rgba('..table.concat(rgb(background_color),',')..',.2)"|'orstyle['body cell']),line['title'], -- Type; table key 'types' in subpages (datatype table, with strings as keys). If table does not exist then the input is displayed as the text (typeNand'<div>'..(TypeandType['title']ortypeN)..'</div>'or''), -- Note-mid; table key 'note-mid' in subpages. Overridden by user input ((args[v]['note-mid']andsmall(args[v]['note-mid']))or(TypeandType['note-mid']andsmall(Type['note-mid']))or(line['note-mid']andsmall(line['note-mid']))or''), -- Transfer; uses system's station link table (args[v]['transfer']andsmall('transfer di '..getTerminusText(args[v]['transfer'],Format),true)or''), '\n|',style['body banner'],color_2,'"|'})) table.insert(wikitable,'\n|'..style['body cell']..sideCell[2]) end end ifargs[v]['note-row']then-- Note ifargs[v]['note-row']:match('^%s*<tr')orargs[v]['note-row']:match('^%s*%|%-')then table.insert(wikitable,'\n'..args[v]['note-row']) else table.insert(wikitable,'\n|-\n|colspan="5" '..style['body cell']..args[v]['note-row']) end table.insert(wikitable,'') table.insert(wikitable,'') table.insert(wikitable,'') end end localfunctioncombine(t,n) ift[n+4]~=''andt[n+4]==t[n]then t[n+4]=''-- The cell in the next row is deleted localrowspan=2 whilet[n+rowspan*4]==t[n]do t[n+rowspan*4]='' rowspan=rowspan+1 end t[n]=mw.ustring.gsub(t[n],'\n|class="','\n|rowspan="'..rowspan..'" class="') end end localM=#wikitable fori=3,M,4docombine(wikitable,i)end fori=4,M,4docombine(wikitable,i)end fori=5,M,4docombine(wikitable,i)end table.insert(wikitable,'\n|}') returntable.concat(wikitable) end localgetArgs=require('Module:Arguments').getArgs localfunctionmakeInvokeFunction(funcName) -- makes a function that can be returned from #invoke, using -- [[Module:Arguments]] returnfunction(frame) localargs=getArgs(frame,{parentOnly=true}) returnp[funcName](args,frame) end end localfunctionmakeTemplateFunction(funcName) -- makes a function that can be returned from #invoke, using -- [[Module:Arguments]] returnfunction(frame) localargs=getArgs(frame,{frameOnly=true}) returnp[funcName](args,frame) end end p.main=makeInvokeFunction('_main') functionp._color(args,frame) localdata=args.data ifargs[1]ordatathen data=dataorgetData(args[1],true) ifnotdatathenreturngetColor(nil,args[1],args[2],args[3],frame)end returngetColor(data,nil,args[2],args[3]) end end p.color=makeInvokeFunction('_color') functionp._box(args,frame) localsystem=args[1]orargs.system lineN=args[2]orargs.line ifnot(systemorlineN)thenreturn''end localline,Type,line_data localinline=args[3]orargs.inline typeN=args.type localdata=args.data ifsystemordatathen data=dataorgetData(system,true) localcolor ifdatathen localdefault=data['lines']['_default']or{} line,lineN=getLine(data,lineN) iftypeNthen typeN=data['aliases']anddata['aliases'][mw.ustring.lower(typeN)]ortypeN Type=line['types']andline['types'][typeN]andline['types'][typeN]['title']ortypeN end color=getColor(data,nil,lineN,typeN) ifinline~='box'then line_data=lineorerror(i18n[lang]['error_unknown'](lineN)) line=line_data['title']ordefault['title']orerror(i18n[lang]['error_missing']('title')) line=mw.ustring.gsub(line,'%%1',lineN) end else color=getColor(nil,system,lineN,typeN,frame) ifinline~='box'then line=frame:expandTemplate{title=system..' lines',args={lineN,['branch']=typeN}} ifmw.text.trim(line)==''thenreturnerror(i18n[lang]['error_unknown'](lineN))end end Type=typeN end localresult ifTypeandType~=''andinline~='box'then ifline==''then line=Type else result=' – '..Type end end ifargs.notethenresult=(resultor'')..' '..args.noteend result=resultor'' ifnotinlinethen-- [[Template:Legend]] result='<div class="legend" style="page-break-inside:avoid;break-inside:avoid-column"><span class="legend-color" style="display:inline-block;min-width:1.25em;height:1.25em;line-height:1.25;margin:1px 0;border:1px solid black;color:inherit;background-color:#'..color..'"> </span> '..line..result..'</div>' elseifinline=='yes'then result='<span style="color:inherit;background-color:#'..color..';border:1px solid #000"> </span> '..line..result elseifinline=='box'then result='<span style="color:inherit;background-color:#'..color..';border:1px solid #000"> </span>'..result elseifinline=='link'then locallink=args.linkormw.ustring.match(line,'%[%[([^%[:|%]]+)[|%]]') iflinkthen result='[['..link..'|<span style="color:inherit;background-color:#'..color..';border:1px solid #000"> </span>]]'..result else result='<span style="color:inherit;background-color:#'..color..';border:1px solid #000"> </span>'..result end elseifinline=='square'then result='<span style="color:#'..color..';line-height:initial">■</span> '..line..result elseifinline=='lsquare'then locallink=args.linkormw.ustring.match(line,'%[%[([^%[:|%]]+)[|%]]') iflinkthen result='[['..link..'|<span style="color:#'..color..';line-height:initial">■</span>]]' else result='<span style="color:#'..color..';line-height:initial">■</span>' end elseifinline=='dot'then result='<span style="color:#'..color..';line-height:initial">●</span> '..line..result elseifinline=='ldot'then locallink=args.linkormw.ustring.match(line,'%[%[([^%[:|%]]+)[|%]]') iflinkthen result='[['..link..'|<span style="color:#'..color..';line-height:initial">●</span>]]' else result='<span style="color:#'..color..';line-height:initial">●</span>' end elseifinline=='small'then result='<span style="color:inherit;background-color:#'..color..'"> </span>'..' '..line..result else localyesno=require("Module:Yesno") locallink=args.linkormw.ustring.match(line,'%[%[([^%[:|%]]+)[|%]]') localborder_color,text_color localcolor_box=data['color box format']ordata['rail box format']or{} ifline_datathen ifline_data['types']andline_data['types'][typeN]then localType_data=line_data['types'][typeN] border_color=Type_data['border color']orline_data['border color']orcolor text_color=Type_data['text color']orline_data['text color'] ifcolor_box=='title'andnotargs[4]then lineN=Type_data['short name']orline_data['short name']orrequire('Module:Delink')._delink{line} else lineN=Type_data['short name']orline_data['short name']orlineN end else border_color=line_data['border color']orcolor text_color=line_data['text color'] ifcolor_box=='title'andnotargs[4]then lineN=line_data['short name']orrequire('Module:Delink')._delink{line} else lineN=line_data['short name']orlineN end end else border_color=color end text_color=text_colorand'#'..text_colororrequire('Module:Color contrast')._greatercontrast{color} localbold=';font-weight:bold' if(yesno(args.bold)==false)thenbold=''end ifinline=='route'then-- [[Template:RouteBox]] iflinkthen result='<span style="color:inherit;background-color:#'..color..';border:.075em solid #'..border_color..';padding:0 .3em">[['..link..'|<span style="color:'..text_color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>]]</span>' else result='<span style="background-color:#'..color..';border:.075em solid #'..border_color..';padding:0 .3em;color:'..text_color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>' end elseifinline=='croute'then-- [[Template:Bahnlinie]] iflinkthen result='<span style="color:inherit;background-color:#'..color..';border:.075em solid #'..border_color..';border-radius:.5em;padding:0 .3em">[['..link..'|<span style="color:'..text_color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>]]</span>' else result='<span style="color:inherit;background-color:#'..color..';border:.075em solid #'..border_color..';border-radius:.5em;padding:0 .3em;color:'..text_color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>' end elseifinline=='xroute'then-- [[Template:Bahnlinie]] iflinkthen result='<span style="border:.075em solid #'..border_color..';border-radius:.5em;padding:0 .3em">[['..link..'|<span style="color:#'..color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>]]</span>' else result='<span style="border:.075em solid #'..border_color..';border-radius:.5em;padding:0 .3em;color:#'..color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>' end elseifinline=='broute'then iflinkthen result='<span style="color:inherit;background-color:#'..color..';border:.075em solid #000;padding:0 .3em">[['..link..'|<span style="color:'..text_color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>]]</span>' else result='<span style="background-color:#'..color..';border:.075em solid #000;padding:0 .3em;color:'..text_color..bold..';font-size:inherit;white-space:nowrap">'..lineN..'</span>' end else-- [[Template:Legend]] (fallback; duplication to simplify logic) result='<div class="legend" style="page-break-inside:avoid;break-inside:avoid-column"><span class="legend-color" style="display:inline-block;min-width:1.25em;height:1.25em;line-height:1.25;margin:1px 0;border:1px solid black;color:inherit;background-color:#'..color..'"> </span> '..line..result..'</div>' end end result=mw.ustring.gsub(result,':%s*#transparent',':transparent') returnresult end end p.box=makeInvokeFunction('_box') functionp._icon(args,frame) localsystem=args[1]orargs.system localdata=args.data ifnotsystemandnotdatathen return end data=dataorgetData(system) localline,line_name=getLine(data,args[2]orargs.line) localicon localicon_format iflinethen localline_type=args[3]orargs.type ifline_typethen line_type=data.aliasesanddata.aliases[mw.ustring.lower(line_type)]orline_type line_type=line.typesandline.types[line_type]-- If there's no type table or entry for this type, then it can't have its own icon icon_format=line_type['icon format']ordata['type icon format'] ifline_type.iconthen icon=line_type.icon end end ifnoticonthen icon=line.icon end -- Only if there is no icon use the icon_format. ifnoticonandnoticon_formatthen icon_format=line['icon format']ordata['line icon format'] end localdefault=data.lines._defaultor{} ificonandstring.find(icon,"%%1")anddefaultanddefault.iconthen icon=mw.ustring.gsub(default.icon,'%%1',line_name) end end ifnoticonthen icon=data['system icon'] end ifnoticon_formatthen icon_format=data['system icon format'] end ificon_formatthen ificon_format~='image'then icon=p._box({data=data,[2]=(args[2]orargs.line),[3]=icon_format,type=(args[3]orargs.type),bold=args.bold,link=args.link},frame) ifargs.namethen iflineandline.titlethen returnicon.." "..line.title end returnicon.." "..data["system title"] end end end localsize=args.size ifsizethen ifmw.ustring.match(size,'%d$')then size='|'..size..'px' else size='|'..size end -- Upright values are to be disabled until there is use of upright scaling in subpages; doesn't seem to work anyway as of 2018-08-10 localregex={ '|%s*%d*x?%d+px%s*([%]|])',-- '|%s*upright=%d+%.?%d*%s*([%]|])', '|%s*upright%s*([%]|])' } ifmw.ustring.match(icon,regex[1])then icon=mw.ustring.gsub(icon,regex[1],size..'%1') -- elseif mw.ustring.match(icon, regex[2]) then -- icon = gsub(icon, regex[2], size .. '%1') -- elseif mw.ustring.match(icon, regex[3]) then -- icon = gsub(icon, regex[3], size .. '%1') else icon=mw.ustring.gsub(icon,'(%[%[[^%]|]+)([%]|])','%1'..size..'%2') end end locallink=args.link iflinkthen ifmw.ustring.match(icon,'|%s*link=[^%]|]*[%]|]')then icon=mw.ustring.gsub(icon,'|%s*link=[^%]|]*([%]|])','|link='..link..'%1') else icon=mw.ustring.gsub(icon,'(%[%[[^%]|]+)([%]|])','%1|link='..link..'%2') end end localalt=args.altorlink ifaltthen ifmw.ustring.match(icon,'|%s*alt=[^%]|]*[%]|]')then icon=mw.ustring.gsub(icon,'|%s*alt=[^%]|]*([%]|])','|alt='..alt..'%1') else icon=mw.ustring.gsub(icon,'(%[%[[^%]|]+)([%]|])','%1|alt='..alt..'%2') end end ifargs.namethen iflineandline.titlethen returnicon.." "..line.title end returnicon.." "..data["system title"] end returnicon end p.icon=makeInvokeFunction('_icon') p['rail icon']=makeTemplateFunction('_icon') functionp._line(args,frame) localsystem=args[1]orargs.system localline=args[2]orargs.line ifnotlinethenreturn''end localType=args[3]orargs.type localdata=args.data ifsystemordatathen data=dataorgetData(system,true) ifdatathen line=(getLine(data,line))orerror(i18n[lang]['error_unknown'](line)) ifTypethen Type=data['aliases']anddata['aliases'][mw.ustring.lower(Type)]orType Type=line['types']andline['types'][Type]andline['types'][Type]['title']orType end line=line['title']orerror(i18n[lang]['error_missing']('title')) else line=frame:expandTemplate{title=system..' lines',args={line,['branch']=Type}} ifmw.text.trim(line)==''thenreturnerror(i18n[lang]['error_unknown'](lineN))end end ifTypeandType~=''then ifline==''then line=Type else line=line..' – '..Type end end returnline end end p.line=makeInvokeFunction('_line') functionp._shortline(args,frame) localsystem=args[1]orargs.system lineN=args[2]orargs.line ifnot(systemorlineN)thenreturn''end localline,Type,line_data typeN=args.type localdata=args.data ifsystemordatathen data=dataorgetData(system,true) ifdatathen localdefault=data['lines']['_default']or{} line,lineN=getLine(data,lineN) iftypeNthen typeN=data['aliases']anddata['aliases'][mw.ustring.lower(typeN)]ortypeN Type=line['types']andline['types'][typeN]andline['types'][typeN]['title']ortypeN end line_data=lineorerror(i18n[lang]['error_unknown'](lineN)) line=line_data['title']ordefault['title']orerror(i18n[lang]['error_missing']('title')) line=mw.ustring.gsub(line,'%%1',lineN) else line=frame:expandTemplate{title=system..' lines',args={lineN,['branch']=typeN}} ifmw.text.trim(line)==''thenreturnerror(i18n[lang]['error_unknown'](lineN))end Type=typeN end localresult ifTypeandType~=''then ifline==''then line=Type else result=' – '..Type end end ifargs.notethenresult=(resultor'')..' '..args.noteend result=resultor'' locallink=args.linkormw.ustring.match(line,'%[%[([^%[:|%]]+)[|%]]') ifline_datathen ifline_data['types']andline_data['types'][typeN]then localType_data=line_data['types'][typeN] lineN=Type_data['short name']orline_data['short name']orlineN else lineN=line_data['short name']orlineN end end iflinkthen result='[['..link..'|'..lineN..']]' else result=lineN end result=mw.ustring.gsub(result,':%s*#transparent',':transparent') returnresult end end p.shortline=makeInvokeFunction('_shortline') functionp._station(args,frame) localsystem=args[1]orargs.system localstation=args[2]orargs.station ifnotstationthenreturn''end lineN=args[3]orargs.line typeN=args[4]orargs.type localdata=args.data ifsystemordatathen data=dataorgetData(system,true) ifdatathen local_Format=data['station format'][station]ordata['station format'][1] if_Formatthen ifdata['aliases']then iflineNthen lineN=data['aliases'][mw.ustring.lower(lineN)]orlineN end iftypeNthen typeN=data['aliases'][mw.ustring.lower(typeN)]ortypeN end end station=getStation(station,_Format) else station=stationor'' end else station=frame:expandTemplate{title=system..' stations',args={['station']=station,['line']=lineN,['branch']=typeN}} end returnstation end end p.station=makeInvokeFunction('_station') p['station link']=makeTemplateFunction('_station') functionp._terminusTable(args,frame) localsystem=args[1]orargs.system lineN=args[2]orargs.line localside=mw.ustring.sub(mw.ustring.lower(args[3]orargs.sideor''),1,1) typeN=args.type localprefix=(side=='r')and'right'or'left' localdata=args.data ifsystemordatathen data=dataorgetData(system,true) end ifdatathen localline=getLine(data,lineN)orerror(i18n[lang]['error_unknown'](lineN)) iftypeNanddataanddata['aliases']thentypeN=data['aliases'][mw.ustring.lower(typeN)]ortypeNend localType=line['types']andline['types'][typeN] localcircular ifTypethen ifType['circular']then -- Type may override the circular status of the line circular=Type['circular'] end else circular=line['circular'] end returnTypeandType[prefix..' terminus']orline[prefix..' terminus'],data['station format']ori18n[lang]['error_format'],circular else localterminus=frame:expandTemplate{title='S-line/'..system..' '..prefix..'/'..lineN} returnmw.ustring.gsub(terminus,'{{{type}}}',typeN) end end functionp._terminus(args,frame) localvar,Format,circular=p._terminusTable(args,frame) returncircularandvarorgetTerminusText(var,Format) end p.terminus=makeInvokeFunction('_terminus') functionp._style(args,frame) localstyle=args[1]orargs.style localsystem=args[2]orargs.system localline=args[3]orargs.line localstation=args[4]orargs.station localresult={} localdata=args.data localdefault='background-color:#efefef'-- Default background color for {{Infobox station}} ifsystemordatathen data=dataorgetData(system,true) end ifdatathen localfunctiongetValue(var) iftype(var)=='table'then var=var[line]orvar[1] iftype(var)=='table'then var=var[station]orvar[1] end end ifvar~=''thenreturnvarend end ifstyle=='header'then localtmp=data['name format']andgetValue(data['name format']) iftmpthentable.insert(result,tmp)end elseifstyle=='subheader'then localtmp=data['header background color']andgetValue(data['header background color']) iftmpthen table.insert(result,'background-color:#'..tmp) localcolor=data['header text color']andgetValue(data['header text color']) ifcolorthen table.insert(result,'color:#'..color) else localgreatercontrast=require('Module:Color contrast')._greatercontrast ifgreatercontrast{tmp}=='#FFFFFF'thentable.insert(result,'color:#FFFFFF')end end else table.insert(result,default) localcolor=data['header text color']andgetValue(data['header text color']) ifcolorthentable.insert(result,'color:#'..color)end end end result=table.concat(result,';') elseifsystemthen localtitle='Template:'..system..' style' localtitleObj=mw.title.new(title) iftitleObjandtitleObj.existsthen localtmp ifstyle=='header'then tmp=frame:expandTemplate{title=title,args={'name_format',line,station}} iftmp~=''thentable.insert(result,tmp)end elseifstyle=='subheader'then tmp=frame:expandTemplate{title=title,args={'thbgcolor',line,station}} iftmp~=''then table.insert(result,'background-color:#'..tmp) localcolor=frame:expandTemplate{title=title,args={'thcolor',line,station}} ifcolor~=''then table.insert(result,'color:#'..color) else localratio=require('Module:Color contrast')._ratio ifratio{tmp,'222222'}<4.5thentable.insert(result,'color:#FFFFFF')end-- 222222 is the default text color in Vector end else table.insert(result,default) tmp=frame:expandTemplate{title=title,args={'thcolor',line,station}} iftmp~=''then table.insert(result,'color:#'..tmp) end end end result=table.concat(result,';') else ifstyle=='subheader'then result=default else result='' end end else ifstyle=='subheader'then result=default else result='' end end returnresult end functionp.style(frame) localargs=getArgs(frame,{frameOnly=true}) returnp._style(args,frame) end functionp.convert(frame) localargs=frame.args localcode=mw.text.split(mw.ustring.gsub(args[1],'^%s*{{(.*)}}%s*$','%1'),'%s*}}%s*{{%s*') localsystem localgroup=tonumber(args.offsetor0)or0 localfirstgroup=group+1 localdelete={ ['s-rail']=true, ['s-rail-next']=true, ['s-rail-national']=true, ['s-start']=true, ['s-rail-start']=true, ['start']=true, ['s-end']=true, ['end']=true } localorder={ 'line','left','right','to-left','to-right', 'oneway-left','oneway-right','through-left','through-right', 'reverse','reverse-left','reverse-right', 'note-left','note-mid','note-right','transfer' -- circular: use module subpage -- state: not implemented } localreplace={ ['previous']='left', ['next']='right', ['type']='to-left', ['type2']='to-right', ['branch']='type', ['note']='note-left', ['notemid']='note-mid', ['note2']='note-right', ['oneway1']='oneway-left', ['oneway2']='oneway-right', ['through1']='through-left', ['through2']='through-right' } localremove_rows={} localdata={} localnoclear=false fori,vinipairs(code)do code[i]=mw.ustring.gsub(code[i],'\n',' ') localtemplate=mw.ustring.lower(mw.text.trim(mw.ustring.match(code[i],'^[^|]+'))) code[i]=mw.ustring.match(code[i],'(|.+)$') if(mw.ustring.match(code[i]or'','noclear%s*=%s*[a-z]'))then noclear=true end iftemplate=='s-line'then data[i]={} localthis_system=mw.text.trim(mw.ustring.match(code[i],'|%s*system%s*=([^|]+)')) code[i]=mw.text.split(code[i],'%s*|%s*') form,ninipairs(code[i])do localtmp=mw.text.split(n,'%s*=%s*') iftmp[3]then tmp[2]=mw.ustring.gsub(n,'^.-%s*=','') end tmp[1]=replace[tmp[1]]ortmp[1] iftmp[2]then -- checks for matching brackets localcurly=select(2,mw.ustring.gsub(tmp[2],"{",""))-select(2,mw.ustring.gsub(tmp[2],"}","")) localsquare=select(2,mw.ustring.gsub(tmp[2],"%[",""))-select(2,mw.ustring.gsub(tmp[2],"%]","")) ifnot(curly==0andsquare==0)then localcount=mw.clone(m)+1 whilenot(curly==0andsquare==0)do tmp[2]=tmp[2]..'|'..code[i][count] curly=curly+select(2,mw.ustring.gsub(code[i][count],"{",""))-select(2,mw.ustring.gsub(code[i][count],"}","")) square=square+select(2,mw.ustring.gsub(code[i][count],"%[",""))-select(2,mw.ustring.gsub(code[i][count],"%]","")) code[i][count]='' count=count+1 end end data[i][tmp[1]]=tmp[2] end end if(this_system~=system)or(notsystem)then system=this_system data[i]['system']=system else data[i]['system']=nil end locallast=data[i-1]ordata[i-2]ordata[i-3] iflastthen forr,sinpairs({ ['hide1']={'left','to-left','note-left','oneway-left'}, ['hide2']={'right','to-right','note-right','oneway-right'}, ['hidemid']={'type','note-mid'} })do ifdata[i][r]then form,ninipairs(s)do ifnotdata[i][n]then data[i][n]=last[n] end end end end end code[i]={} localX='|' localY=(i+group)..'=' ifdata[i]['system']then table.insert(code[i],'|system') table.insert(code[i],Y) table.insert(code[i],data[i]['system']) table.insert(code[i],'\n') end form,ninipairs(order)do ifdata[i][n]then table.insert(code[i],X) table.insert(code[i],n) table.insert(code[i],Y) table.insert(code[i],data[i][n]) end end code[i]=table.concat(code[i]) elseiftemplate=='s-note'then code[i]=mw.ustring.gsub(code[i],'|%s*text%s*=','|header'..i+group..'=') code[i]=mw.ustring.gsub(code[i],'|%s*wide%s*=[^|]*','') elseiftemplate=='s-text'then code[i]=mw.ustring.gsub(code[i],'|%s*text%s*=','|note-row'..i+group..'=') elseifdelete[template]then code[i]='' table.insert(remove_rows,1,i)-- at the start, so that the rows are deleted in reverse order group=group-1 end end fori,vinipairs(remove_rows)do table.remove(code,v) end code=table.concat(code,'\n') localt={'{{Adjacent stations'..(noclearand'|noclear=y\n'or''),'\n}}'} system=mw.ustring.match(code,'|system(%d*)=') code=mw.ustring.gsub(code,'\n\n+','\n') iftonumber(system)>firstgroupthen -- If s-line isn't the first template then the system will have to be moved to the top system=mw.ustring.match(code,'|system%d*=([^|]*[^|\n])') code=mw.ustring.gsub(code,'|system%d*=[^|]*','') code='\n|system'..firstgroup..'='..system..code elseifnotmw.ustring.match(code,'^[^{%[]*|[^=|]+2=')then -- If there's only one parameter group then there's no need to have line breaks code=mw.ustring.gsub(code,'\n','') code=mw.ustring.gsub(code,'(|[^=|]+)1=','%1=') t[2]='}}' ifnotmw.ustring.match(code,'[%[{]')then code=mw.ustring.gsub(code,'|[^=|]*=$','') code=mw.ustring.gsub(code,'|[^=|]*$','') end end ifnotmw.ustring.match(code,'[%[{]')then code=mw.ustring.gsub(code,'|[^=|]*=|','|') code=mw.ustring.gsub(code,'|[^=|]*|','|') code=mw.ustring.gsub(code,'|[^=|]*=\n','\n') code=mw.ustring.gsub(code,'|[^=|]*\n','\n') end returnt[1]..code..t[2] end returnp