Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
No edit summary
Theme navbox-image
 
(63 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 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',
 
-- do not localize marker table
if roadInfo['pic'] then
marker = {
local fileName = roadInfo['pic'][1] .. route .. roadInfo['pic'][2] -- Get filename from template
oddeven = '\127_ODDEVEN_\127',
 
restart = '\127_ODDEVEN0_\127',
-- Override the default format with exceptions for some highways
regex = '\127_ODDEVEN(%d?)_\127'
if division == 'highway' or division == 'toll' then
},
highwayNumber = string.gsub(route, '%D', '')
category = {
highwayNumber = tonumber(highwayNumber)
orphan = '[[Category:Navbox orphans]]',
horizontal_lists = 'Navigational boxes without horizontal lists',
if route:upper() == '407ETR' then -- Picture exceptions
background_colors = 'Navboxes using background colours',
fileName = 'Highway407crest.png'
illegible = 'Potentially illegible navboxes',
elseif route:upper() == 'QEW' and args['shield'] == 'yes' then
borders = 'Navboxes using borders',
fileName = 'Ontario QEW.svg'
},
elseif route:upper() == 'QEW' and not args['shield'] then
keyword = {
fileName = 'Ontario QEW crown.svg'
border_subgroup = 'subgroup',
elseif args['shield'] == 'yes' and highwayNumber and highwayNumber >= 500 then
border_child = 'child',
fileName = 'Ontario Highway ' .. route .. '.svg'
border_none = 'none',
elseif args['shield'] == 'yes' then
evenodd_swap = 'swap',
fileName = 'Ontario ' .. route .. '.svg'
navbar_off = 'off',
elseif highwayNumber and highwayNumber >= 500 then
navbar_plain = 'plain',
fileName = 'Ontario Highway ' .. route .. '.svg'
nocat_false = 'false',
end
nowrapitems_yes = 'yes',
end
orphan_yes = 'yes',
state_collapsed = 'collapsed',
if mw.title.new('File:' .. fileName).file.exists then -- Check if the file exists and record it if it does
state_off = 'off',
existingFile = fileName
state_plain = 'plain',
end
subgroups = {'subgroup', 'child', ''},
end
subpage_doc = 'doc',
subpage_sandbox = 'sandbox',
if existingFile == '' and division ~= 'highway' and division ~= 'toll' then -- Check if fallback should be used
subpage_testcases = 'testcases',
local fileName = 'File:RR ' .. route .. ' jct.svg' -- Get fallback file name
tracking_no = 'no'
 
},
if mw.title.new('File:' .. fileName).file.exists then -- Check if the fallback file exists and recoed it if it does
class = {
existingFile = existingFile
autocollapse = 'autocollapse',
end
collapsible = 'mw-collapsible',
end
collapsed = 'mw-collapsed',
 
-- Warning
if existingFile == '' then
navbox = 'navbox', -- WMF currently hides 'navbox' from mobile,
return '' -- Return nothing if no existing file was found
-- so you probably shouldn't change the navbox class.
end
navbox_abovebelow = 'navbox-abovebelow notheme',
 
navbox_group = 'navbox-group notheme',
local size = 'x20px' -- Default size
navbox_image = 'navbox-image',
navbox_inner = 'navbox-inner notheme',
-- Override default size with exceptions
navbox_list = 'navbox-list notheme',
if args['size'] then
navbox_list_with_group = 'navbox-list-with-group',
size = args['size']
navbox_part = 'navbox-', -- do not l10n
elseif route:upper() == '407ETR' then
sizenavbox_styles = '24pxnavbox-styles',
navbox_subgroup = 'navbox-subgroup',
elseif division == 'kawartha lakes' then
navbox_title = 'navbox-title notheme', -- l10n only if you change pattern.navbox_title below
size = '21px'
navbox_odd_part = 'odd', -- do not l10n
elseif args['shield'] == 'yes' and division == 'highway' then
navbox_even_part = 'even', -- do not l10n
size = 'x25px'
nomobile = 'nomobile',
elseif division == 'toll' then
sizenowraplinks = 'x30pxnowraplinks',
noviewer = 'noviewer' -- used to remove images from MediaViewer
end
},
pattern = {
return '[[File:' .. existingFile .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitext
listnum = '^list(%d+)$',
end
class = 'class',
 
sandbox = '/sandbox$',
-- Generate the text part of the output
navbox = 'Template:Navbox',
local function getText(frame, route, roadInfo, args)
nowrap = '^<span class="nowrap">',
local link
style = 'style$',
local display
navbox_title = '<th[^>]*"navbox%-title"',
 
hlist = 'hlist',
if route:upper() == '407ETR' then -- Exception for the 407 ETR
plainlist = 'plainlist',
link = 'Ontario Highway 407'
},
display = '407 ETR'
arg = {
elseif route:upper() == 'QEW' then -- Exception for the QEW
linkabove = 'Queen Elizabeth Wayabove',
aboveclass = 'aboveclass',
display = 'Queen Elizabeth Way'
abovestyle = 'abovestyle',
else
basestyle = 'basestyle',
link = (roadInfo['prefix'] and roadInfo['prefix'] .. ' ' or '') .. roadInfo['type'] .. ' ' .. route
bodyclass = 'bodyclass',
display = roadInfo['type'] .. ' ' .. route
bodystyle = 'bodystyle',
end
border = 'border',
below = 'below',
if (frame:callParserFunction('#ifexist', link, '1') ~= '' or args['showred']) and not args['nolink'] then -- Check if the link show be shown
belowclass = 'belowclass',
return '[[' .. link .. '|' .. display .. ']]' -- Return the link
belowstyle = 'belowstyle',
else
evenodd = 'evenodd',
return display -- Fallback to returning the display text
evenstyle = 'evenstyle',
end
group1 = 'group1',
end
group2 = 'group2',
 
group_and_num = 'group%d',
-- Gets the wikitext for a place
groupstyle_and_num = 'group%dstyle',
local function getPlace(frame, place, args)
groupclass = 'groupclass',
if frame:callParserFunction('#ifexist', place .. ', Ontario', '1') ~= '' or args['showred'] then
groupstyle = 'groupstyle',
return '[[' .. place .. ', Ontario|' .. place .. ']]'
groupwidth = 'groupwidth',
else
innerstyle = 'innerstyle',
return place
image = 'image',
end
imageclass = 'imageclass',
end
imageleft = 'imageleft',
 
imageleftstyle = 'imageleftstyle',
-- Entry function
imagesetyle = 'imagestyle',
function p.jcon(frame)
list_and_num = 'list%d',
local args = getArgs(frame)
listclass_and_num = 'list%dclass',
 
liststyle_and_num = 'list%dstyle',
local roadType = args[1]:lower() or '' -- Get the route type (region)
list1padding = 'list1padding',
local route = args[2] or '' -- Get the route number
listclass = 'listclass',
 
listpadding = 'listpadding',
local removeRegex = { -- Regex to remove from lowercase input
liststyle = 'liststyle',
'^ ',
name = 'name',
'^municipality of',
'^citynavbar of= 'navbar',
navboxclass = 'navboxclass',
'^region of',
'^countynocat of= 'nocat',
nowrapitems = 'nowrapitems',
' $',
oddstyle = 'oddstyle',
'regional road$',
orphan = 'region$orphan',
state = 'county$state',
'countystyle road$= '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 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 .. '&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 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 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 .. '&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 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 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