Module:Adjacent stations: Difference between revisions

Content deleted Content added
No edit summary
sync
Line 136:
local gsub = mw.ustring.gsub
 
local function getLine(data, _linelineN)
if _linelineN then
if data['aliases'] then
_linelineN = data['aliases'][lower(_linelineN)] or _linelineN
end
local default = data['lines']['_default'] or {}
local line = data['lines'][_linelineN] or {}
for k, v in pairs(default) do
if v then line[k] = line[k] or v end
end
line['title'] = line['title'] and gsub(line['title'], '%%1', _linelineN)
return line, _linelineN
end
end
Line 172:
local match = mw.ustring.match
local concat = table.concat
local _linelineN, _TypetypeN
 
local function getStation(station, _Format)
if type(_Format) == 'table' then
_Format = _Format[_linelineN] or _Format[1]
if type(_Format) == 'table' then
_Format = _Format[_TypetypeN] or _Format[1]
end
end
if _TypetypeN then _Format = gsub(_Format, '%%3', _TypetypeN) end
if _linelineN then _Format = gsub(_Format, '%%2', _linelineN) end
return (match(_Format, '%[%[.+%]%]')) and (gsub(_Format, '%%1', station)) or concat({'[[', gsub(_Format, '%%1', station), '|', station, ']]'})
end
Line 318:
end
 
_linelineN = args[v]['line'] or '_default'
_TypetypeN = args[v]['type']
if data[v]['aliases'] then
_linelineN = data[v]['aliases'][lower(_linelineN)] or _linelineN
if _TypetypeN then _TypetypeN = data[v]['aliases'][lower(_TypetypeN)] or _TypetypeN end
end
 
-- get the line table
local line = data[v]['lines'] and (mw.clone(data[v]['lines'][_linelineN]) or error(i18n[lang]['error_unknown'](args[v]['line']))) or error(i18n[lang]['error_line'])
local default = data[v]['lines']['_default'] or {}
line['title'] = line['title'] or default['title']
line['title'] = gsub(line['title'], '%%1', _linelineN)
 
-- cell across row for non-stop service
Line 336:
concat({'\n|-\n|colspan="5" ',
style['body cell'],
((args[v]['nonstop'] == 'former') and i18n[lang]['nonstop_past'] or i18n[lang]['nonstop_present'])(p._box({data = data[v], line = _linelineN, Type = _TypetypeN, inline = 'yes'}))
})
)
Line 346:
 
local color, background_color
local Type = line['types'] and line['types'][_TypetypeN] -- get the line type table
 
