-- 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 data = mw.loadData('Module:Sandbox/BrandonXLF/4')
templatestyles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'User:BrandonXLF/styles2.css' }
-- Generate the wikitext for the picture
},
local function pictureWikitext(frame, route, division, roadInfo, args)
hlist_templatestyles = 'Hlist/styles.css',
local existingFile = ''
plainlist_templatestyles = 'Plainlist/styles.css',
local size = args['size'] or 'x20px' -- Image size
-- do not localize marker table
marker = {
if roadInfo['pic'] then
oddeven = '\127_ODDEVEN_\127',
local fileName = roadInfo['pic'][1] .. route .. roadInfo['pic'][2] -- Get filename from template
restart = '\127_ODDEVEN0_\127',
local routeNum = string.gsub(route, '%D', '')
regex = '\127_ODDEVEN(%d?)_\127'
routeNum = tonumber(routeNum)
},
category = {
-- Override the default format with exceptions for some highways
orphan = '[[Category:Navbox orphans]]',
if division == 'highway' or division == 'toll' then
horizontal_lists = 'Navigational boxes without horizontal lists',
if route:upper() == '407ETR' then -- Exception for 407 ETR
background_colors = 'Navboxes using background colours',
fileName = 'Highway407crest.png'
illegible = 'Potentially illegible navboxes',
elseif routeNum and routeNum >= 500 then -- Exception for secondary and tertiary highways
borders = 'Navboxes using borders',
fileName = 'Ontario Highway ' .. route .. '.svg'
},
elseif args['shield'] == 'yes' then
keyword = {
fileName = 'Ontario ' .. route .. '.svg'
border_subgroup = 'subgroup',
end
border_child = 'child',
end
border_none = 'none',
evenodd_swap = 'swap',
if mw.title.new('File:' .. fileName).file.exists then -- Check if the file exists and record it if it does
navbar_off = 'off',
existingFile = fileName
navbar_plain = 'plain',
nocat_false = 'false',
-- Override default size with exceptions
nowrapitems_yes = 'yes',
if route:upper() == '407ETR' then
sizeorphan_yes = '24pxyes',
state_collapsed = 'collapsed',
elseif division == 'kawartha lakes' then
sizestate_off = '21pxoff',
state_plain = 'plain',
elseif routeNum and routeNum >= 800 and division == 'highway' then
subgroups = {'subgroup', 'child', ''},
size = '20px'
subpage_doc = 'doc',
elseif args['shield'] == 'yes' and division == 'highway' then
sizesubpage_sandbox = 'x25pxsandbox',
subpage_testcases = 'testcases',
elseif division == 'toll' then
sizetracking_no = 'x30pxno'
},
end
class = {
end
autocollapse = 'autocollapse',
end
collapsible = 'mw-collapsible',
collapsed = 'mw-collapsed',
if existingFile == '' and division ~= 'highway' and division ~= 'toll' then -- Check if fallback should be used
-- Warning
local fileName = 'File:RR ' .. route .. ' jct.svg' -- Get fallback file name
navbox = 'navbox', -- WMF currently hides 'navbox' from mobile,
-- so you probably shouldn't change the navbox class.
if mw.title.new('File:' .. fileName).file.exists then -- Check if the fallback file exists and recoed it if it does
navbox_abovebelow = 'navbox-abovebelow notheme',
existingFile = existingFile
navbox_group = 'navbox-group notheme',
end
navbox_image = 'navbox-image',
end
navbox_inner = 'navbox-inner notheme',
navbox_list = 'navbox-list notheme',
if existingFile == '' then
navbox_list_with_group = 'navbox-list-with-group',
return '' -- Return nothing if no existing file was found
navbox_part = 'navbox-', -- do not l10n
end
navbox_styles = 'navbox-styles',
navbox_subgroup = 'navbox-subgroup',
return '[[File:' .. existingFile .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitext
navbox_title = 'navbox-title notheme', -- l10n only if you change pattern.navbox_title below
end
navbox_odd_part = 'odd', -- do not l10n
navbox_even_part = 'even', -- do not l10n
-- Generate the text part of the output
nomobile = 'nomobile',
local function getText(frame, route, roadInfo, args)
nowraplinks = 'nowraplinks',
local link
noviewer = 'noviewer' -- used to remove images from MediaViewer
local display
},
pattern = {
if route:upper() == '407ETR' then -- Exception for the 407 ETR
linklistnum = 'Ontario Highway 407^list(%d+)$',
displayclass = '407 ETRclass',
sandbox = '/sandbox$',
elseif route:upper() == 'QEW' then -- Exception for the QEW
linknavbox = 'Queen Elizabeth WayTemplate:Navbox',
displaynowrap = 'Queen^<span Elizabeth Wayclass="nowrap">',
style = 'style$',
else
navbox_title = '<th[^>]*"navbox%-title"',
link = (roadInfo['prefix'] and roadInfo['prefix'] .. ' ' or '') .. roadInfo['type'] .. ' ' .. route
hlist = 'hlist',
display = roadInfo['type'] .. ' ' .. route
plainlist = 'plainlist',
end
},
arg = {
if (frame:callParserFunction('#ifexist', link, '1') ~= '' or args['showred']) and not args['nolink'] then -- Check if the link show be shown
above = 'above',
return '[[' .. link .. '|' .. display .. ']]' -- Return the link
aboveclass = 'aboveclass',
else
abovestyle = 'abovestyle',
return display -- Fallback to returning the display text
basestyle = 'basestyle',
end
bodyclass = 'bodyclass',
end
bodystyle = 'bodystyle',
border = 'border',
-- Gets the wikitext for a place
below = 'below',
local function getPlace(frame, place, args)
belowclass = 'belowclass',
if frame:callParserFunction('#ifexist', place .. ', Ontario', '1') ~= '' or args['showred'] then
belowstyle = 'belowstyle',
return '[[' .. place .. ', Ontario|' .. place .. ']]'
evenodd = 'evenodd',
else
evenstyle = 'evenstyle',
return place
group1 = 'group1',
end
group2 = 'group2',
end
group_and_num = 'group%d',
groupstyle_and_num = 'group%dstyle',
-- Entry function
groupclass = 'groupclass',
function p.jcon(frame)
groupstyle = 'groupstyle',
local args = getArgs(frame)
groupwidth = 'groupwidth',
innerstyle = 'innerstyle',
local roadType = args[1]:lower() or '' -- Get the route type (region)
image = 'image',
local route = args[2] or '' -- Get the route number
imageclass = 'imageclass',
imageleft = 'imageleft',
local removeRegex = { -- Regex to remove from lowercase input
imageleftstyle = 'imageleftstyle',
'^ ',
imagesetyle = 'imagestyle',
'^municipality of',
list_and_num = 'list%d',
'^city of',
listclass_and_num = 'list%dclass',
'^region of',
liststyle_and_num = 'list%dstyle',
'^county of',
list1padding = 'list1padding',
' $',
listclass = 'listclass',
'regional road$',
listpadding = 'listpadding',
'region$',
liststyle = 'liststyle',
'county$',
'countyname road$= 'name',
navbar = '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 '​' -- Return ZWSP if road type is not supported or the route is not specified
end
local export = ''
local picture = ''
if args['ot'] then -- Set correct arguments if output should be only text
args['nosh'] = 'yes'
args['nolink'] = 'yes'
end
-- Define the picture
if not 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 .. ' ' 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 .. ' ' 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 args['tch'] then
if picture ~= '' then picture = picture .. ' ' 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 args['pic aft'] then
export = picture -- Add the picture if it goes first
end
-- Define the text
if not args['notext'] then -- If allowed to show text
if export ~= '' then export = export .. ' ' 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 .. ' / ' .. getText(frame, args['con'], roadInfo, args) -- Add the text of the first concurrency
end
if args['con2'] then
export = export .. ' / ' .. getText(frame, args['con2'], roadInfo, args) -- Add the text of the second concurrency
end
if args['tch'] then
export = export .. ' / [[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 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
|