Difference between revisions of "Module:Infobox road/locations"

From blackwiki
Jump to navigation Jump to search
test>Fredddie
(add PHL by request)
m (20 revisions imported)
 
(11 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
local function countries(args, country)
 
local function countries(args, country)
     local data = {EUR = "no", ASIA = "no", default = "yes"}
+
     local data = {AFRICA = "no", ARAB = "no", ASIA = "no", EUR = "no", default = "yes"}
 
     local yesOrNo = data[country] or data.default
 
     local yesOrNo = data[country] or data.default
 
     if yesOrNo == "no" then
 
     if yesOrNo == "no" then
Line 12: Line 12:
  
 
local function regions(args, country)
 
local function regions(args, country)
local data = {EUR = "no", ESP = "no", ITA = "no", HRV = "no", CZE = "no", CAN = "no", CYP = "no", GRC = "no", POL = "no", HUN = "no",
+
local data = {EUR = "no", AUS = "no", AUT = "no", BIH = "no", CAN = "no", CYP = "no", CZE = "no", ESP = "no", GRC = "no", HRV = "no",
              SVN = "no", SVK = "no", AUT = "no", TUR = "no", UKR = "no", BIH = "no", SRB = "no", SGP = "no", AUS = "no", default = "yes"}
+
              HUN = "no", ITA = "no", POL = "no", SGP = "no", SRB = "no", SVK = "no", SVN = "no", TUR = "no", UKR = "no", default = "yes"}
 
if args.communities then
 
if args.communities then
return "Autonomous communities:", args.communities
+
return "Autonomous<br>communities", args.communities
 
end
 
end
 
local yesOrNo = data[country] or data.default
 
local yesOrNo = data[country] or data.default
 
if yesOrNo == "no" then
 
if yesOrNo == "no" then
return "Regions:", args.regions
+
return "Regions", args.regions
 
else
 
else
return "Regions:", nil
+
return "Regions", nil
 
end
 
end
 
end
 
end
  
 
local function states(args, country)
 
local function states(args, country)
     local data = {USA = "no", IND = "no", DEU = "no", AUT = "no", MEX = "no", AUS = "no", BRA = "no", default = "yes"}
+
     local data = {AUS = "no", AUT = "no", BRA = "no", DEU = "no", IND = "no", MEX = "no", MYS = "no", USA = "no", default = "yes"}
 
     local yesOrNo = data[country] or data.default
 
     local yesOrNo = data[country] or data.default
 
     if yesOrNo == "no" then
 
     if yesOrNo == "no" then
Line 36: Line 36:
  
 
local function provinces(args, country)
 
local function provinces(args, country)
     local data = {TUR = "no", THA = "no", IRN = "no", NLD = "no", ESP = "no", PHL = "no", default = "yes"}
+
     local data = {CAN = "no", CRI = "no", ESP = "no", IRN = "no", NLD = "no", PHL = "no", SAU = "no", THA = "no", TUR = "no", default = "yes"}
 
     local yesOrNo = data[country] or data.default
 
     local yesOrNo = data[country] or data.default
 
     if yesOrNo == "no" then
 
     if yesOrNo == "no" then
Line 52: Line 52:
 
     local boroughs = args.boroughs
 
     local boroughs = args.boroughs
 
     if counties then
 
     if counties then
         return "Counties:", counties
+
         return "Counties", counties
 
     elseif districts then
 
     elseif districts then
         return "Districts:", districts
+
         return "Districts", districts
 
     elseif municipalities then
 
     elseif municipalities then
         return "Municipalities:", municipalities
+
         return "Municipalities", municipalities
 
     elseif parishes then
 
     elseif parishes then
         return "Parishes:", parishes
+
         return "Parishes", parishes
 
     elseif boroughs then
 
     elseif boroughs then
         return "Boroughs:", boroughs
+
         return "Boroughs", boroughs
 
     else
 
     else
 
         return '', nil
 
         return '', nil
Line 70: Line 70:
 
     local province = country or ''
 
     local province = country or ''
 
     if province == "AB" then
 
     if province == "AB" then
         label = "Specialized<br>and rural<br>municipalities:"
+
         label = "Specialized<br>and rural<br>municipalities"
 
     else
 
     else
         label = "Rural<br>municipalities:"
+
         label = "Rural<br>municipalities"
 
     end
 
     end
     local data = {MB = "no", SK = "no", AB = "no", default = "yes"}
+
     local data = {AB = "no", MB = "no", SK = "no", default = "yes"}
 
     local yesOrNo = data[province] or data.default
 
     local yesOrNo = data[province] or data.default
 
     if yesOrNo == "no" then
 
     if yesOrNo == "no" then
Line 107: Line 107:
 
     local label
 
     local label
 
     if country == "GBR" then
 
     if country == "GBR" then
         label = "[[Primary status|Primary<br>destinations]]:"
+
         label = "[[Primary status|Primary<br>destinations]]"
 
     else
 
     else
         label = "Primary<br>destinations:"
+
         label = "Primary<br>destinations"
 
     end
 
     end
     local data = {AUS = "no", NZL = "no", GBR = "no", IRL = "no", MYS = "no", IND = "no", NPL = "no", default = "yes"}
+
     local data = {AUS = "no", GBR = "no", IMN = "no", IND = "no", IRL = "no", MYS = "no", NIR = "no", NPL = "no", NZL = "no", default = "yes"}
 
     local yesOrNo = data[country] or data.default
 
     local yesOrNo = data[country] or data.default
 
     if yesOrNo == "no" then
 
     if yesOrNo == "no" then
Line 136: Line 136:
  
 
local function locations(args, country)
 
local function locations(args, country)
     local labels = {highway = "Major settlements:", ["rural road"] = "Major settlements:", freeway = "Major suburbs:", ["city highway"] = "Major suburbs:", road = "Major suburbs:", street = "Suburb:"}
+
     local labels = {highway = "Major settlements", ["rural road"] = "Major settlements", freeway = "Major suburbs", ["city highway"] = "Major suburbs", road = "Major suburbs", street = "Suburb"}
 
     local data = {AUS = "no", default = "yes"}
 
     local data = {AUS = "no", default = "yes"}
 
     local yesOrNo = data[country] or data.default
 
     local yesOrNo = data[country] or data.default
 
     if yesOrNo == "no" then
 
     if yesOrNo == "no" then
 
         local type = args.type or ''
 
         local type = args.type or ''
         local label = labels[type] or "Primary<br>destinations:"
+
         local label = labels[type] or "Primary<br>destinations"
 
         return label, args.locations
 
         return label, args.locations
 
     else
 
     else
Line 153: Line 153:
 
     local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
 
     local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
 
      
 
      
     local parameters = {label1 = "Countries:", label3 = "States:", label4 = "Provinces:", label7 = "Divisions:", label8 = "Major cities:",
+
     local parameters = {label1 = "Countries", label3 = "States", label4 = "Provinces", label7 = "Divisions", label8 = "Major cities",
                         label9 = "Towns:", label10 = "Villages:", child = "yes", decat = "yes", labelstyle = "text-align:right", title = "Location"}
+
                         label9 = "Towns", label10 = "Villages", child = "yes", decat = "yes", labelstyle = "text-align:right", title = "Location"}
 
     local data = {}
 
     local data = {}
 
      
 
      

Latest revision as of 12:54, 19 September 2020

Documentation for this module may be created at Module:Infobox road/locations/doc

local p = {}

local function countries(args, country)
    local data = {AFRICA = "no", ARAB = "no", ASIA = "no", EUR = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args.countries
    else
        return nil
    end
end

local function regions(args, country)
	local data = {EUR = "no", AUS = "no", AUT = "no", BIH = "no", CAN = "no", CYP = "no", CZE = "no", ESP = "no", GRC = "no", HRV = "no",
	              HUN = "no", ITA = "no", POL = "no", SGP = "no", SRB = "no", SVK = "no", SVN = "no", TUR = "no", UKR = "no", default = "yes"}
	if args.communities then
		return "Autonomous<br>communities", args.communities
	end
	local yesOrNo = data[country] or data.default
	if yesOrNo == "no" then
		return "Regions", args.regions
	else
		return "Regions", nil
	end
end

local function states(args, country)
    local data = {AUS = "no", AUT = "no", BRA = "no", DEU = "no", IND = "no", MEX = "no", MYS = "no", USA = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args.states
    else
        return nil
    end
end

local function provinces(args, country)
    local data = {CAN = "no", CRI = "no", ESP = "no", IRN = "no", NLD = "no", PHL = "no", SAU = "no", THA = "no", TUR = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args.provinces
    else
        return nil
    end
end

local function counties(args, country)
    local counties = args.counties
    local districts = args.districts
    local municipalities = args.municipalities
    local parishes = args.parishes
    local boroughs = args.boroughs
    if counties then
        return "Counties", counties
    elseif districts then
        return "Districts", districts
    elseif municipalities then
        return "Municipalities", municipalities
    elseif parishes then
        return "Parishes", parishes
    elseif boroughs then
        return "Boroughs", boroughs
    else
        return '', nil
    end
end

local function ruralMunis(args, country)
    local label
    local province = country or ''
    if province == "AB" then
        label = "Specialized<br>and rural<br>municipalities"
    else
        label = "Rural<br>municipalities"
    end
    local data = {AB = "no", MB = "no", SK = "no", default = "yes"}
    local yesOrNo = data[province] or data.default
    if yesOrNo == "no" then
        return label, args.rural_municipalities
    else
        return '', nil
    end
end

local function divisions(args, country)
    local province = country or ''
    local data = {ON = "no", default = "yes"}
    local yesOrNo = data[province] or data.default
    if yesOrNo == "no" then
        return args.divisions
    else
        return nil
    end
end

local function cities(args, country, parameter)
    local data = {USA = "yes", default = "no"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args[parameter]
    else
        return nil
    end
end

local function destinations(args, country)
    local label
    if country == "GBR" then
        label = "[[Primary status|Primary<br>destinations]]"
    else
        label = "Primary<br>destinations"
    end
    local data = {AUS = "no", GBR = "no", IMN = "no", IND = "no", IRL = "no", MYS = "no", NIR = "no", NPL = "no", NZL = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return label, args.destinations
    else
        return '', nil
    end
end

local function lga(args, country)
    local labels = {SA = "[[Local government areas of South Australia|LGA(s)]]", VIC = "[[Local government in Victoria|LGA(s)]]", NSW = "[[Local government areas of New South Wales|LGA(s)]]",
                    QLD = "[[Local government areas of Queensland|LGA(s)]]", NT = "[[Local government areas of the Northern Territory|LGA(s)]]",
                    WA = "[[Local government areas of Western Australia|LGA(s)]]", TAS = "[[Local government areas of Tasmania|LGA(s)]]", ACT = "District(s)"}
    local data = {AUS = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        local state = args.state or ''
        local label = labels[state] or "[[Local government in Australia|LGA(s)]]"
        return label, args.lga
    else
        return '', nil
    end
end

local function locations(args, country)
    local labels = {highway = "Major settlements", ["rural road"] = "Major settlements", freeway = "Major suburbs", ["city highway"] = "Major suburbs", road = "Major suburbs", street = "Suburb"}
    local data = {AUS = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        local type = args.type or ''
        local label = labels[type] or "Primary<br>destinations"
        return label, args.locations
    else
        return '', nil
    end
end

function p.locations(frame)
    local pframe = frame:getParent()
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
    
    local parameters = {label1 = "Countries", label3 = "States", label4 = "Provinces", label7 = "Divisions", label8 = "Major cities",
                        label9 = "Towns", label10 = "Villages", child = "yes", decat = "yes", labelstyle = "text-align:right", title = "Location"}
    local data = {}
    
    local function emptyParam(param)
        if param == '' then
            return nil
        else
            return param
        end
    end

    local country = emptyParam(args.country)
    local state = emptyParam(args.state)
    local province = emptyParam(args.province)
    if not(country) then
        local stateParam = args.state or args.province
        if not(stateParam) then
            country = ''
        else
            local countryMask = require "Module:Infobox road/meta/mask/country"
            country = countryMask._country(stateParam, country)
        end
    end
    data[1] = countries(args, country)
    parameters.label2, data[2] = regions(args, country)
    data[3] = states(args, country)
    data[4] = provinces(args, country)
    parameters.label5, data[5] = counties(args, country)
    parameters.label6, data[6] = ruralMunis(args, province)
    data[7] = divisions(args, province)
    data[8] = cities(args, country, 'cities')
    data[9] = cities(args, country, 'towns')
    data[10] = cities(args, country, 'villages')
    parameters.label11, data[11] = destinations(args, country)
    parameters.label12, data[12] = lga(args, country)
    parameters.label13, data[13] = locations(args, country)
    
    local hasData = false
    for k,v in pairs(data) do
        if v ~= '' then
            hasData = true
            break
        end
    end
    if not(hasData) then
        return ''
    end
    
    for k,v in pairs(data) do
        parameters["data" .. k] = v
    end
    
    local infoboxModule = require 'Module:Infobox'
    return infoboxModule.infobox(parameters)
end

return p