if Type then
Line 377:
or i18n[lang]['terminus']) .. "''"
else
local terminusterminusT
local _terminusterminusN = Type and Type[b .. ' terminus'] or line[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 _terminusterminusN[2] cannot be used and _terminusterminusN[via] is reserved
if type(_terminusterminusN) == 'string' or (type(_terminusterminusN) == 'table' and (_terminusterminusN[2] or _terminusterminusN['via'])) then
if args[v]['to-' .. b] then
terminusterminusT = args[v]['to-' .. b]
local _or = match(terminusterminusT, i18n[lang]['or-format'])
if _or then
terminusterminusT = gsub(terminusterminusT, i18n[lang]['or-format'], '\127_OR_\127')
terminusterminusT = gsub(terminusterminusT, i18n[lang]['comma-format'], '\127_OR_\127')
end
local _via = (match(terminusterminusT, i18n[lang]['via-format']))
if _via then
terminusterminusT = gsub(terminusterminusT, i18n[lang]['via-format'], '')
terminusterminusT = mw.text.split(terminusterminusT, '\127_OR_\127')
terminusterminusT['via'] = _via
elseif _or then
terminusterminusT = mw.text.split(terminusterminusT, '\127_OR_\127')
end
else
terminusterminusT = _terminusterminusN
end
elseif type(_terminusterminusN) == 'table' then
terminusterminusT = _terminusterminusN[args[v]['to-' .. b]] or _terminusterminusN[args[v]['to']] or _terminusterminusN[1]
end
 
Line 407:
 
local subText = (args[v]['oneway-' .. b] or line['oneway-' .. b]) and i18n[lang]['oneway']
or args[v][b] == terminusterminusT and i18n[lang]['terminus']
or line['circular'] and terminusterminusT
or i18n[lang]['towards'](station(terminusterminusT))
subText = small(subText, true)
 
Line 422:
 
-- 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
(_TypetypeN and '<div>' .. (Type and Type['title'] or _TypetypeN) .. '</div>' or ''),
 
-- Note-mid; table key 'note-mid' in subpages. Overridden by user input
Line 491:
function p._box(args, frame)
local system = args[1] or args.system
local _linelineN = args[2] or args.line
if not (system or _linelineN) then return '' end
local line, Type, line_data
local inline = args[3] or args.inline
local _TypetypeN = args.type
local data = args.data
if system or data then
Line 502:
if data then
local default = data['lines']['_default'] or {}
line, _linelineN = getLine(data, _linelineN)
if _TypetypeN then
_TypetypeN = data['aliases'] and data['aliases'][lower(_TypetypeN)] or _TypetypeN
Type = line['types'] and line['types'][_TypetypeN] and line['types'][_TypetypeN]['title'] or _TypetypeN
end
color = getColor(data, nil, _linelineN, _TypetypeN)
if inline ~= 'box' then
line_data = line or error(i18n[lang]['error_unknown'](_linelineN))
line = line_data['title'] or default['title'] or error(i18n[lang]['error_missing']('title'))
line = gsub(line, '%%1', _linelineN)
end
else
color = getColor(nil, system, _linelineN, _TypetypeN, frame)
if inline ~= 'box' then
line = frame:expandTemplate{ title = system .. ' lines', args = {_linelineN, ['branch'] = _TypetypeN} }
if mw.text.trim(line) == '' then return error(i18n[lang]['error_unknown'](_linelineN)) end
end
Type = _TypetypeN
end
 
Line 572:
local border_color, text_color
if line_data then
if line_data['types'] and line_data['types'][_TypetypeN] then
local Type_data = line_data['types'][_TypetypeN]
border_color = Type_data['border color'] or line_data['border color'] or color
text_color = Type_data['text color'] or line_data['text color']
_linelineN = Type_data['short name'] or line_data['short name'] or _linelineN
else
border_color = line_data['border color'] or color
text_color = line_data['text color']
_linelineN = line_data['short name'] or _linelineN
end
else
Line 590:
if inline == 'route' then -- [[Template:RouteBox]]
if link then
result = '<span style="background-color:#' .. color .. ';border:.075em solid #' .. border_color .. ';padding:0 .3em">[[' .. link .. '|<span style="color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. _linelineN .. '</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">' .. _linelineN .. '</span>'
end
elseif inline == 'croute' then -- [[Template:Bahnlinie]]
if link then
result = '<span style="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">' .. _linelineN .. '</span>]]</span>'
else
result = '<span style="background-color:#' .. color .. ';border:.075em solid #' .. border_color .. ';border-radius:.5em;padding:0 .3em;color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. _linelineN .. '</span>'
end
elseif inline == 'xroute' then -- [[Template:Bahnlinie]]
if link then
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">' .. _linelineN .. '</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">' .. _linelineN .. '</span>'
end
else -- [[Template:Legend]] (fallback; duplication to simplify logic)
Line 715:
else
line = frame:expandTemplate{ title = system .. ' lines', args = {line, ['branch'] = Type} }
if mw.text.trim(line) == '' then return error(i18n[lang]['error_unknown'](_linelineN)) end
end
 
Line 735:
local station = args[2] or args.station
if not station then return '' end
local _linelineN = args[3] or args.line
local _TypetypeN = args[4] or args.type
local data = args.data
if system or data then
Line 744:
if _Format then
if data['aliases'] then
if _linelineN then
_linelineN = data['aliases'][lower(_linelineN)] or _linelineN
end
if _TypetypeN then
_TypetypeN = data['aliases'][lower(_TypetypeN)] or _TypetypeN
end
end
Line 756:
end
else
station = frame:expandTemplate{ title = system .. ' stations', args = {['station'] = station, ['line'] = _linelineN, ['branch'] = _TypetypeN} }
end