local p = {}
local getArgsparser = require('Module:ArgumentsRoad data/parser').getArgsparser
local yesno = require('Module:Yesno')
local data = mw.loadData('Module:Sandbox/BrandonXLF/4')
function p.subpages()
-- Generate the wikitext for the picture
local subpages = {
local function pictureWikitext(frame, route, division, roadInfo, args)
'AFR',
local existingFile = ''
'ALB',
local size = args['size'] or 'x20px' -- Image size
'AND',
'ARE',
if roadInfo['pic'] then
'ARG',
local fileName = roadInfo['pic'][1] .. route .. roadInfo['pic'][2] -- Get filename from template
'ARM',
local routeNum = string.gsub(route, '%D', '')
'ASIA',
routeNum = tonumber(routeNum)
'AUS',
'AUT',
-- Override the default format with exceptions for some highways
'AZE',
if division == 'highway' or division == 'toll' then
'BEL',
if route:upper() == '407ETR' then -- Exception for 407 ETR
'BEN',
fileName = 'Highway407crest.png'
'BGD',
elseif routeNum and routeNum >= 500 then -- Exception for secondary and tertiary highways
'BGR',
fileName = 'Ontario Highway ' .. route .. '.svg'
'BIH',
elseif yesno(args['shield']) then
'BLR',
fileName = 'Ontario ' .. route .. '.svg'
end'BLZ',
end'BOL',
'BRA',
'CAN',
if mw.title.new('File:' .. fileName).file.exists then -- Check if the file exists and record it if it does
'CAN/AB',
existingFile = fileName
'CAN/BC',
'CAN/MB',
-- Override default size with exceptions
'CAN/NB',
if route:upper() == '407ETR' then
'CAN/NL',
size = '24px'
'CAN/NS',
elseif division == 'kawartha lakes' then
'CAN/NT',
size = '21px'
'CAN/ON',
elseif routeNum and routeNum >= 800 and division == 'highway' then
'CAN/PE',
size = '20px'
'CAN/QC',
elseif yesno(args['shield']) and division == 'highway' then
'CAN/SK',
size = 'x25px'
'CAN/YT',
elseif division == 'toll' then
size = 'x30pxCHE',
end'CHL',
end'CHN',
'COL',
end
'CRI',
'CYP',
if existingFile == '' and division ~= 'highway' and division ~= 'toll' then -- Check if fallback should be used
'CZE',
local fileName = 'RR ' .. route .. ' jct.svg' -- Get fallback file name
'DEU',
'DJI',
if mw.title.new('File:' .. fileName).file.exists then -- Check if the fallback file exists and recoed it if it does
'DNK',
existingFile = fileName
end'DZA',
'ECU',
end
'ESP',
'EST',
if existingFile == '' then
'EUR',
return '' -- Return nothing if no existing file was found
'FIN',
end
'FRA',
'GBR',
return '[[File:' .. existingFile .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitext
'GEO',
end
'GHA',
'GIB',
-- Generate the text part of the output
'GRC',
local function getText(frame, route, roadInfo, args)
'HKG',
local link
'HRV',
local display
'HUN',
'IDN',
if route:upper() == '407ETR' then -- Exception for the 407 ETR
'IMN',
link = 'Ontario Highway 407'
'IND',
display = '407 ETR'
'IRL',
elseif route:upper() == 'QEW' then -- Exception for the QEW
'IRN',
link = 'Queen Elizabeth Way'
'IRQ',
display = 'Queen Elizabeth Way'
'ISL',
else
'ISR',
link = (roadInfo['prefix'] and roadInfo['prefix'] .. ' ' or '') .. roadInfo['type'] .. ' ' .. route
'ITA',
display = roadInfo['type'] .. ' ' .. route
'JAM',
end
'JOR',
'JPN',
if ((mw.title.new(link).exists or yesno(args['showred'])) and not yesno(args['nolink'])) then -- Check if the link show be shown
'KAM',
return '[[' .. link .. '|' .. display .. ']]' -- Return the link
'KAZ',
else
'KGZ',
return display -- Fallback to returning the display text
'KOR',
end
'KOS',
end
'LAO',
'LKA',
-- Gets the wikitext for a place
'LSO',
local function getPlace(frame, place, args)
'LTU',
if mw.title.new(place .. ', Ontario').exists or yesno(args['showred']) then
'LUX',
return '[[' .. place .. ', Ontario|' .. place .. ']]'
'LVA',
else
'MDA',
return place
'MEX',
end
'MKD',
end
'MMR',
'MNE',
-- Entry function
'MTQ',
function p.jcon(frame)
'MYS',
local args = getArgs(frame)
'NAM',
'NIC',
local roadType = args[1]:lower() or '' -- Get the route type (region)
'NIR',
local route = args[2] or '' -- Get the route number
'NLD',
'NOR',
local removeRegex = { -- Regex to remove from lowercase input
'^ NPL',
'^municipality ofNZL',
'^city ofOMN',
'^region ofPAK',
'^county ofPER',
' $PHL',
'regional road$PK',
'region$POL',
'county$PRT',
'county road$ROU',
'RUS',
'SAD',
'SRB',
'SVK',
'SVN',
'SWE',
'THA',
'TUR',
'TWN',
'UKR',
'URY',
'USA',
'USA/AK',
'USA/AL',
'USA/AR',
'USA/AS',
'USA/AZ',
'USA/CA',
'USA/CO',
'USA/CT',
'USA/DC',
'USA/DE',
'USA/FL',
'USA/GA',
'USA/GU',
'USA/HI',
'USA/IA',
'USA/ID',
'USA/IL',
-- 'USA/IN',
'USA/KS',
'USA/KY',
'USA/LA',
'USA/MA',
'USA/MD',
'USA/ME',
'USA/MI',
'USA/MN',
'USA/MO',
'USA/MP',
'USA/MS',
'USA/MT',
'USA/NC',
'USA/ND',
'USA/NE',
'USA/NH',
'USA/NJ',
'USA/NM',
'USA/NV',
'USA/NY',
'USA/OH',
'USA/OK',
'USA/OR',
'USA/PA',
'USA/PR',
'USA/RI',
'USA/SC',
'USA/SD',
'USA/TN',
'USA/TX',
'USA/UT',
'USA/VA',
'USA/VI',
'USA/VT',
'USA/WA',
'USA/WI',
'USA/WV',
'USA/WY',
'UZB',
'VEN',
'VNM',
'ZAF'
}
local out = ''
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
for _, subpage in ipairs(subpages) do
local export = ''
local data = require('Module:Road data/strings/' .. subpage)
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 .. ' ' 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 yesno(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 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 .. ' ' 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 yesno(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 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
if type(data) == 'table' then
table.insert(reverseAliases[name], alias)
end
for roadType, info in pairs(data) do
shield = parser({
local list = mw.html.create('ul') -- Create output element
['route'] = '1'
}, 'shieldmain', roadType, 'Module:Road data/strings/' .. subpage)
for name, info in pairs(data.types) do -- Create tables for each region
nameList = list
if type(shield) == 'table' then
:tag('li')
if shield[0] then
:wikitext(info['prefix'] and info['prefix'] .. ' ' or '', info['type'])
out = out .. '<br>' .. ('[[File:%s|x25px|alt=|link=]]'):format(shield[0])
:tag('ul')
:tag('li') end
elseif shield then
:wikitext(name)
out = out .. '<br>' .. ('[[File:%s|x25px|alt=|link=]]'):format(shield)
:done()
end
if reverseAliases[name] then -- Display aliases
for _, alias in ipairs(reverseAliases[name]) do
nameList
:tag('li')
:wikitext(alias)
end
end
end
return out
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
|