local getArgs = require("Module:Arguments").getArgs
local p = {}
--------------------------------------------------------------------------------
---------- Turn division into type ---------------------------------------------
--------------------------------------------------------------------------------
local typeTable = {
["Hwy"] = "Highway",
["Highway"] = "Highway",
["Sudbury"] = "Municipal",
["SB"] = "Municipal",
["Greater Sudbury"] = "Municipal",
["GS"] = "Municipal",
["Brant"] = "County",
["Bruce"] = "County",
["CK"] = "County",
["Chatham-Kent"] = "County",
["Dufferin"] = "County",
["Elgin"] = "County",
["Essex"] = "County",
["Frontenac"] = "County",
["Haldimand"] = "County",
["Grey"] = "County",
["HH"] = "County",
["Haliburton"] = "County",
["Hastings"] = "County",
["Huron"] = "County",
["LG"] = "County",
["Leeds and Grenville"] = "County",
["LA"] = "County",
["Lennox and Addington"] = "County",
["Lambton"] = "County",
["Middlesex"] = "County",
["Norfolk"] = "County",
["Northumberland"] = "County",
["Oxford"] = "County",
["Perth"] = "County",
["PB"] = "County",
["Peterborough"] = "County",
["Prescott and Russell"] = "County",
["PR"] = "County",
["Prince Edward County"] = "County",
["PEC"] = "County",
["Renfrew"] = "County",
["Simcoe"] = "County",
["Stormont, Dundas and Glengarry"] = "County",
["SDG"] = "County",
["Wellington"] = "County",
["Durham"] = "Regional",
["Hamilton"] = "Regional",
["Halton"] = "Regional",
["Niagara"] = "Regional",
["Peel"] = "Regional",
["Ottawa"] = "Regional",
["Waterloo"] = "Regional",
["York"] = "Regional",
["KL"] = "City",
["Kawartha Lakes"] = "City",
["Brant County Highway"] = "County Highway",
["BCH"] = "County Highway",
["Norfolk County Highway"] = "County Highway",
["NCH"] = "County Highway",
["Durham Regional Highway"] = "Regional Highway",
["DRH"] = "Regional Highway",
["Haldimand County Highway"] = "County Highway",
["HCH"] = "County Highway",
}
--------------------------------------------------------------------------------
---------- Turn alt names for division into division ---------------------------
--------------------------------------------------------------------------------
local altDivTable = {
["Hwy"] = "Highway",
["SB"] = "Sudbury",
["GS"] = "Sudbury",
["Greater Sudbury"] = "Sudbury",
["Brant County Highway"] = "Brant",
["BCH"] = "Brant",
["Chatham Kent"] = "Chatham-Kent",
["CK"] = "Chatham-Kent",
["Haldimand County Highway"] = "Haldimand",
["HCH"] = "Haldimand",
["HH"] = "Haliburton",
["LG"] = "Leeds and Grenville",
["LA"] = "Lennox and Addington",
["Norfolk County Highway"] = "Norfolk",
["NCH"] = "Norfolk",
["PB"] = "Peterborough",
["PR"] = "Prescott and Russell",
["PEC"] = "Prince Edward",
["SDG"] = "Stormont, Dundas and Glengarry",
["DRH"] = "Durham",
["Durham Regional Highway"] = "Durham",
["Prince Edward County"] = "Prince Edward",
["KL"] = "Kawartha Lakes",
}
--------------------------------------------------------------------------------
---------- Give code needed to make most pictures ------------------------------
--------------------------------------------------------------------------------
local pictureTable = {
["Essex"] = {"Essex County Road ",".png"},
["York"] = {"York Regional Road ",".svg"},
["Kawartha Lakes"] = {"KawarthaLakesRoad",".png"},
["Durham"] = {"Durham Regional Road ",".svg"},
["Niagara"] = {"Niagara Regional Road ",".svg"},
["Peel"] = {"Peel Regional Road ",".svg"},
["Halton"] = {"Halton Regional Road ",".svg"},
["Simcoe"] = {"Peel Regional Road ",".JPG"},
["Highway"] = {"Ontario ",".svg"},
}
--------------------------------------------------------------------------------
---------- R E T R U N P I C T U R E -------------------------------------------
---------- Return the picture of text ------------------------------------------
--------------------------------------------------------------------------------
local function returnPicture(frame,Type,args,division)
local export;
if not pictureTable[division] then
return "​"
end
local picture = pictureTable[division][1]..args[2]..pictureTable[division][2] or ""
if frame:callParserFunction('#ifexist', 'Media:' .. picture, '1') ~= '' then
if picture then
export = picture
---------- Exceptions for picture rules go here --------------------------------
elseif args[2] == "52" and division == "Simcoe" then
export = "Simcoe county road 52.png"
elseif args[2] == "407" and division == "Highway" then
export = "Highway407crest.png"
elseif args[2] == "QEW" and division == "Highway" then
export = "Ontario QEW.svg"
elseif tonumber(args[2]) >= 500 then
local export = "Ontario Highway "..args[2]..".svg"
end
else
return "​"
end
if frame:callParserFunction('#ifexist', 'Media:' .. export, '1') ~= '' then
if args["size"] then
return table.concat({"[[File:",export,"|alt=|link=|",args["size"],"]]"})
---------- Exceptions for picture size go here ---------------------------------
elseif division == "Highway" then
return table.concat({"[[File:",export,"|alt=|link=|24x22px]]"})
elseif division == "Kawartha Lakes" then
return table.concat({"[[File:",export,"|alt=|link=|21px]]"})
else
return table.concat({"[[File:",export,"|alt=|link=|19px]]"})
end
end
end
--------------------------------------------------------------------------------
---------- R E T U R N T E X T -------------------------------------------------
---------- Returns the text/link -----------------------------------------------
--------------------------------------------------------------------------------
local function returnText(frame,Type,args,division)
local export;
local dis;
if not args["nolink"] then
if args[2] == "QEW" then --EXCEPTION
export = "Queen Elizabeth Way"
elseif Type == "Highway" then
export = "Ontario Highway".." "..args[2]
dis = "Highway".." "..args[2]
elseif Type == "Regional Highway" then
export = division.." Regional Highway".." "..args[2]
elseif Type == "County Highway" then
export = division.." County Highway".." "..args[2]
else
local Type2;
if division == "Kawartha Lakes" then
Type2 = ""
else
Type2 = " "..Type
end
export = division..Type2.." ".."Road".." "..args[2]
dis = Type.." ".."Road".." "..args[2]
end
if frame:callParserFunction('#ifexist',export, '1') ~= '' then
if dis then
export = "[["..export.."|"..dis.."]]"
else
export = "[["..export.."]]"
end
elseif dis then
export = dis
end
end
if not export then
if args[2] == "QEW" then --EXCEPTION
export = "Queen Elizabeth Way"
elseif Type == "Highway" then
export = "Highway".." "..args[2]
elseif Type == "Regional Highway" then
export = division.."Regional Highway".." "..args[2]
elseif Type == "County Highway" then
export = division.."County Highway".." "..args[2]
else
export = Type.." ".."Road".." "..args[2]
end
end
return export
end
--------------------------------------------------------------------------------
---------- A D D P L A C E -----------------------------------------------------
---------- Add name/link for a city/town ---------------------------------------
--------------------------------------------------------------------------------
local function addPlace(frame,export,place,after)
local preExport
if frame:callParserFunction('#ifexist',place..", Ontario", '1') ~= '' then
preExport = "[["..place..", Ontario|"..place.."]]"
else
preExport = place
end
if after == true then
return export..", "..preExport
else
return export.." – "..preExport
end
end
--------------------------------------------------------------------------------
---------- P . S U P P O R T E D -----------------------------------------------
---------- Return all supported "regions" --------------------------------------
--------------------------------------------------------------------------------
function p.supported (frame)
local export = "<u>'''Supported 'Regions''''</u>"
for k,v in pairs(typeTable) do
export = export.."<br />"..k
end
return export
end
--------------------------------------------------------------------------------
---------- P . J C O N ---------------------------------------------------------
---------- Return final picture(s)/text(s) -------------------------------------
--------------------------------------------------------------------------------
function p.jcon (frame)
local args = getArgs(frame)
local Type = typeTable[args[1]]
local division = altDivTable[args[1]] or args[1]
local export = ""
if not args[1] and not args[2] then return "​" end
args["2A"] = args[2]
if args["con"] then args["2B"] = args["con"] end
if args["con2"] then args["2C"] = args["con2"] end
if not args["nosh"] then -- Image
args[2] = args["2A"]
export = returnPicture(frame,Type,args,division) -- Add image
if args["con"] then
args[2] = args["2B"]
export = export.." "..returnPicture(frame,Type,args,division) -- Add image 2
end
if args["con2"] then
args[2] = args["2C"]
export = export.." "..returnPicture(frame,Type,args,division) -- Add image 3
end
if mw.ustring.match(export,"File:") then
export = export.." "
end
end
if not args["notext"] then -- Text
args[2] = args["2A"]
export = export..returnText(frame,Type,args,division) -- Add text/link
if args["con"] then
args[2] = args["2B"]
export = export.." ".."/".." "..returnText(frame,Type,args,division) -- Add text/link 2
end
if args["con2"] then
args[2] = args["2C"]
export = export.." ".."/".." "..returnText(frame,Type,args,division) -- Add text/link 3
end
end
if args["dir"] then -- Direction
export = export.." "..args["dir"]
if args["condir"] then
export=export.."/"..args["condir"]
end
end
if args[3] then -- Name (argument 3)
export = export.." ("..args[3]..")"
end
if args["city"] then -- City 1
export = addPlace(frame,export,args["city"],false)
elseif args["town"] then -- Or town 1
export = addPlace(frame,export,args["town"],false)
end
if args["city2"] then -- City 1
export = addPlace(frame,export,args["city2"],true)
elseif args["town2"] then -- Or town 1
export = addPlace(frame,export,args["town2"],true)
end
return export
end
return p;