local p = {}
local getArgs = require('Module:Arguments').getArgs
local util = require("Module:Road data/util")
local yesno = require('Module:Yesno')
local routeModule = require("Module:Infobox road/route")
local parserModule = require("Module:Road data/parser")
local parser = parserModule.parser
local format = mw.ustring.format
local = mw.getCurrentFrame  
local function country(args)
local state = args.state or args.province
local country
local countryModule = mw.loadData("Module:Road data/countrymask")
local country = args.country or countryModule[state]  
return country
end  
local function the(args)
if country(args) == "ALA" or country(args) == "BHS" or country(args) == "CAF" or country(args) == "COG" or country(args) == "COD" or country(args) == "COM" or country(args) == "CZE" or country(args) == "DOM" or country(args) == "FSM" or country(args) == "GMB" or country(args) == "IMN" or country(args) == "MDV" or country(args) == "MHL" or country(args) == "NLD" or country(args) == "PHL" or country(args) == "SLB" or country(args) == "ARE" or country(args) == "GBR" or country(args) == "USA" then
return 'the'
else
return ''
end
end  
local function africa(args)
return "***Trans-African Highway network**"
end  
local function asia(args)
return "***Asian Highway Network**"
end  
local function europe(args)
if args.type == "Pan" then
return "***Pan-European corridors**"
else
return "***International E-road network**\n\n*A Class\n*B Class"
end
end  
local function browselinks(args)
local ISO = require('Module:ISO 3166')
local name = ISO.name({country(args)})  
if country(args) == '' or country(args) == 'YUG' or country(args) == nil then
return nil  
elseif country(args) == 'ASIA' then
return asia(args)  
elseif country(args) == 'EUR' then
return europe(args)  
elseif country(args) == 'TAH' then
return africa(args)  
elseif country(args) == 'ARE' then
return string.format("***Transport in %s %s**\n\n*Roads in Dubai", the(args), name)  
elseif country(args) == 'AUS' then
local state = args.state or ''
local stateName = ISO.name({"AUS-" .. state})
local links = "***Highways in Australia**\n\n*National Highway\n*Freeways in Australia"
if state == 'ACT' then
return links .. "\n\n**Road infrastructure in Canberra**"
elseif state == 'NSW' then
return links .. "\n\n**Highways in New South Wales**"
elseif state ~= '' then
return string.format("%s \n\n**Highways in %s**", links, stateName, stateName)
else
return links
end  
elseif country(args) == 'AUT' then
return "***Highways of Austria**\n\n*Autobahns\n*Expressways\n*State Roads"  
elseif country(args) == 'BEL' then
return "***Highways of Belgium**\n\n*Motorways\n*National Roads"  
elseif country(args) == 'BRA' then
local state = args.state or ''
local stateName = ISO.name({"BRA-" .. state})
local links = "***Highways in Brazil**"
if state == 'RS' or state == 'SP' then
return string.format("%s \n\n*%s State Highways", links, stateName, stateName)
else
return links
end  
elseif country(args) == 'BRN' then
return "***Brunei National Roads System**"  
elseif country(args) == 'CAN' then
local province = args.province or ''
local stateName = ISO.name({"CAN-" .. province})  
local TCH
if args.type == 'TCH' and province == '' then
TCH = "***Trans-Canada Highway**\n\n*National Highway System"
elseif args.type == 'TCH' and province ~= '' then
TCH = "***Trans-Canada Highway**"
else
TCH = ''
end  
local provinces
if province == '' then
provinces = ''
elseif province == 'NT' then
provinces = "**Northwest Territories highways**"
elseif province == 'YT' or province == 'YK' then
provinces = "**Territorial highways in Yukon**"
elseif province == 'NU' then
provinces = "**Highways in Nunavut**"
elseif province == 'BC' then
provinces = "**British Columbia provincial highways**"
elseif province == 'NL' then
provinces = "**Highways in Newfoundland and Labrador**"
elseif province == 'QC' then
provinces = "**Quebec provincial highways**"
elseif province == 'ON' then
if args.type == 'Fwy' or args.type == 'Hwy' or args.type == 'ON' or args.type == 'ON 1960' or args.type == 'Secondary' or args.type == 'Sec' or args.type == 'TCH' then
provinces = "**Ontario provincial highways**"
elseif args.type == 'CR' or args.type == 'DR' or args.type == 'MR' or args.type == 'RR' then
provinces = "**County roads in Ontario**"
elseif args.type == 'Parkway' then
provinces = "**Parkways of the Great Lakes**"
elseif args.type == 'Toronto' then
provinces = "**Roads in Toronto**"
else
provinces = "**Roads in Ontario**"
end
else
provinces = string.format("**Provincial highways in %s**", stateName, stateName)
end  
local second
if province == 'YT' or province == 'YK' then
second = "Miscellaneous"
elseif province == 'MB' then
second = "Winnipeg City Routes"
elseif province == 'NB' then
second = "Former routes"
elseif province == 'NS' then
second = "100-series"
elseif province == 'QC' then
second = "Autoroutes\n*List\n*Former"
elseif province == 'ON' then
if args.type == 'Fwy' or args.type == 'Hwy' or args.type == 'ON' or args.type == 'ON 1960' or args.type == 'Secondary' or args.type == 'Sec' or args.type == 'TCH' then
second = "Current\n*Former\n*400-series"
elseif args.type == 'Parkway' then
second = "Long Sault\n*Niagara\n*St. Clair\n*1000 Islands\n\n***Roads in Ontario**"
elseif args.type == 'Toronto' then
second = "North–South\n*East–West\n*Diagonal"
else
second = ''
end
else
second = ''
end  
return string.format("%s\n\n*%s\n\n*%s", TCH, provinces, second)  
elseif country(args) == 'CHE' then
return "***Transport in Switzerland**\n\n*Motorways"  
elseif country(args) == 'CHN' then
local province = args.province or ''
local stateName = ISO.name({"CHN-" .. province})
local links
if args.type == "Ex" or args.type == "Expwy" then
links = "***National Trunk Highway System**\n\n*Primary\n*Auxiliary\n\n*National Highways\n*Transport in China"
elseif args.type == "G" then
links = "***National Trunk Highway System**\n\n*Primary\n*Auxiliary"
else
links = "***Transport in China**"
end  
if province == 'BJ' or province == 'SH' or province == 'JS' or province == 'ZJ' or province == 'HA' or province == 'GD' then
return string.format("%s \n\n***Expressways of %s**", links, stateName)
else
return links
end  
elseif country(args) == 'CRI' then
return "***National Road Network of Costa Rica**"  
elseif country(args) == 'CYP' then
return "***Motorways and roads in Cyprus**"  
elseif country(args) == 'DEU' then
if args.type == "E" then
return europe(args)
else
return "***Roads in Germany**\n\n*Autobahns\n**List\n*Federal\n**List\n\n*State\n*E-roads"
end  
elseif country(args) == 'ESP' then
local province = args.province or ''
local stateName = ISO.name({"ESP-" .. province})
local links
if args.type == "E" then
links = europe(args)
else
links = "***Highways in Spain**\n\n**Autopistas* and *autovías*\n*National Roads"
end  
local community
if province ~= '' then
if province == 'B' or province == 'GI' or province == 'L' or province == 'T' then
community = "**Primary Highways in Catalonia**"
elseif province == 'GC' or province == 'TF' then
community = "**Transport in the Canary Islands**"
elseif province == 'ML' then
community = "**Transport in Melilla**"
elseif province == 'M' or province == 'MD' then
community = "**Transport in the Community of Madrid**"
else
community = ''
end
else
community = ''
end  
return string.format("%s\n\n*%s", links, community)  
elseif country(args) == 'FIN' then
if args.type == "E" then
return europe(args)
else
return "***Highways in Finland**"
end  
elseif country(args) == 'FRA' then
if args.type == "E" then
return europe(args)
else
return "***Roads in France**\n\n**Autoroutes*\n**Routes nationales*"
end  
elseif country(args) == 'GBR' or country(args) == 'ENG' or country(args) == 'SCT' or country(args) == 'WLS' then
if args.type == "Roman" then
return "***Roman roads in Britannia**"
else
return "***Roads in the United Kingdom**\n\n*Motorways\n*A and B road zones"
end  
elseif country(args) == 'GEO' then