Module:Routemap: Difference between revisions
Content added Content deleted
Vivaporius (talk | contribs) m (1 revision imported) |
en>Centrist16 (Created page with "local i18n = { errors = { ["parameter-missing"] = "Missing parameter!", ["collapsible-block-not-closed"] = "Collapsible section not closed properly!", ["collapsible-blo...") |
||
Line 10: | Line 10: | ||
}, |
}, |
||
["error-categories"] = { |
["error-categories"] = { |
||
default = '[[Category:Pages with errors of Module Routemap]]' |
default = '[[Category:Pages with errors of Module Routemap]]', |
||
["text-images"] = '[[Category:Pages using Routemap with text images]]', |
|||
["separate-navbar"] = '[[Category:Pages using Routemap with a separate navbar template]]', |
|||
["missing-text-values"] = '[[Category:Pages using BSto or BSsrws with missing text values]]', |
|||
["br-tags"] = '[[Category:Pages using BSto, BSsplit, BSsrws or BScvt with br tags]]', |
|||
["srws"] = '[[Category:Pages using BSsplit instead of BSsrws]]', |
|||
["rmr-error"] = '[[Category:Pages with bad value for RoutemapRoute template]]' |
|||
}, |
|||
text = { |
|||
navbar_mini = false, -- for navbar pos 2 only |
|||
navbar_text = 'This diagram:', -- for navbar pos 2 only |
|||
legend_text = 'Legend', |
|||
legend = { |
|||
default = '[[Template:Railway line legend', |
|||
track = '[[Template:Railway track legend', |
|||
bus = '[[Template:Bus route legend', |
|||
canal = '[[Template:Waterways legend', |
|||
water = '[[Template:Waterways legend', |
|||
waterway = '[[Template:Waterways legend', |
|||
foot = '[[Template:Trails legend', |
|||
footpath = '[[Template:Trails legend', |
|||
walkway = '[[Template:Trails legend' |
|||
} |
|||
}, |
}, |
||
html = { |
html = { |
||
Line 19: | Line 41: | ||
|style="padding:0%s"|<div style="position:relative">%s</div><div%s>[[File:BSicon_%s.svg|x20px|link=|alt=|%s]]%s</div>', |
|style="padding:0%s"|<div style="position:relative">%s</div><div%s>[[File:BSicon_%s.svg|x20px|link=|alt=|%s]]%s</div>', |
||
["cell-text-fmt"] = '\ |
["cell-text-fmt"] = '\ |
||
|style="padding:0;width:%s;min-width:%s;line-height:20px%s" title="%s"|<%s style=" |
|style="padding:0;width:%s;min-width:%s;line-height:20px%s" title="%s"|<%s style="line-height:.975;display:inline-block%s">%s%s%s%s</%s>', |
||
["cell-overlaptext-fmt"] = '<div style="position:absolute;width:%s;min-width:%s;line-height:20px%s" title="%s"><%s style=" |
["cell-overlaptext-fmt"] = '<div style="position:absolute;width:%s;min-width:%s;line-height:20px%s" title="%s"><%s style="line-height:.975;display:inline-block%s">%s%s%s</%s></div>', |
||
["cell-text-fmt-with-overlap"] = '\ |
["cell-text-fmt-with-overlap"] = '\ |
||
|style="padding:0%s"|<div style="position:relative">%s</div><div style="width:%s;min-width:%s;line-height:20px%s" title="%s"><%s style=" |
|style="padding:0%s"|<div style="position:relative">%s</div><div style="width:%s;min-width:%s;line-height:20px%s" title="%s"><%s style="line-height:.975;display:inline-block%s">%s%s%s%s</%s></div>', |
||
["cell-empty-fmt"] = '\n|style="padding:0;width:%s;min-width:%s;height:20px;min-height:20px%s"|%s', |
["cell-empty-fmt"] = '\n|style="padding:0;width:%s;min-width:%s;height:20px;min-height:20px%s"|%s', |
||
["cell-empty-fmt-with-overlap"] = '\n|style="padding:0%s"|<div style="position:relative">%s</div><div style="width:%s;min-width:%s;height:20px;min-height:20px%s">%s</div>', |
["cell-empty-fmt-with-overlap"] = '\n|style="padding:0%s"|<div style="position:relative">%s</div><div style="width:%s;min-width:%s;height:20px;min-height:20px%s">%s</div>', |
||
Line 30: | Line 52: | ||
["row-linfo4-fmt"] = '\ |
["row-linfo4-fmt"] = '\ |
||
|style="vertical-align:middle;padding:0 3px 0 0;text-align:left;%s"|< |
|style="width:auto;vertical-align:middle;padding:0 3px 0 0;text-align:left;%s"|<div style="display:inline;font-size:90%%;">%s</div>',-- parameters:linfo4-width, linfo4 |
||
["row-linfo3-fmt"] = '< |
["row-linfo3-fmt"] = '<div style="display:inline;font-size:90%%;">%s</div> ', |
||
["row-rinfo3-fmt"] = ' < |
["row-rinfo3-fmt"] = ' <div style="display:inline;font-size:90%%;">%s</div>', |
||
["row-rinfo4-fmt"] = '\ |
["row-rinfo4-fmt"] = '\ |
||
|style="vertical-align:middle;padding:0 0 0 3px;text-align:right;%s"|< |
|style="width:auto;vertical-align:middle;padding:0 0 0 3px;text-align:right;%s"|<div style="display:inline;font-size:90%%;">%s</div>',-- parameters:rinfo4-width, rinfo4 |
||
["row-general-fmt"] = '\ |
["row-general-fmt"] = '\ |
||
|- style="line-height:1" %s\ |
|- style="line-height:1" %s\ |
||
|colspan="%s" style="vertical-align:middle;padding:0;text-align:right;%s"|%s\ |
|colspan="%s" style="width:auto;vertical-align:middle;padding:0;text-align:right;%s"|%s\ |
||
|style="vertical-align:middle;text-align:left;padding:0 %s;%s"|< |
|style="width:auto;vertical-align:middle;text-align:left;padding:0 %s;%s"|<div style="display:inline;font-size:90%%;">%s</div>\ |
||
|style="padding:0%s"|\ |
|style="width:auto;padding:0%s"|\ |
||
{|cellspacing="0" cellpadding="0" style="display: |
{|cellspacing="0" cellpadding="0" style="display:table;width:unset;line-height:0;padding:0 !important;margin:0 auto !important"\ |
||
|- style="display:inline-table"%s\ |
|- style="display:inline-table;%s"%s\ |
||
|}\ |
|}\ |
||
|style="vertical-align:middle;text-align:right;padding:0 %s;%s"|< |
|style="width:auto;vertical-align:middle;text-align:right;padding:0 %s;%s"|<div style="display:inline;font-size:90%%;">%s</div>\ |
||
|colspan="%s" style="vertical-align:middle;padding:0;text-align:left;%s"|%s%s',-- parameters: linfo4-fmt, colspan-left, linfo3+2-width, linfo3+2, linfo1-pad, linfo1-width, linfo1, bg, cells, rinfo1-pad, rinfo1-width, rinfo1, colspan-right, rinfo2+3-width, rinfo2+3, rinfo4-fmt |
|colspan="%s" style="width:auto;vertical-align:middle;padding:0;text-align:left;%s"|%s%s',-- parameters: linfo4-fmt, colspan-left, linfo3+2-width, linfo3+2, linfo1-pad, linfo1-width, linfo1, bg, cells, rinfo1-pad, rinfo1-width, rinfo1, colspan-right, rinfo2+3-width, rinfo2+3, rinfo4-fmt |
||
["row-collapsible-begin-fmt"] = '\ |
["row-collapsible-begin-fmt"] = '\ |
||
Line 58: | Line 80: | ||
["row-collapsible-left-linfo4+3+2-fmt"] = '\ |
["row-collapsible-left-linfo4+3+2-fmt"] = '\ |
||
{|cellspacing="0" cellpadding="0" style="line-height:1;width:100%%;padding:0 !important;margin:0 !important"\ |
{|cellspacing="0" cellpadding="0" style="line-height:1;width:100%%;padding:0 !important;margin:0 !important"\ |
||
|style="vertical-align:middle;padding:0 3px 0 1px;text-align:left"| < |
|style="width:auto;vertical-align:middle;padding:0 3px 0 1px;text-align:left"| <div style="display:inline;font-size:90%%;">%s</div>\ |
||
|style="vertical-align:middle;text-align:right"| %s\ |
|style="width:auto;vertical-align:middle;text-align:right"| %s\ |
||
|}',-- parameters: linfo4, linfo3+2 |
|}',-- parameters: linfo4, linfo3+2 |
||
["row-collapsible-right-button-width"] = '45px',-- 72px is the minimal width for [развернуть] / [свернуть] button at 90%. Use 58px for [expand] / [collapse] |
["row-collapsible-right-button-width"] = '45px',-- 72px is the minimal width for [развернуть] / [свернуть] button at 90%. Use 58px for [expand] / [collapse] |
||
["row-collapsible-right-rinfo2+3+4-fmt"] = '\ |
["row-collapsible-right-rinfo2+3+4-fmt"] = '\ |
||
{|cellspacing="0" cellpadding="0" style="line-height:1;width:100%%;padding:0 !important;margin:0 !important"\ |
{|cellspacing="0" cellpadding="0" style="line-height:1;width:100%%;padding:0 !important;margin:0 !important"\ |
||
|style="vertical-align:middle;text-align:left"| %s\ |
|style="width:auto;vertical-align:middle;text-align:left"| %s\ |
||
|style="vertical-align:middle;padding:0 1px 0 3px;text-align:right"| < |
|style="width:auto;vertical-align:middle;padding:0 1px 0 3px;text-align:right"| <div style="display:inline;font-size:90%%;">%s</div>\ |
||
|}',-- parameters: rinfo2+3, linfo4 |
|}',-- parameters: rinfo2+3, linfo4 |
||
["row-collapsible-right-button-fmt"] = '\n| style="vertical-align:middle;padding-left:3px;font-size:90%%;min-width:%s;%s" |',--parameters: right-button-width, rinfo4-width |
["row-collapsible-right-button-fmt"] = '\n| style="width:auto;vertical-align:middle;padding-left:3px;font-size:90%%;min-width:%s;%s" |',--parameters: right-button-width, rinfo4-width |
||
["row-collapsible-replace-begin-fmt"] = '\ |
["row-collapsible-replace-begin-fmt"] = '\ |
||
Line 76: | Line 98: | ||
["colspan-fmt"] = '%s\n|-\n| colspan="7" style="background-color:%s;text-align:%s;%s"|\n%s', |
["colspan-fmt"] = '%s\n|-\n| colspan="7" style="background-color:%s;text-align:%s;%s"|\n%s', |
||
["empty-row-fmt"] = '\n|-\n| style="padding |
["empty-row-fmt"] = '\n|-\n| style="width:auto;padding:0 3px 0 0;%s" |\n| style="width:auto;padding: 0;%s" |\n| style="width:auto;padding:0 %s;%s" |\n| style="width:auto;padding:0" |\n| style="width:auto;padding:0 %s;%s" |\n| style="width:auto;padding:0;%s" |\n| style="width:auto;padding:0 0 0 3px;%s" |' |
||
} |
} |
||
} |
} |
||
local p,q={},{} |
local p,q={},{} |
||
local getArgs = require('Module:Arguments').getArgs |
|||
local function makeInvokeFunction(funcName) |
|||
-- makes a function that can be returned from #invoke, using |
|||
-- [[Module:Arguments]]. |
|||
return function (frame) |
|||
local args = getArgs(frame, {parentOnly = true}) |
|||
return p[funcName](args) |
|||
end |
|||
end |
|||
local function formaterror(key,param) |
local function formaterror(key,param) |
||
local result = string.format(i18n.html['colspan-fmt'], '', '', '', '', '<span class="error">' .. string.format(i18n.errors[key] or (tostring(key) .. ' %s'), |
local result = string.format(i18n.html['colspan-fmt'], '', '', '', '', '<span class="error">' .. string.format(i18n.errors[key] or (tostring(key) .. ' %s'), |
||
tostring(param or '')) .. '</span>') |
tostring(param or '')) .. '</span>') |
||
if mw.site.namespaces[mw.title.getCurrentTitle().namespace].isContent then result = result .. (i18n[' |
if mw.site.namespaces[mw.title.getCurrentTitle().namespace].isContent then result = result .. (i18n['error-categories'][key] or i18n['error-categories'].default or '') end |
||
return result |
return result |
||
end |
end |
||
Line 110: | Line 143: | ||
maroon = '800000', ex_maroon = 'B16464', |
maroon = '800000', ex_maroon = 'B16464', |
||
ochre = 'CC6600', ex_ochre = 'DEA164', |
ochre = 'CC6600', ex_ochre = 'DEA164', |
||
olive = '837902', ex_olive = 'B2AC64', |
|||
orange = 'FF6600', ex_orange = 'FF9955', |
orange = 'FF6600', ex_orange = 'FF9955', |
||
pink = 'F0668D', ex_pink = 'F4A1B8', |
pink = 'F0668D', ex_pink = 'F4A1B8', |
||
Line 123: | Line 157: | ||
} |
} |
||
return colors[code] or colors.bahn |
return colors[code] or colors.bahn |
||
end |
|||
p.RGBbyCode = makeInvokeFunction('_RGBbyCode') |
|||
function p._RGBbyCode(args) |
|||
return RGBbyCode(args[1]) |
|||
end |
end |
||
Line 192: | Line 232: | ||
local function widths(p) |
local function widths(p) |
||
local values = { |
|||
local values = {['w'] = 160, ['bs'] = 120, ['s'] = 80, ['b'] = 40, [''] = 20, ['cd'] = 15, ['d'] = 10, ['c'] = 5,} -- in px |
|||
['w'] = 160, ['+bs'] = 140, ['bs'] = 120, ['+s'] = 100, |
|||
['s'] = 80, ['+db'] = 70, ['+b'] = 60, ['db'] = 50, |
|||
['b'] = 40, ['+cd'] = 35, ['+d'] = 30, ['+c'] = 25, |
|||
[''] = 20, ['ocd'] = 17.5, ['cd'] = 15, ['od'] = 12.5, |
|||
['d'] = 10, ['oc'] = 7.5, ['c'] = 5, ['o'] = 2.5 |
|||
} -- in px |
|||
return values[p] |
return values[p] |
||
end |
end |
||
Line 213: | Line 259: | ||
tmp = mw.text.split(overlapIcons[#overlapIcons], '!@') |
tmp = mw.text.split(overlapIcons[#overlapIcons], '!@') |
||
overlapIcons[#overlapIcons] = tmp[1] |
overlapIcons[#overlapIcons] = tmp[1] |
||
if #tmp > 1 then link = tmp[2] end |
if #tmp > 1 then link = tmp[2] end |
||
tmp = mw.text.split(icon, '__') |
tmp = mw.text.split(icon, '__') |
||
icon = tmp[1] |
icon = tmp[1] |
||
Line 247: | Line 293: | ||
if not cellProps.fontsize or rowProps.fontsize or cellProps.fontsize == 'info' then |
if not cellProps.fontsize or rowProps.fontsize or cellProps.fontsize == 'info' then |
||
elseif cellProps.fontsize == 'cmt' or cellProps.fontsize == 'comment' then |
elseif cellProps.fontsize == 'cmt' or cellProps.fontsize == 'comment' then |
||
cellProps._before, cellProps._after = '< |
cellProps._before, cellProps._after = '<div style="display:inline;font-size:90%;">', '</div>' |
||
else |
else |
||
cellProps.style = cellProps.style..';font-size:'..cellProps.fontsize |
cellProps.style = cellProps.style..';font-size:'..cellProps.fontsize |
||
Line 262: | Line 308: | ||
tmp = {} |
tmp = {} |
||
for i, v in ipairs(overlapIcons) do |
for i, v in ipairs(overlapIcons) do |
||
local thislink = link |
|||
if |
if i ~= #overlapIcons then thislink = '' end |
||
if thislink and thislink ~= '' then icontip = thislink end |
|||
if overlapProps[i].style then overlapProps.style = ';'..overlapProps[i].style else overlapProps.style = '' end |
if overlapProps[i].style then overlapProps.style = ';'..overlapProps[i].style else overlapProps.style = '' end |
||
overlapProps[i].bg = overlapProps[i].bg or overlapProps[i].background or overlapProps[i].bgcolor |
overlapProps[i].bg = overlapProps[i].bg or overlapProps[i].background or overlapProps[i].bgcolor |
||
Line 278: | Line 325: | ||
if rowProps.fontsize or cellProps.fontsize or overlapProps[i].fontsize == 'info' then |
if rowProps.fontsize or cellProps.fontsize or overlapProps[i].fontsize == 'info' then |
||
elseif not overlapProps[i].fontsize then |
elseif not overlapProps[i].fontsize then |
||
overlapProps.style = overlapProps.style..';font-size:10px' |
overlapProps.style = overlapProps.style..';font-size:10px;transform:scaleX(.9)' |
||
elseif overlapProps[i].fontsize == 'cmt' or overlapProps[i].fontsize == 'comment' then |
elseif overlapProps[i].fontsize == 'cmt' or overlapProps[i].fontsize == 'comment' then |
||
overlapProps._before, overlapProps._after = '< |
overlapProps._before, overlapProps._after = '<div style="display:inline;font-size:90%;">', '</div>' |
||
else |
else |
||
overlapProps.style = overlapProps.style..';font-size:'..overlapProps[i].fontsize |
overlapProps.style = overlapProps.style..';font-size:'..overlapProps[i].fontsize |
||
Line 294: | Line 341: | ||
overlapProps.tag = {'abbr title="'..string.gsub(overlapProps[i].abbr, '"', '"')..'"', 'abbr'} |
overlapProps.tag = {'abbr title="'..string.gsub(overlapProps[i].abbr, '"', '"')..'"', 'abbr'} |
||
else |
else |
||
overlapProps.tag = {' |
overlapProps.tag = {'div', 'div'} |
||
end |
end |
||
width = (widths(tmp_iconpre) or 20)..'px' |
width = (widths(tmp_iconpre) or 20)..'px' |
||
Line 301: | Line 348: | ||
v = mw.text.trim(v) |
v = mw.text.trim(v) |
||
if string.find(v, 'num') then |
if string.find(v, 'num') then |
||
if not string.find(v, 'numN%d+') then tracking = tracking..'[ |
if not string.find(v, 'numN%d+') then tracking = tracking..(i18n['error-categories']['text-images'] or i18n['error-categories'].default) end |
||
end |
end |
||
table.insert(tmp, string.format(i18n.html['cell-overlapicon-fmt'], overlapProps.style, v, |
table.insert(tmp, string.format(i18n.html['cell-overlapicon-fmt'], overlapProps.style, v, thislink, icontip)) |
||
end |
end |
||
end |
end |
||
Line 321: | Line 368: | ||
if rowProps.fontsize or cellProps.fontsize or iconProps.fontsize == 'info' then |
if rowProps.fontsize or cellProps.fontsize or iconProps.fontsize == 'info' then |
||
elseif not iconProps.fontsize then |
elseif not iconProps.fontsize then |
||
iconProps.style = iconProps.style..';font-size:10px' |
iconProps.style = iconProps.style..';font-size:10px;transform:scaleX(.9)' |
||
elseif iconProps.fontsize == 'cmt' or iconProps.fontsize == 'comment' then |
elseif iconProps.fontsize == 'cmt' or iconProps.fontsize == 'comment' then |
||
iconProps._before, iconProps._after = '< |
iconProps._before, iconProps._after = '<div style="display:inline;font-size:90%;">', '</div>' |
||
else |
else |
||
iconProps.style = iconProps.style..';font-size:'..iconProps.fontsize |
iconProps.style = iconProps.style..';font-size:'..iconProps.fontsize |
||
Line 337: | Line 384: | ||
iconProps.tag = {'abbr title="'..string.gsub(iconProps.abbr, '"', '"')..'"', 'abbr'} |
iconProps.tag = {'abbr title="'..string.gsub(iconProps.abbr, '"', '"')..'"', 'abbr'} |
||
else |
else |
||
iconProps.tag = {' |
iconProps.tag = {'div', 'div'} |
||
end |
end |
||
if tmp2[1] then iconProps.style = ';'..iconProps.style end |
if tmp2[1] then iconProps.style = ';'..iconProps.style end |
||
Line 345: | Line 392: | ||
if iconProps.style ~= '' then iconProps.style = string.gsub(' style="'..iconProps.style..'"', '";', '"', 1) end |
if iconProps.style ~= '' then iconProps.style = string.gsub(' style="'..iconProps.style..'"', '";', '"', 1) end |
||
if string.find(icon, 'num') then |
if string.find(icon, 'num') then |
||
if not string.find(icon, 'numN%d+') then tracking = tracking..'[ |
if not string.find(icon, 'numN%d+') then tracking = tracking..(i18n['error-categories']['text-images'] or i18n['error-categories'].default) end |
||
end |
end |
||
return string.format(i18n.html['cell-icon-fmt-with-overlap'], cellProps.style, mw.text.trim(table.concat(tmp)), iconProps.style, icon, icontip, tracking) |
return string.format(i18n.html['cell-icon-fmt-with-overlap'], cellProps.style, mw.text.trim(table.concat(tmp)), iconProps.style, icon, icontip, tracking) |
||
Line 356: | Line 403: | ||
if link and link ~= '' then icontip = link end |
if link and link ~= '' then icontip = link end |
||
if icontext then |
if icontext then |
||
if not cellProps.fontsize and not rowProps.fontsize then cellProps.style = cellProps.style..';font-size:10px' end |
if not cellProps.fontsize and not rowProps.fontsize then cellProps.style = cellProps.style..';font-size:10px;transform:scaleX(.9)' end |
||
if cellProps.abbr then |
if cellProps.abbr then |
||
cellProps.tag = {'abbr title="'..string.gsub(cellProps.abbr, '"', '"')..'"', 'abbr'} |
cellProps.tag = {'abbr title="'..string.gsub(cellProps.abbr, '"', '"')..'"', 'abbr'} |
||
else |
else |
||
cellProps.tag = {' |
cellProps.tag = {'div', 'div'} |
||
end |
end |
||
width = (widths(iconpre) or 20)..'px' |
width = (widths(iconpre) or 20)..'px' |
||
Line 366: | Line 413: | ||
else |
else |
||
if string.find(icon, 'num') then |
if string.find(icon, 'num') then |
||
if not string.find(icon, 'numN%d+') then tracking = tracking..'[ |
if not string.find(icon, 'numN%d+') then tracking = tracking..(i18n['error-categories']['text-images'] or i18n['error-categories'].default) end |
||
end |
end |
||
return string.format(i18n.html['cell-icon-fmt'], cellProps.style, icon, link, icontip, tracking) |
return string.format(i18n.html['cell-icon-fmt'], cellProps.style, icon, link, icontip, tracking) |
||
Line 393: | Line 440: | ||
]] |
]] |
||
local result = {['linfo4'] = '', ['linfo3+2'] = '', ['linfo1'] = '', ['cells'] = {}, ['rinfo1'] = '', ['rinfo2+3'] = '', ['rinfo4'] = '', ['rowProp'] = {}} |
local result = {['linfo4'] = '', ['linfo3+2'] = '', ['linfo1'] = '', rowstyle = '', ['cells'] = {}, ['rinfo1'] = '', ['rinfo2+3'] = '', ['rinfo4'] = '', ['rowProp'] = {}} |
||
local lcolspan, rcolspan, linfo4_fmt, rinfo4_fmt = '2', '2', '', '' |
local lcolspan, rcolspan, linfo4_fmt, rinfo4_fmt = '2', '2', '', '' |
||
local left, right, icons, overlapIcons, tmp = {}, {}, {}, {}, mw.text.split(pattern, '! !') |
local left, right, icons, overlapIcons, tmp = {}, {}, {}, {}, mw.text.split(pattern, '! !') |
||
Line 456: | Line 503: | ||
icons = mw.text.split(tmp[1], '\\')--splitting the string of icons first by "\" |
icons = mw.text.split(tmp[1], '\\')--splitting the string of icons first by "\" |
||
if type(filler) == 'string' then |
if type(filler) == 'string' then |
||
result.style = ';font-size:0px' |
|||
result['cells'][1] = 'style="height:' .. filler .. '"'--row parameter before any cells |
|||
result.rowstyle = 'height:' .. filler .. ';min-height:' .. filler --row parameter before any cells |
|||
for i, v in ipairs(icons) do table.insert(result['cells'], fillercell(v)) end--no !@ or !~ for filler row |
for i, v in ipairs(icons) do table.insert(result['cells'], fillercell(v)) end--no !@ or !~ for filler row |
||
else |
else |
||
result.style = '' |
|||
for i, v in ipairs(icons) do |
for i, v in ipairs(icons) do |
||
tmp = mw.text.split(v, '!~') |
tmp = mw.text.split(v, '!~') |
||
Line 468: | Line 517: | ||
end |
end |
||
result['cells'] = table.concat(result['cells']) |
result['cells'] = table.concat(result['cells']) |
||
if result.rowProp.style then result.style = ';'..result.rowProp.style |
if result.rowProp.style then result.style = result.style..';'..result.rowProp.style end |
||
result.rowProp.bg = result.rowProp.bg or result.rowProp.background or result.rowProp.bgcolor ; result.rowProp.color = result.rowProp.color or result.rowProp.colour ; result.rowProp.bold = result.rowProp.bold or result.rowProp.b ; result.rowProp.italic = result.rowProp.italic or result.rowProp.i or result.rowProp.it |
result.rowProp.bg = result.rowProp.bg or result.rowProp.background or result.rowProp.bgcolor ; result.rowProp.color = result.rowProp.color or result.rowProp.colour ; result.rowProp.bold = result.rowProp.bold or result.rowProp.b ; result.rowProp.italic = result.rowProp.italic or result.rowProp.i or result.rowProp.it |
||
if result.rowProp.bg then result.style = result.style..';background:'..result.rowProp.bg end |
if result.rowProp.bg then result.style = result.style..';background:'..result.rowProp.bg end |
||
Line 485: | Line 534: | ||
return result |
return result |
||
else |
else |
||
return string.format(i18n.html['row-general-fmt'], linfo4_fmt, lcolspan, '', result['linfo3+2'], q.linfo1_pad, '', result['linfo1'], result.style, |
return string.format(i18n.html['row-general-fmt'], linfo4_fmt, lcolspan, '', result['linfo3+2'], q.linfo1_pad, '', result['linfo1'], result.style, result.rowstyle, |
||
result['cells'], q.rinfo1_pad, '', result['rinfo1'], rcolspan, '', result['rinfo2+3'], rinfo4_fmt) |
result['cells'], q.rinfo1_pad, '', result['rinfo1'], rcolspan, '', result['rinfo2+3'], rinfo4_fmt) |
||
end |
end |
||
Line 506: | Line 555: | ||
if tmp then |
if tmp then |
||
if tmp == 'endCollapsible' then return formaterror('collapsible-block-empty') |
if tmp == 'endCollapsible' then return formaterror('collapsible-block-empty') |
||
else return formaterror('collapsible-block-no-first-row') .. |
else return formaterror('collapsible-block-no-first-row') .. q.isKeyword(rows[i], i, rows) --no valid keywords that can follow "startCollapsible" |
||
end |
end |
||
end |
end |
||
Line 523: | Line 572: | ||
if tmp['linfo4'] ~= '' or tmp['linfo3+2'] ~= '' then linfo4_3_2_fmt = string.format(i18n.html['row-collapsible-left-linfo4+3+2-fmt'], tmp['linfo4'], tmp['linfo3+2']) end |
if tmp['linfo4'] ~= '' or tmp['linfo3+2'] ~= '' then linfo4_3_2_fmt = string.format(i18n.html['row-collapsible-left-linfo4+3+2-fmt'], tmp['linfo4'], tmp['linfo3+2']) end |
||
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-collapsible-left-button-fmt'], i18n.html['row-collapsible-left-button-width'], q.text_width[1]), |
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-collapsible-left-button-fmt'], i18n.html['row-collapsible-left-button-width'], q.text_width[1]), |
||
'1', q.text_width[2], linfo4_3_2_fmt, q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, tmp['cells'], '', '', '', '1', '', '', string.format(i18n.html['row-rinfo4-fmt'], '', '')) |
'1', q.text_width[2], linfo4_3_2_fmt, q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, '', tmp['cells'], '', '', '', '1', '', '', string.format(i18n.html['row-rinfo4-fmt'], '', '')) |
||
else |
else |
||
if tmp['rinfo4'] ~= '' or tmp['rinfo2+3'] ~= '' then rinfo2_3_4_fmt = string.format(i18n.html['row-collapsible-right-rinfo2+3+4-fmt'], tmp['rinfo2+3'], tmp['rinfo4']) end |
if tmp['rinfo4'] ~= '' or tmp['rinfo2+3'] ~= '' then rinfo2_3_4_fmt = string.format(i18n.html['row-collapsible-right-rinfo2+3+4-fmt'], tmp['rinfo2+3'], tmp['rinfo4']) end |
||
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-linfo4-fmt'], q.text_width[1], tmp['linfo4']), |
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-linfo4-fmt'], q.text_width[1], tmp['linfo4']), |
||
'1', q.text_width[2], tmp['linfo3+2'], q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, tmp['cells'], q.rinfo1_pad, q.text_width[4], tmp['rinfo1'], |
'1', q.text_width[2], tmp['linfo3+2'], q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, '', tmp['cells'], q.rinfo1_pad, q.text_width[4], tmp['rinfo1'], |
||
'1', q.text_width[5], rinfo2_3_4_fmt, string.format(i18n.html['row-collapsible-right-button-fmt'], i18n.html['row-collapsible-right-button-width'], q.text_width[6])) |
'1', q.text_width[5], rinfo2_3_4_fmt, string.format(i18n.html['row-collapsible-right-button-fmt'], i18n.html['row-collapsible-right-button-width'], q.text_width[6])) |
||
end |
end |
||
Line 541: | Line 590: | ||
if tmp['linfo4'] ~= '' or tmp['linfo3+2'] ~= '' then linfo4_3_2_fmt = string.format(i18n.html['row-collapsible-left-linfo4+3+2-fmt'], tmp['linfo4'], tmp['linfo3+2']) end |
if tmp['linfo4'] ~= '' or tmp['linfo3+2'] ~= '' then linfo4_3_2_fmt = string.format(i18n.html['row-collapsible-left-linfo4+3+2-fmt'], tmp['linfo4'], tmp['linfo3+2']) end |
||
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-linfo4-fmt'], '', ''), '1', q.text_width[2], linfo4_3_2_fmt, |
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-linfo4-fmt'], '', ''), '1', q.text_width[2], linfo4_3_2_fmt, |
||
q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, tmp['cells'], '', '', '', '1', '', '', string.format(i18n.html['row-rinfo4-fmt'], '', '')) |
q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, '', tmp['cells'], '', '', '', '1', '', '', string.format(i18n.html['row-rinfo4-fmt'], '', '')) |
||
else |
else |
||
if tmp['rinfo4'] ~= '' or tmp['rinfo2+3'] ~= '' then rinfo2_3_4_fmt = string.format(i18n.html['row-collapsible-right-rinfo2+3+4-fmt'], tmp['rinfo2+3'], tmp['rinfo4']) end |
if tmp['rinfo4'] ~= '' or tmp['rinfo2+3'] ~= '' then rinfo2_3_4_fmt = string.format(i18n.html['row-collapsible-right-rinfo2+3+4-fmt'], tmp['rinfo2+3'], tmp['rinfo4']) end |
||
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-linfo4-fmt'], q.text_width[1], tmp['linfo4']), '1', q.text_width[2], |
result = result .. string.format(i18n.html['row-general-fmt'], string.format(i18n.html['row-linfo4-fmt'], q.text_width[1], tmp['linfo4']), '1', q.text_width[2], |
||
tmp['linfo3+2'], q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, tmp['cells'], q.rinfo1_pad, q.text_width[4], tmp['rinfo1'], '1', q.text_width[5], |
tmp['linfo3+2'], q.linfo1_pad, q.text_width[3], tmp['linfo1'], tmp.style, '', tmp['cells'], q.rinfo1_pad, q.text_width[4], tmp['rinfo1'], '1', q.text_width[5], |
||
rinfo2_3_4_fmt, string.format(i18n.html['row-rinfo4-fmt'], '', '')) |
rinfo2_3_4_fmt, string.format(i18n.html['row-rinfo4-fmt'], '', '')) |
||
end |
end |
||
Line 588: | Line 637: | ||
end |
end |
||
local function localroute(pattern,ptw,pbg) |
local function localroute(pattern,ptw,pbg,process) |
||
local tmp = {} |
local tmp = {} |
||
if mw.text.trim(pbg) ~= '' then q.bg = pbg end |
if mw.text.trim(pbg) ~= '' then q.bg = pbg end |
||
tmp = mw.text.split(mw.text.trim(ptw), ',') |
tmp = mw.text.split(mw.text.trim(ptw), '%s*,%s*') |
||
if #tmp == 6 then |
if #tmp == 6 then |
||
for i = 1, 6 do |
for i = 1, 6 do |
||
if tmp[i] ~= '' then |
if tmp[i] ~= '' then |
||
if tonumber(string.sub(tmp[i],-1)) then |
if tonumber(string.sub(tmp[i],-1)) then |
||
q.text_width[i] = 'width:' .. tmp[i] .. 'px;' |
q.text_width[i] = 'width:' .. tmp[i] .. 'px;min-width:' .. tmp[i] .. 'px;' |
||
else |
else |
||
q.text_width[i] = 'width:' .. tmp[i] .. ';' |
q.text_width[i] = 'width:' .. tmp[i] .. ';min-width:' .. tmp[i] .. ';' |
||
end |
end |
||
end |
end |
||
Line 611: | Line 660: | ||
if tmp[i] ~= '' then |
if tmp[i] ~= '' then |
||
if tonumber(string.sub(tmp[i],-1)) then |
if tonumber(string.sub(tmp[i],-1)) then |
||
q.text_width[i + 3] = 'width:' .. tmp[i] .. 'px;' |
q.text_width[i + 3] = 'width:' .. tmp[i] .. 'px;min-width:' .. tmp[i] .. 'px;' |
||
else |
else |
||
q.text_width[i + 3] = 'width:' .. tmp[i] .. ';' |
q.text_width[i + 3] = 'width:' .. tmp[i] .. ';min-width:' .. tmp[i] .. ';' |
||
end |
end |
||
end |
end |
||
end |
end |
||
q.linfo1_pad = '' |
q.linfo1_pad = '' |
||
elseif #tmp == 1 and tmp[1]~='' then |
elseif #tmp == 1 and tmp[1] ~= '' then |
||
if tonumber(string.sub(tmp[1],-1)) then |
if tonumber(string.sub(tmp[1],-1)) then |
||
q.text_width[5] = 'width:' .. tmp[1] .. 'px;' |
q.text_width[5] = 'width:' .. tmp[1] .. 'px;min-width:' .. tmp[1] .. 'px;' |
||
else |
else |
||
q.text_width[5] = 'width:' .. tmp[1] .. ';' |
q.text_width[5] = 'width:' .. tmp[1] .. ';min-width:' .. tmp[1] .. ';' |
||
end |
end |
||
q.linfo1_pad = '' |
q.linfo1_pad = '' |
||
end |
|||
for i = 1, 6 do |
|||
tmp = tonumber(mw.ustring.match(q.text_width[i], ':([0-9]+%.?[0-9]*)px;')) |
|||
if tmp then |
|||
tmp = tmp*3/40 |
|||
q.text_width[i] = 'width:' .. tmp .. 'em;min-width:' .. tmp .. 'em;' |
|||
end |
|||
end |
end |
||
tmp = {} |
tmp = {} |
||
local index = 0 |
local index = 0 |
||
local rows = {} |
local rows = {} |
||
if not process or process == '' or negative(process) then |
|||
pattern = mw.ustring.gsub(pattern, '\n(#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])', '%1') |
|||
end |
|||
for item in pattern:gmatch('([^\n]*)\n?') do |
for item in pattern:gmatch('([^\n]*)\n?') do |
||
item = mw.text.trim(item) |
item = mw.text.trim(item) |
||
Line 652: | Line 711: | ||
q.text_width[1] = q.text_width[1] .. 'min-width:' .. i18n.html['row-collapsible-left-button-width'] .. ';' |
q.text_width[1] = q.text_width[1] .. 'min-width:' .. i18n.html['row-collapsible-left-button-width'] .. ';' |
||
else |
else |
||
q.text_width[6] = q.text_width[6] .. 'min-width:' .. i18n.html['row-collapsible-right-button-width'] .. ';' |
q.text_width[6] = q.text_width[6] .. 'min-width:' .. i18n.html['row-collapsible-right-button-width'] .. ';' |
||
end |
end |
||
end |
end |
||
Line 660: | Line 719: | ||
end |
end |
||
local function getArgNums(prefix, args) |
|||
local getArgs = require('Module:Arguments').getArgs |
|||
-- Copied from Module:Infobox on enwiki. |
|||
-- Returns a table containing the numbers of the arguments that exist |
|||
local function makeInvokeFunction(funcName) |
|||
-- for the specified prefix. For example, if the prefix were 'data', and |
|||
-- makes a function that can be returned from #invoke, using |
|||
-- 'data1', 'data2', and 'data5' existed, this would return {1, 2, 5}. |
|||
-- [[Module:Arguments]]. |
|||
local nums = {} |
|||
return function (frame) |
|||
for k, v in pairs(args) do |
|||
local args = getArgs(frame, {parentOnly = true}) |
|||
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$') |
|||
return p[funcName](args) |
|||
if num then table.insert(nums, tonumber(num)) end |
|||
end |
end |
||
table.sort(nums) |
|||
end |
|||
return nums |
|||
local function getArgNums(prefix, args) |
|||
-- Copied from Module:Infobox on enwiki. |
|||
-- Returns a table containing the numbers of the arguments that exist |
|||
-- for the specified prefix. For example, if the prefix were 'data', and |
|||
-- 'data1', 'data2', and 'data5' existed, this would return {1, 2, 5}. |
|||
local nums = {} |
|||
for k, v in pairs(args) do |
|||
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$') |
|||
if num then table.insert(nums, tonumber(num)) end |
|||
end |
|||
table.sort(nums) |
|||
return nums |
|||
end |
end |
||
Line 691: | Line 739: | ||
function p._infobox(args) -- Creates a pretty box. |
function p._infobox(args) -- Creates a pretty box. |
||
args.map1, args.tw, args['map1-title'], args['map1-collapsible'], args['map1- |
args.map1, args.tw, args['map1-title'], args['map1-collapsible'], args['map1-collapse'] = args.map1 or args.map, args.tw or args['text-width'] or args['text width'], args['map1-title'] or args['map-title'], args['map1-collapsible'] or args['map-collapsible'], args['map1-collapse'] or args['map1-collapsed'] or args['map-collapse'] or args['map-collapsed'] |
||
local function map_prefix(x) return 'map'..x end |
local function map_prefix(x) return 'map'..x end |
||
local mapnums, prefix = {} |
local mapnums, prefix = {} |
||
Line 704: | Line 752: | ||
table.sort(mapnums) |
table.sort(mapnums) |
||
end |
end |
||
args['title bg color'] = args['title bg color'] or args['title-bg'] or '#27404E' |
args['title bg color'] = args['title bg color'] or args['title bg'] or args['title-bg'] or '#27404E' |
||
args['title color'] = args['title color'] or args['title-color'] or greatercontrast{args['title bg color'], '#FFF', rgb_black} |
args['title color'] = args['title color'] or args['title-color'] or greatercontrast{args['title bg color'], '#FFF', rgb_black} |
||
args.legend = args.legend or '' |
args.legend = args.legend or '' |
||
Line 711: | Line 759: | ||
args.navbar = args.navbar or args.tnavbar |
args.navbar = args.navbar or args.tnavbar |
||
if args.navbar then |
if args.navbar then |
||
navtable = {args.navbar, |
navtable = {args.navbar, mini = i18n.text.navbar_mini, text = i18n.text.navbar_text} |
||
args.navbar = navbar(navtable) |
args.navbar = navbar(navtable) |
||
else |
else |
||
Line 740: | Line 788: | ||
args.fontsize = 100 |
args.fontsize = 100 |
||
else |
else |
||
args.inline2 = 'box-shadow: 0 2px 2px 0 rgba(0, 0, 0, |
args.inline2 = 'box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12), 0 3px 1px -2px rgba(0, 0, 0, .2); -moz-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12), 0 3px 1px -2px rgba(0, 0, 0, .2); -webkit-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12), 0 3px 1px -2px rgba(0, 0, 0, .2);' |
||
args.fontsize = 88 -- as above: CSS rule for .infobox in % |
args.fontsize = 88 -- as above: CSS rule for .infobox in % |
||
end |
end |
||
Line 783: | Line 831: | ||
result = result .. '<div style="float:left;padding-right:5px">' .. args.navbar .. '</div>' |
result = result .. '<div style="float:left;padding-right:5px">' .. args.navbar .. '</div>' |
||
end |
end |
||
args.legend2 = |
args.legend2 = mw.ustring.lower(args.legend) |
||
if args.legend2 ~= 'no' and args.legend2 ~= '0' then |
if args.legend2 ~= 'no' and args.legend2 ~= '0' then |
||
args.legend = i18n.text.legend[args.legend2] or ((args.legend2 ~= '') and ('[['..args.legend) or i18n.text.legend.default) |
|||
local legtable = {['water']={'canal','water','waterway'},['foot']={'foot','footpath','walkway'}} |
|||
args.legend = args.legend .. '|' .. (args['legend alt'] or i18n.text.legend_text) .. ']]' |
|||
for k, v in pairs(legtable) do |
|||
for _, name in ipairs(v) do |
|||
if args.legend2 == name then args.legend2 = k end |
|||
end |
|||
end |
|||
if args.legend2 == 'water' then args.legend = '[[Template:Waterways legend' |
|||
elseif args.legend2 == 'foot' then args.legend = '[[Template:Trails legend' |
|||
elseif args.legend2 == 'bus' then args.legend = '[[Template:Bus route legend' |
|||
elseif args.legend2 == 'track' then args.legend = '[[Template:Railway track legend' |
|||
elseif args.legend ~= '' then args.legend = '[[' .. args.legend |
|||
else args.legend = '[[Template:Railway line legend' |
|||
end |
|||
if args['legend alt'] then |
|||
args.legend = args.legend .. '|' .. args['legend alt'] .. ']]' |
|||
else |
|||
args.legend = args.legend .. '|Legend]]' |
|||
end |
|||
result = result .. '<div class="selfreference noprint" style="text-align:right;font-size:90%;">' .. args.legend .. '</div>' |
result = result .. '<div class="selfreference noprint" style="text-align:right;font-size:90%;">' .. args.legend .. '</div>' |
||
end |
end |
||
Line 817: | Line 849: | ||
args.header_margin = '0 55px' |
args.header_margin = '0 55px' |
||
args.ending = '\n|}' |
args.ending = '\n|}' |
||
if positive(args['map'..v..'-collapsed']) then args.map_collapsed = ' mw-collapsed autocollapse' else args.map_collapsed = '' end |
if positive(args['map'..v..'-collapse']) or positive(args['map'..v..'-collapsed']) then args.map_collapsed = ' mw-collapsed autocollapse' else args.map_collapsed = '' end |
||
result = result..'\n|-\n|\n{|class="mw-collapsible'..args.map_collapsed..'" cellpadding="0" cellspacing="0" style="display: table; min-width:100%; margin:0 auto;"' |
result = result..'\n|-\n|\n{|class="mw-collapsible'..args.map_collapsed..'" cellpadding="0" cellspacing="0" style="display: table; min-width:100%; margin:0 auto;"' |
||
end |
end |
||
Line 826: | Line 858: | ||
if k == 1 then args.border_top = '' else args.border_top = 'border-top: 5px solid '..args.bg..';' end |
if k == 1 then args.border_top = '' else args.border_top = 'border-top: 5px solid '..args.bg..';' end |
||
end |
end |
||
result = result .. '\n|-\n|style="'..args.border_top..'padding:' .. args.padding2 .. '"|\n{|cellpadding="0" cellspacing="0" class="nogrid" style="padding:0px;border:0px;background:transparent;white-space:nowrap;line-height:1.2;font-size:'..(args.fontsize2 * |
result = result .. '\n|-\n|style="'..args.border_top..'padding:' .. args.padding2 .. '"|\n{|cellpadding="0" cellspacing="0" class="nogrid" style="padding:0px;border:0px;background:transparent;white-space:nowrap;line-height:1.2;font-size:'..(args.fontsize2 * .95)..'%;margin:auto"\n'..localroute(args[prefix(v)], (args['tw'..v] or args['text-width'..v] or args['text width'..v] or args.tw or ''), args.bg, args.process)..'\n|}'..args.ending |
||
end |
end |
||
args.bottom = args.bottom or args.footnote |
args.bottom = args.bottom or args.footnote |
||
Line 832: | Line 864: | ||
if args.inline then args.padding2 = '6px' else args.padding2 = '0px' end |
if args.inline then args.padding2 = '6px' else args.padding2 = '0px' end |
||
result = result .. '\n|-\n|style="line-height:normal;text-align:right;padding:' .. args.padding2 .. ' 5px 5px;'..(args.bottomstyle or args.footnotestyle or '')..'"|' .. args.bottom |
result = result .. '\n|-\n|style="line-height:normal;text-align:right;padding:' .. args.padding2 .. ' 5px 5px;'..(args.bottomstyle or args.footnotestyle or '')..'"|' .. args.bottom |
||
if string.find(args.bottom, '&action=edit') then result = result .. '[ |
if string.find(args.bottom, '&action=edit') then result = result .. (i18n['error-categories']['separate-navbar'] or i18n['error-categories'].default) end |
||
end |
end |
||
if args.navbar ~= '' and args['navbar pos'] == '2' then |
if args.navbar ~= '' and args['navbar pos'] == '2' then |
||
if negative(args['navbar long']) or positive(args['navbar mini']) then navtable.mini = true; args.navbar = navbar(navtable) end |
if negative(args['navbar long']) or positive(args['navbar mini']) then navtable.mini = true; args.navbar = navbar(navtable) end |
||
if args.inline and not args.bottom then args.padding2 = '6px' else args.padding2 = '0px' end |
if args.inline and not args.bottom then args.padding2 = '6px' else args.padding2 = '0px' end |
||
result = result .. '\n|-\n|style="line-height:normal;padding:' .. args.padding2 .. ' 5px 3px;text-align:center"|' .. args.navbar |
result = result .. '\n|-\n|style="line-height:normal;padding:' .. args.padding2 .. ' 5px 3px;text-align:center"|' .. args.navbar |
||
end |
end |
||
return result .. '\n|}' |
return result .. '\n|}' |
||
Line 859: | Line 891: | ||
result = result..';'..style..'">'..rowstart..lh |
result = result..';'..style..'">'..rowstart..lh |
||
if line then result = result..';border-bottom:1px solid gray' end |
if line then result = result..';border-bottom:1px solid gray' end |
||
local bgpad = ';padding-left: |
local bgpad = ';padding-left:.5em;padding-right:.5em' |
||
local function bgtext(v) |
local function bgtext(v) |
||
return ';color:'..greatercontrast{v, '#FFF', rgb_black} |
return ';color:'..greatercontrast{v, '#FFF', rgb_black} |
||
Line 893: | Line 925: | ||
['ch'] = 20.1168, |
['ch'] = 20.1168, |
||
['mi;ch'] = 80, |
['mi;ch'] = 80, |
||
['m'] = 1 / |
['m'] = 1 / .9144, |
||
['yd'] = |
['yd'] = .9144, |
||
['ft'] = |
['ft'] = .3048, |
||
} |
} |
||
local sf = { -- 10 ^ floor(log10(cvt[inp]) + |
local sf = { -- 10 ^ floor(log10(cvt[inp]) + .5); or 10 ^ floor(log10(cvt[inps[1]] * cvt[inp]) + .5) for dual-unit inputs. this corrects the accuracy of result so that it usually has same significant figures |
||
['mi'] = 1, |
['mi'] = 1, |
||
['ch'] = 10, |
['ch'] = 10, |
||
['mi;ch'] = |
['mi;ch'] = .01, |
||
['m'] = 1, |
['m'] = 1, |
||
['yd'] = 1, |
['yd'] = 1, |
||
['ft'] = 1 |
['ft'] = .1, |
||
} |
} |
||
if not inp then inp = 'mi' end |
if not inp then inp = 'mi' end |
||
Line 927: | Line 959: | ||
t1 = v1..' '..outp |
t1 = v1..' '..outp |
||
v1 = tonumber(v1) |
v1 = tonumber(v1) |
||
t2 = floor(v1 / cvt[inps[1]])..' '..inps[1]..' '..floor(v1 % cvt[inps[1]] / cvt[inps[1]] * cvt[inp] * mult * sf[inp] + |
t2 = floor(v1 / cvt[inps[1]])..' '..inps[1]..' '..floor(v1 % cvt[inps[1]] / cvt[inps[1]] * cvt[inp] * mult * sf[inp] + .5) / mult / sf[inp]..' '..inps[2] |
||
else |
else |
||
v1 = split(trim(v1), ';') |
v1 = split(trim(v1), ';') |
||
t1 = v1[1]..' '..inps[1]..' '..v1[2]..' '..inps[2] |
t1 = v1[1]..' '..inps[1]..' '..v1[2]..' '..inps[2] |
||
t2 = floor((tonumber(v1[1]) * cvt[inps[1]] + tonumber(v1[2]) * cvt[inps[1]] / cvt[inp]) * mult / sf[inp] + |
t2 = floor((tonumber(v1[1]) * cvt[inps[1]] + tonumber(v1[2]) * cvt[inps[1]] / cvt[inp]) * mult / sf[inp] + .5) / mult * sf[inp]..' '..outp |
||
end |
end |
||
else |
else |
||
if swap then |
if swap then |
||
v2 = floor(tonumber(v1) / cvt[inp] * mult * sf[inp] + |
v2 = floor(tonumber(v1) / cvt[inp] * mult * sf[inp] + .5) / mult / sf[inp] |
||
inp, outp = outp, inp |
inp, outp = outp, inp |
||
else |
else |
||
v2 = floor(tonumber(v1) * cvt[inp] * mult / sf[inp] + |
v2 = floor(tonumber(v1) * cvt[inp] * mult / sf[inp] + .5) / mult * sf[inp] |
||
end |
end |
||
t1 = v1..' '..inp |
t1 = v1..' '..inp |
||
Line 974: | Line 1,006: | ||
result = result..rowend..'</table> ' |
result = result..rowend..'</table> ' |
||
if bs == 'to' or bs == 'srws' then |
if bs == 'to' or bs == 'srws' then |
||
if t1 == ' ' or t2 == ' ' then result = result.. |
if t1 == ' ' or t2 == ' ' then result = result..(i18n['error-categories']['missing-text-values'] or i18n['error-categories'].default) end |
||
end |
end |
||
if string.find(t1, '<br ?/?>') ~= nil or string.find(t2, '<br ?/?>') ~= nil then result = result..'[ |
if string.find(t1, '<br ?/?>') ~= nil or string.find(t2, '<br ?/?>') ~= nil then result = result..(i18n['error-categories']['br-tags'] or i18n['error-categories'].default) end |
||
if bs == 'split' then |
if bs == 'split' then |
||
if link and t1 and t2 then |
if link and t1 and t2 then |
||
if string.find(link, '^'..t1..' '..t2..' ') then result = result..'[ |
if string.find(link, '^'..t1..' '..t2..' ') then result = result..(i18n['error-categories']['srws'] or i18n['error-categories'].default) end |
||
end |
end |
||
end |
end |
||
Line 991: | Line 1,023: | ||
args[4] = args[4] or args.it or args.i |
args[4] = args[4] or args.it or args.i |
||
args[5] = args[5] or args.b |
args[5] = args[5] or args.b |
||
return base(args[1],args[2],args[3],nil,nil,args[4],nil,args[5],args.align,args.style,args.bg1,args.bg2,args.line,'105%','92%',' |
return base(args[1],args[2],args[3],nil,nil,args[4],nil,args[5],args.align,args.style,args.bg1,args.bg2,args.line,'105%','92%','.9',nil,nil,nil,'to') |
||
end |
end |
||
Line 1,000: | Line 1,032: | ||
args[4] = args[4] or args.it or args.i |
args[4] = args[4] or args.it or args.i |
||
args[5] = args[5] or args.b |
args[5] = args[5] or args.b |
||
return base(args[1],args[2],args[3],nil,args[4],nil,nil,args[5],args.align,args.style,args.bg1,args.bg2,args.line,'inherit','inherit',' |
return base(args[1],args[2],args[3],nil,args[4],nil,nil,args[5],args.align,args.style,args.bg1,args.bg2,args.line,'inherit','inherit','.9',nil,nil,nil,'split') |
||
end |
end |
||
Line 1,009: | Line 1,041: | ||
args[4] = args[4] or args.it or args.i |
args[4] = args[4] or args.it or args.i |
||
args[5] = args[5] or args.b |
args[5] = args[5] or args.b |
||
return base(args[1],args[2],nil,args[3],args[4],nil,nil,args[5],args.align,args.style,args.bg1,args.bg2,args.line,'inherit','inherit',' |
return base(args[1],args[2],nil,args[3],args[4],nil,nil,args[5],args.align,args.style,args.bg1,args.bg2,args.line,'inherit','inherit','.9',nil,nil,nil,'srws') |
||
end |
end |
||
Line 1,015: | Line 1,047: | ||
function p._BScvt(args) |
function p._BScvt(args) |
||
return base(nil,nil,nil,nil,nil,nil,args.alt,nil,args.align,args.style,args.bg1,args.bg2,args.line,'inherit','inherit',' |
return base(nil,nil,nil,nil,nil,nil,args.alt,nil,args.align,args.style,args.bg1,args.bg2,args.line,'inherit','inherit','.9',args[1],args[2],args['in'],'cvt') |
||
end |
end |
||
Line 1,054: | Line 1,086: | ||
end |
end |
||
if not result then |
if not result then |
||
return '<span style="color:#f00">Invalid [[Template:RoutemapRoute]] arrow value "<span style="font-style:italic">'..d..'</span>". |
return '<span style="color:#f00">Invalid [[Template:RoutemapRoute]] arrow value "<span style="font-style:italic">'..d..'</span>".</span>'..(i18n['error-categories']['rmr-error'] or i18n['error-categories'].default) |
||
else |
else |
||
return result |
return result |
||
Line 1,107: | Line 1,139: | ||
end |
end |
||
local count, icons, overlaps, overlapCalc = tonumber(args['$count']) or 1, {}, {}, math.log10(args.n) |
local count, icons, overlaps, overlapCalc = tonumber(args['$count']) or 1, {}, {}, math.log10(args.n) |
||
local text = (args.text and '*') or '' |
|||
if overlapCalc == math.floor(overlapCalc) then overlapCalc = 10^(overlapCalc) else overlapCalc = 10^(math.floor(overlapCalc) + 1) end |
if overlapCalc == math.floor(overlapCalc) then overlapCalc = 10^(overlapCalc) else overlapCalc = 10^(math.floor(overlapCalc) + 1) end |
||
while count <= args.n do |
while count <= args.n do |
||
local cellparams, overlapn = {}, (string.match(count/overlapCalc, '%.(0+)') or '')..count |
local cellparams, overlapn = {}, (string.match(count/overlapCalc, '%.(0+)') or '')..count |
||
table.insert(icons, (args[count] or '')) |
table.insert(icons, (text..(args[count] or ''))) |
||
if args['O'..overlapn] then |
if args['O'..overlapn] then |
||
local iconparams, overlapparams, overlapt = {}, {}, {} |
local iconparams, overlapparams, overlapt = {}, {}, {} |
||
Line 1,130: | Line 1,163: | ||
end |
end |
||
if overlapparams[1] then args['O'..overlapn..v] = args['O'..overlapn..v]..'__'..table.concat(overlapparams, ',') end |
if overlapparams[1] then args['O'..overlapn..v] = args['O'..overlapn..v]..'__'..table.concat(overlapparams, ',') end |
||
table.insert(overlapt, args['O'..overlapn..v]) |
table.insert(overlapt, text..args['O'..overlapn..v]) |
||
end |
end |
||
overlaps = '!~'..args['O'..overlapn]..'!~'..table.concat(overlapt, '!~') |
overlaps = '!~'..text..args['O'..overlapn]..'!~'..table.concat(overlapt, '!~') |
||
else |
else |
||
overlaps = '!~'..args['O'..overlapn] |
overlaps = '!~'..text..args['O'..overlapn] |
||
end |
end |
||
icons[count] = icons[count]..overlaps |
icons[count] = icons[count]..overlaps |
||
Line 1,190: | Line 1,223: | ||
Creates Routemap syntax for a diagram row based on parameters. |
Creates Routemap syntax for a diagram row based on parameters. |
||
Simplified version; an in-app upgrade to the full version costs US$0.99. |
|||
Intended to be used to substitute legacy templates. |
Intended to be used to substitute legacy templates. |
||
Note that for compatibility the link and sidebar parameter names are different. |
Note that for compatibility the link and sidebar parameter names are different. |
||
Line 1,202: | Line 1,234: | ||
end |
end |
||
local count, icons, overlaps, overlapCalc = tonumber(args['$count']) or 1, {}, {}, math.log10(args.n) |
local count, icons, overlaps, overlapCalc = tonumber(args['$count']) or 1, {}, {}, math.log10(args.n) |
||
local text = (args.text and '*') or '' |
|||
if overlapCalc == math.floor(overlapCalc) then overlapCalc = 10^(overlapCalc) else overlapCalc = 10^(math.floor(overlapCalc) + 1) end |
if overlapCalc == math.floor(overlapCalc) then overlapCalc = 10^(overlapCalc) else overlapCalc = 10^(math.floor(overlapCalc) + 1) end |
||
while count <= args.n do |
while count <= args.n do |
||
local cellparams, overlapn = {}, (string.match(count/overlapCalc, '%.(0+)') or '')..count |
local cellparams, overlapn = {}, (string.match(count/overlapCalc, '%.(0+)') or '')..count |
||
table.insert(icons, (args[count] or '')) |
table.insert(icons, (text..(args[count] or ''))) |
||
if args['O'..overlapn] then |
if args['O'..overlapn] then |
||
local overlapt = {} |
local overlapt = {} |
||
Line 1,211: | Line 1,244: | ||
table.sort(overlaps) |
table.sort(overlaps) |
||
if overlaps[1] then |
if overlaps[1] then |
||
for i, v in ipairs(overlaps) do table.insert(overlapt, args['O'..overlapn..v]) end |
for i, v in ipairs(overlaps) do table.insert(overlapt, text..args['O'..overlapn..v]) end |
||
overlaps = '!~'..args['O'..overlapn]..'!~'..table.concat(overlapt, '!~') |
overlaps = '!~'..text..args['O'..overlapn]..'!~'..table.concat(overlapt, '!~') |
||
else |
else |
||
overlaps = '!~'..args['O'..overlapn] |
overlaps = '!~'..text..args['O'..overlapn] |
||
end |
end |
||
icons[count] = icons[count]..overlaps |
icons[count] = icons[count]..overlaps |
||
Line 1,277: | Line 1,310: | ||
res = string.gsub(res, '{|%s?{{[Rr]ailway line header}}', '{{Routemap') |
res = string.gsub(res, '{|%s?{{[Rr]ailway line header}}', '{{Routemap') |
||
res = string.gsub(res, '{{[Bb][Ss]%-header%d?|', '{{safesubst:BS-header/safesubst|') -- "%d?" means optional digit in case use of variant template like BS-header3. |
res = string.gsub(res, '{{[Bb][Ss]%-header%d?|', '{{safesubst:BS-header/safesubst|') -- "%d?" means optional digit in case use of variant template like BS-header3. |
||
res = string.gsub(res, '{{[Bb][Ss]%-table%d?}}', '|map=') |
res = string.gsub(res, '{{[Bb][Ss]%-table%d?}}', '|map =') |
||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)|', '{{safesubst:BS%1%2/safesubst|') |
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)|', '{{safesubst:BS%1%2/safesubst|') |
||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-replace|', '!replace{{safesubst:BS%1%2/safesubst|') |
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-replace|', '!replace{{safesubst:BS%1%2/safesubst|') |
||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-startCollapsible|', '-startCollapsible-collapsed\n{{safesubst:BS%1%2/safesubst|') |
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-startCollapsible|', '-startCollapsible-collapsed\n{{safesubst:BS%1%2/safesubst|') |
||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-sc|', '-startCollapsible-collapsed\n{{safesubst:BS%1%2/safesubst|') |
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-sc|', '-startCollapsible-collapsed\n{{safesubst:BS%1%2/safesubst|') |
||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%text|', '{{safesubst:BS%1%2text/safesubst|') |
|||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-2|', '{{safesubst:BS%1%2-2/safesubst|') |
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-2|', '{{safesubst:BS%1%2-2/safesubst|') |
||
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-2replace|', '!replace{{safesubst:BS%1%2-2|') |
res = string.gsub(res, '{{[Bb][Ss](%d?)(%d?)%-2replace|', '!replace{{safesubst:BS%1%2-2|') |
||
Line 1,287: | Line 1,321: | ||
res = string.gsub(res, '{{!}}}', '-endCollapsible-') |
res = string.gsub(res, '{{!}}}', '-endCollapsible-') |
||
res = string.gsub(res, '{{[Ee]nd}}', '-endCollapsible-') |
res = string.gsub(res, '{{[Ee]nd}}', '-endCollapsible-') |
||
res = string.gsub(res, '|}\n|}', '}}') -- Replace ending of Railway line header map setup. |
res = string.gsub(res, '|}\n?|}', '}}') -- Replace ending of Railway line header map setup. |
||
res = string.gsub(res, '{{[Bb][Ss]%-colspan}}\n{{safesubst', '{{safesubst') -- BS-colspan is unnecessary and would cause error in Routemap. |
res = string.gsub(res, '{{[Bb][Ss]%-colspan}}\n{{safesubst', '{{safesubst') -- BS-colspan is unnecessary and would cause error in Routemap. |
||
res = string.gsub(res, '{{[Bb][Ss]%-colspan}}\n%-%-%-%-', '-colspan-2\n----') |
res = string.gsub(res, '{{[Bb][Ss]%-colspan}}\n%-%-%-%-', '-colspan-2\n----') |
||
res = string.gsub(res, '<', '<') |
res = string.gsub(res, '<', '<') |
||
res = string.gsub(res, '>', '>') |
res = string.gsub(res, '>', '>') |
||
if string.find(res, '!replace') or string.find(res, ' |
if string.find(res, '!replace') or string.find(res, '|%s*bg%s*=') then |
||
local restable = mw.text.split(res, '\n') |
local restable = mw.text.split(res, '\n') |
||
for i, v in ipairs(restable) do |
for i, v in ipairs(restable) do |
||
Line 1,299: | Line 1,333: | ||
restable[i-2] = string.gsub(restable[i-2], 'collapsed', 'collapsed-replace') |
restable[i-2] = string.gsub(restable[i-2], 'collapsed', 'collapsed-replace') |
||
end |
end |
||
if (string.find(v, '|%s*bg%s*=%s*#?[a-zA-Z0-9]+') or string.find(v, '|%s*bg%s*=%s*#?{{[^{}]+}}%s*|') or string.find(v, '|%s*bg%s*=%s*#?{{[^{}]+}}%s*}}')) and string.find(restable[i-1], '^-startCollapsible') then |
|||
if string.find(v, '{{[Bb][Ss]%d*text') then |
|||
local bg = string.match(v, '|%s*bg%s*=%s*(#?[a-zA-Z0-9]+)') or string.find(v, '|%s*bg%s*=%s*(#?{{[^{}]+}})%s*|') or string.find(v, '|%s*bg%s*=%s*(#?{{[^{}]+}})%s*}}') |
|||
local tmp = {} |
|||
restable[i] = |
restable[i] = string.gsub(restable[i], '|%s*bg%s*=%s*'..bg, '') |
||
restable[i |
restable[i-1] = string.gsub(restable[i-1], '%-?$', '--bg=')..bg |
||
if string.find(restable[i+1], '!replace') then |
|||
restable[i+1] = string.gsub(restable[i+1], '!replace', '') |
|||
if q > 1 then |
|||
restable[i-1] = string.gsub(restable[i-1], 'collapsed%-', 'collapsed-replace') |
|||
if (string.find(restable[i+1], '|%s*bg%s*=%s*#?[a-zA-Z0-9]+') or string.find(restable[i+1], '|%s*bg%s*=%s*#?{{[^{}]+}}%s*|') or string.find(restable[i+1], '|%s*bg%s*=%s*#?{{[^{}]+}}%s*}}')) then |
|||
if r ~= '' then table.insert(tmp, '*'..r..'\\') else table.insert(tmp, '\\') end |
|||
local bg2 = string.match(restable[i+1], '|%s*bg%s*=%s*(#?[a-zA-Z0-9]+)') or string.find(restable[i+1], '|%s*bg%s*=%s*(#?{{[^{}]+}})%s*|') or string.find(restable[i+1], '|%s*bg%s*=%s*(#?{{[^{}]+}})%s*}}') |
|||
elseif q == (restable[i][1] + 1) then |
|||
if bg2 == bg then restable[i+1] = string.gsub(restable[i], '|%s*bg%s*=%s*'..bg2, '') end |
|||
elseif q == (restable[i][1] + 2) then |
|||
if #restable[i] == q then table.insert(tmp, '~~'..r) else table.insert(tmp, '~~ ~~'..(r or ' ')) end |
|||
elseif q > (restable[i][1] + 2) then |
|||
table.insert(tmp, '~~'..(r or ' ')) |
|||
end |
|||
end |
|||
end |
|||
restable[i] = table.concat(tmp) |
|||
end |
|||
if string.find(v, '{{[Bb][Ss]%d*%-2text') then |
|||
local tmp = {} |
|||
restable[i] = mw.text.split(string.gsub(string.gsub(restable[i], '^{{[Bb][Ss](%d?)(%d?)%-2text', '%1%2'), '}}$', ''), '|') |
|||
restable[i][1] = tonumber(string.match(restable[i][1], '%d+')) or 1 |
|||
for q, r in ipairs(restable[i]) do |
|||
if q > 1 then |
|||
if q <= restable[i][1] then |
|||
if r ~= '' then table.insert(tmp, '*'..r..'\\') else table.insert(tmp, '\\') end |
|||
elseif q == (restable[i][1] + 1) then |
|||
if r ~= '' then table.insert(tmp, '*'..r) end |
|||
elseif q == (restable[i][1] + 2) then |
|||
if not restable[i][restable[i][1] + 4] or restable[i][restable[i][1] + 4] == '' then |
|||
if r ~= '' then table.insert(tmp, 1, r..'! !') end |
|||
elseif r ~= '' then |
|||
table.insert(tmp, 1, r..'~~! !') |
|||
end |
|||
elseif q == (restable[i][1] + 3) then |
|||
if #restable[i] == q or #restable[i] == q+1 then |
|||
if r ~= '' then table.insert(tmp, '~~'..r) end |
|||
else |
|||
table.insert(tmp, '~~ ~~'..(r or ' ')) |
|||
end |
|||
elseif q == (restable[i][1] + 4) then |
|||
if r ~= '' then table.insert(tmp, 1, r..'~~') end |
|||
elseif q > (restable[i][1] + 4) then |
|||
table.insert(tmp, '~~'..(r or ' ')) |
|||
end |
|||
end |
end |
||
end |
end |
||
restable[i] = table.concat(tmp) |
|||
end |
end |
||
end |
end |