Module:Adjacent stations/sandbox: Difference between revisions

Content deleted Content added
sync with live
No edit summary
Line 535:
function p._icon(args, frame)
local system = args[1] or args.system
local linedata = args[2] or args.linedata
local line_type = args[3] or args.type
if not system orand not data then
local data = args.data
return
if system or data then
end
data = data or getData(system)
 
data = data or getData(system)
local icon
local icon_format
local line_name = args[2] or args.line
line = (getLine(data, lineline_name))
 
local icon
line = (getLine(data, line))
local icon_format
 
if line then
local default = data.lines._default or {}
if line_type then
if default and default.icon then
line_type = data['aliases'] and data['aliases'][mw.ustring.lower(line_type)] or line_type
icon = mw.ustring.gsub(iconline.title, tmp[1], size .. '%%1', line_name)
line_type = line['types'] and line['types'][line_type] -- If there's no type table or entry for this type, then it can't have its own icon
end
icon_format = line_type['icon format'] or data['type icon format']
icon = line_type['icon']
local line_type = args[3] or args.type
end
if not (icon_format or icon)line_type then
line_type = data['.aliases'] and data['.aliases'][mw.ustring.lower(line_type)] or line_type
icon_format = line['icon format'] or data['line icon format']
line_type = line['.types'] and line['.types'][line_type] -- If there's no type table or entry for this type, then it can't have its own icon
icon = line['icon']
icon_format = line_type['icon format'] or data['type icon format']
}
if line_type.icon then
icon = line_type['.icon']
end
end
if not (icon_format or icon) then
 
icon_format = line['icon format'] or data['line icon format']
if not (icon_format or icon) then
icon_format = data['system icon format']
icon = data['system icon']
end
if not icon then
icon = line['.icon']
end
end
 
if not icon_format then
icon_format = data['system icon format']
if icon_format ~= 'image' then return p._box({data = data, [2] = (args[2] or args.line), [3] = icon_format, type = (args[3] or args.type), bold = args.bold, link = args.link}, frame) end
end
 
if not icon then
icon = data['system icon']
end
if icon_format then
if icon_format ~= 'image' then
if icon_format ~= 'image' then return p._box({data = data, [2] = (args[2] or args.line), [3] = icon_format, type = (args[3] or args.type), bold = args.bold, link = args.link}, frame) end
end
end
 
local size = args.size
if size then
if mw.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
local tmp = {
'|%s*%d*x?%d+px%s*([%]|])', -- '|%s*upright=%d+%.?%d*%s*([%]|])', '|%s*upright%s*([%]|])'
}
if mw.ustring.match(icon, tmp[1]) then
icon = mw.ustring.gsub(icon, tmp[1], size .. '%1')
-- elseif mw.ustring.match(icon, tmp[2]) then
-- icon = gsub(icon, tmp[2], size .. '%1')
-- elseif mw.ustring.match(icon, tmp[3]) then
-- icon = gsub(icon, tmp[3], size .. '%1')
else
icon = mw.ustring.gsub(icon, '(%[%[[^%]|]+)([%]|])', '%1' .. size .. '%2')
end
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
local tmpregex = {
'|%s*%d*x?%d+px%s*([%]|])', -- '|%s*upright=%d+%.?%d*%s*([%]|])', '|%s*upright%s*([%]|])'
}
if mw.ustring.match(icon, tmpregex[1]) then
icon = mw.ustring.gsub(icon, tmp[1], size .. '%1')
-- elseif mw.ustring.match(icon, tmp[2]) then
-- icon = gsub(icon, tmp[2], size .. '%1')
-- elseif mw.ustring.match(icon, tmp[3]) then
-- icon = gsub(icon, tmp[3], size .. '%1')
else
icon = mw.ustring.gsub(icon, '(%[%[[^%]|]+)([%]|])', '%1' .. size .. '%2')
end
end
 
local link = args.link
if link then
if mw.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
end
 
local alt = args.alt or link
if alt then
if mw.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
end
 
if args.name then
if line and line.title then
return icon .. " " .. line.title
end
return icon .. " " .. data["system title"]
end
return icon .. " " .. data["system title"]
end
 
return icon
end