Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
Use yesno
Tag: Reverted
Theme navbox-image
 
(60 intermediate revisions by the same user not shown)
Line 1:
-- Sandbox, do not delete
 
return {
local p = {}
aria_label = 'Navbox',
local getArgs = require('Module:Arguments').getArgs
nowrap_item = '%s<span class="nowrap">%s</span>',
local yesno = require('Module:Yesno')
templatestyles = mw.getCurrentFrame():extensionTag{
local data = mw.loadData('Module:Sandbox/BrandonXLF/4')
name = 'templatestyles', args = { src = 'User:BrandonXLF/styles2.css' }
 
},
-- Generate the wikitext for the picture
hlist_templatestyles = 'Hlist/styles.css',
local function pictureWikitext(frame, route, division, roadInfo, args)
plainlist_templatestyles = 'Plainlist/styles.css',
local existingFile = ''
-- do not localize marker table
local size = args['size'] or 'x20px' -- Image size
marker = {
 
oddeven = '\127_ODDEVEN_\127',
if roadInfo['pic'] then
restart = '\127_ODDEVEN0_\127',
local fileName = roadInfo['pic'][1] .. route .. roadInfo['pic'][2] -- Get filename from template
regex = '\127_ODDEVEN(%d?)_\127'
local routeNum = string.gsub(route, '%D', '')
},
routeNum = tonumber(routeNum)
category = {
 
orphan = '[[Category:Navbox orphans]]',
-- Override the default format with exceptions for some highways
horizontal_lists = 'Navigational boxes without horizontal lists',
if division == 'highway' or division == 'toll' then
background_colors = 'Navboxes using background colours',
if route:upper() == '407ETR' then -- Exception for 407 ETR
illegible = 'Potentially illegible navboxes',
fileName = 'Highway407crest.png'
borders = 'Navboxes using borders',
elseif routeNum and routeNum >= 500 then -- Exception for secondary and tertiary highways
},
fileName = 'Ontario Highway ' .. route .. '.svg'
keyword = {
elseif yesno(args['shield']) then
border_subgroup = 'subgroup',
fileName = 'Ontario ' .. route .. '.svg'
border_child = 'child',
end
border_none = 'none',
end
evenodd_swap = 'swap',
 
navbar_off = 'off',
if mw.title.new('File:' .. fileName).file.exists then -- Check if the file exists and record it if it does
navbar_plain = 'plain',
existingFile = fileName
nocat_false = 'false',
 
nowrapitems_yes = 'yes',
-- Override default size with exceptions
orphan_yes = 'yes',
if route:upper() == '407ETR' then
sizestate_collapsed = '24pxcollapsed',
state_off = 'off',
elseif division == 'kawartha lakes' then
sizestate_plain = '21pxplain',
subgroups = {'subgroup', 'child', ''},
elseif routeNum and routeNum >= 800 and division == 'highway' then
sizesubpage_doc = '20pxdoc',
subpage_sandbox = 'sandbox',
elseif yesno(args['shield']) and division == 'highway' then
sizesubpage_testcases = 'x25pxtestcases',
elseif divisiontracking_no == 'tollno' then
},
size = 'x30px'
class = {
end
autocollapse = 'autocollapse',
end
collapsible = 'mw-collapsible',
end
collapsed = 'mw-collapsed',
-- Warning
if existingFile == '' and division ~= 'highway' and division ~= 'toll' then -- Check if fallback should be used
navbox = 'navbox', -- WMF currently hides 'navbox' from mobile,
local fileName = 'File:RR ' .. route .. ' jct.svg' -- Get fallback file name
-- so you probably shouldn't change the navbox class.
 
navbox_abovebelow = 'navbox-abovebelow notheme',
if mw.title.new('File:' .. fileName).file.exists then -- Check if the fallback file exists and recoed it if it does
navbox_group = 'navbox-group notheme',
existingFile = existingFile
navbox_image = 'navbox-image',
end
navbox_inner = 'navbox-inner notheme',
end
navbox_list = 'navbox-list notheme',
 
navbox_list_with_group = 'navbox-list-with-group',
if existingFile == '' then
navbox_part = 'navbox-', -- do not l10n
return '' -- Return nothing if no existing file was found
navbox_styles = 'navbox-styles',
end
navbox_subgroup = 'navbox-subgroup',
navbox_title = 'navbox-title notheme', -- l10n only if you change pattern.navbox_title below
return '[[File:' .. existingFile .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitext
navbox_odd_part = 'odd', -- do not l10n
end
navbox_even_part = 'even', -- do not l10n
 
nomobile = 'nomobile',
-- Generate the text part of the output
nowraplinks = 'nowraplinks',
local function getText(frame, route, roadInfo, args)
noviewer = 'noviewer' -- used to remove images from MediaViewer
local link
},
local display
pattern = {
 
listnum = '^list(%d+)$',
if route:upper() == '407ETR' then -- Exception for the 407 ETR
linkclass = 'Ontario Highway 407class',
displaysandbox = '407 ETR/sandbox$',
navbox = 'Template:Navbox',
elseif route:upper() == 'QEW' then -- Exception for the QEW
linknowrap = 'Queen^<span Elizabeth Wayclass="nowrap">',
displaystyle = 'Queen Elizabeth Waystyle$',
navbox_title = '<th[^>]*"navbox%-title"',
else
hlist = 'hlist',
link = (roadInfo['prefix'] and roadInfo['prefix'] .. ' ' or '') .. roadInfo['type'] .. ' ' .. route
plainlist = 'plainlist',
display = roadInfo['type'] .. ' ' .. route
end},
arg = {
above = 'above',
if (frame:callParserFunction('#ifexist', link, '1') ~= '' or args['showred']) and not args['nolink'] then -- Check if the link show be shown
aboveclass = 'aboveclass',
return '[[' .. link .. '|' .. display .. ']]' -- Return the link
abovestyle = 'abovestyle',
else
basestyle = 'basestyle',
return display -- Fallback to returning the display text
bodyclass = 'bodyclass',
end
bodystyle = 'bodystyle',
end
border = 'border',
 
below = 'below',
-- Gets the wikitext for a place
belowclass = 'belowclass',
local function getPlace(frame, place, args)
belowstyle = 'belowstyle',
if frame:callParserFunction('#ifexist', place .. ', Ontario', '1') ~= '' or args['showred'] then
evenodd = 'evenodd',
return '[[' .. place .. ', Ontario|' .. place .. ']]'
evenstyle = 'evenstyle',
else
group1 = 'group1',
return place
group2 = 'group2',
end
group_and_num = 'group%d',
end
groupstyle_and_num = 'group%dstyle',
 
groupclass = 'groupclass',
-- Entry function
groupstyle = 'groupstyle',
function p.jcon(frame)
groupwidth = 'groupwidth',
local args = getArgs(frame)
innerstyle = 'innerstyle',
 
image = 'image',
local roadType = args[1]:lower() or '' -- Get the route type (region)
imageclass = 'imageclass',
local route = args[2] or '' -- Get the route number
imageleft = 'imageleft',
 
imageleftstyle = 'imageleftstyle',
local removeRegex = { -- Regex to remove from lowercase input
imagesetyle = 'imagestyle',
'^ ',
list_and_num = 'list%d',
'^municipality of',
listclass_and_num = 'list%dclass',
'^city of',
liststyle_and_num = 'list%dstyle',
'^region of',
list1padding = 'list1padding',
'^county of',
listclass = 'listclass',
' $',
listpadding = 'listpadding',
'regional road$',
liststyle = 'liststyle',
'region$',
name = 'county$name',
'countynavbar road$= 'navbar',
navboxclass = 'navboxclass',
nocat = 'nocat',
nowrapitems = 'nowrapitems',
oddstyle = 'oddstyle',
orphan = 'orphan',
state = 'state',
style = 'style',
templatestyles = 'templatestyles',
child_templatestyles = 'child templatestyles',
title = 'title',
titleclass = 'titleclass',
titlestyle = 'titlestyle',
tracking = 'tracking'
},
-- names of navbar arguments
navbar = {
name = 1,
fontstyle = 'fontstyle',
mini = 'mini'
}
}
 
for _,v in ipairs(removeRegex) do
roadType = mw.ustring.gsub(roadType, v, '') -- Remove items in removeRegex from the road type
end
 
roadType = data.aliases[roadType] or roadType -- Transform alias into proper name
 
if data.signs[roadType] or data.signs[route:lower()] then
return data.signs[roadType] or data.signs[route:lower()] -- Return signs symbols like airport and hospital
end
 
local roadInfo = data.types[roadType] -- Get road type info from the data module
 
if not roadInfo or not route then
return '&#8203;' -- Return ZWSP if road type is not supported or the route is not specified
end
local export = ''
local picture = ''
 
if yesno(args['ot']) then -- Set correct arguments if output should be only text
args['nosh'] = 'yes'
args['nolink'] = 'yes'
end
 
-- Define the picture
if not yesno(args['nosh']) then -- If allowed to add shield
picture = pictureWikitext(frame, route, roadType, roadInfo, args) -- Return picture of road 1
if args['con'] then
if picture ~= '' then picture = picture .. '&nbsp;' end -- Add a NBSP if there's already a picture
picture = picture .. pictureWikitext(frame, args['con'], roadType, roadInfo, args) -- Add the picture of the first concurrency
end
 
if args['con2'] then
if picture ~= '' then picture = picture .. '&nbsp;' end -- Add a NBSP if there's already a picture
picture = picture .. pictureWikitext(frame, args['con2'], roadType, roadInfo, args) -- Add the picture of the second concurrency
end
 
if yesno(args['tch']) then
if picture ~= '' then picture = picture .. '&nbsp;' end -- Add a NBSP if there's already a picture
picture = picture .. '[[File:TCH-blank.svg|x20px]]' -- Add the TCH picture
end
end
if not yesno(args['pic aft']) then
export = picture -- Add the picture if it goes first
end
 
-- Define the text
if not yesno(args['notext']) then -- If allowed to show text
if export ~= '' then export = export .. '&nbsp;' end -- Add a NBSP after the picture if it exists
export = export .. getText(frame, route, roadInfo, args) -- Return text of road 1
if args['con'] then
export = export .. '&nbsp;/ ' .. getText(frame, args['con'], roadInfo, args) -- Add the text of the first concurrency
end
if args['con2'] then
export = export .. '&nbsp;/ ' .. getText(frame, args['con2'], roadInfo, args) -- Add the text of the second concurrency
end
if yesno(args['tch']) then
export = export .. '&nbsp;/ [[Trans-Canada Highway|TCH]]' -- Add the TCH text
end
end
local dirs = {} -- Table to store directions
if args['dir'] then
table.insert(dirs, args['dir']) -- Add the primary direction
end
 
if args['condir'] then
table.insert(dirs, args['condir']) -- Add the first concurrency direction
end
 
if args['condir2'] then
table.insert(dirs, args['condir2']) -- Add the second concurrency direction
end
dirs = table.concat(dirs, '/') -- Concat the directions into a single string
if dirs ~= '' then
export = export .. ' – ' .. dirs -- Add the directions to the output
end
 
-- Add the name to the text output
if args[3] then
export = export .. ' (' .. args[3] .. ')'
end
local cities = {} -- Table to store cities
 
if args['city'] or args['town'] then
table.insert(cities, getPlace(frame, args['city'] or args['town'], args)) -- Add the first city
end -- Add the first city
if args['city2'] or args['town2'] then
table.insert(cities, getPlace(frame, args['city2'] or args['town2'], args)) -- Add the second city
end -- Add the second city
cities = table.concat(cities, ', ') -- Concat the cities into a single string
if cities ~= '' then
export = export .. ' – ' .. cities -- Add the cities to the output
end
 
if yesno(args['pic aft']) and picture then
if export ~= '' then export = export .. ' ' end -- Add a space if export already has text
export = export .. picture -- Add the picture if it goes last
end
 
return export
end
 
-- Generates a list of supported regions
function p.supported(frame)
local reverseAliases = {}
 
for alias, name in pairs(data.aliases) do -- Reverse the alias table to allow lookup by name
if not reverseAliases[name] then
reverseAliases[name] = {}
end
table.insert(reverseAliases[name], alias)
end
local list = mw.html.create('ul') -- Create output element
 
for name, info in pairs(data.types) do -- Create tables for each region
nameList = list
:tag('li')
:wikitext(info['prefix'] and info['prefix'] .. ' ' or '', info['type'])
:tag('ul')
:tag('li')
:wikitext(name)
:done()
if reverseAliases[name] then -- Display aliases
for _, alias in ipairs(reverseAliases[name]) do
nameList
:tag('li')
:wikitext(alias)
end
end
end
 
mtoSignList = list
:tag('li')
:wikitext('MTO signs')
:tag('ul')
for sign, wikitext in pairs(data.signs) do
mtoSignList -- Add the sign name and image to the MTO sign list
:tag('li')
:wikitext(sign, ' ', wikitext)
if reverseAliases[sign] then -- Display aliases
for _, alias in ipairs(reverseAliases[sign]) do
mtoSignList -- Add the sign name and image to the MTO sign list
:tag('li')
:wikitext(alias, ' ', wikitext)
end
end
end
 
return tostring(list)
end
 
return p