local titleSelf = mw.title.new(... or mw.getCurrentFrame:getTitle)local titleCountryData = mw.title.newif titleSelf.isSubpage then local sandbox = titleSelf.subpageText:match^sandbox if sandbox then titleCountryData = titleCountryData:subPageTitle(sandbox) endendlocal CountryData = require(tostring(titleCountryData))local p =
function p.main(frame)
--Get input arguments local args = require('Module:Arguments').getArgs(frame,)
--Call main function return p.luaMain(frame,args)
end
function p.luaMain(frame,args)
local function emp2nil(x) if x
--Country & mode parameters local mode = string.lower(args[1] or "usc") local mi = string.sub(mode,1,1) local ms = string.sub(mode,2,2) local mn = string.sub(mode,3,3) local me = string.sub(mode,4,-1)
local country = args[2] or "" local countryDataCountry = country if string.find(me, "i") then local titleIocCountryData = mw.title.new local IocCountryData = require(tostring(titleIocCountryData)) local iocCountryAlias = IocCountryData.countryAliases[country] or country countryDataCountry = IocCountryData.countries[iocCountryAlias]["countrydata_name"] or IocCountryData.countries[iocCountryAlias]["name"] end local avar = args["avar"] or args["altvar"] local clink = args["clink"] or args["link"]
--Get country data & altvar data local data, alink, amap, asuf if avar then local age = args["age"] or "" local aalias amap, aalias = require("Module:Flagg/Altvar data").alttable(age) avar = string.gsub(string.lower(avar or ""),"[-]","") avar = aalias[avar] or avar if not amap[avar] then error("Unknown avar") end local apar = data = CountryData.getcachedtable(frame, countryDataCountry, apar) asuf = amap[avar].altlink alink = data["link alias-"..amap[avar].altvar] or (clink or data["shortname alias"] or data.alias or country).." "..asuf else data = (args["nodata"] and) or CountryData.getcachedtable(frame, countryDataCountry,) avar = "" amap = end
--Name and link parameters clink = clink or data.alias or country
local pref = args["pref"] local suff = args["suff"] or asuf local pref2 = args["pref2"] local suff2 = args["suff2"] if not pref and not suff then --Default prefix pref = "Flag of" end local yn_map = local fthe = (args["pthe"] and yn_map[args["pthe"]]~=0) or (args["the"] and yn_map[args["the"]]~=0) local nthe = (args["nthe"] and yn_map[args["nthe"]]~=0) or (args["the"] and yn_map[args["the"]]~=0) fthe = fthe and (pref and "t" or "T").."he " or "" nthe = nthe and (pref and "t" or "T").."he " or "" local flink = args["plink"] or args["flink"] or alink or clink
"" and "" or space2emp((pref2 or "").." ")..fthe..clink..space2emp(" "..(suff2 or "")) else flink2 = flink end local fsec = args["psection"] or args["section"] local fsec2 = args["psection2"] or args["section"] local csec = args["csection"] or args["section"] fsec = fsec and "#"..fsec or "" fsec2 = fsec2 and "#"..fsec2 or "" csec = csec and "#"..csec or ""
if string.find(me,"f") then if mw.title.new(flink).exists
true then flink = flink2 fsec = fsec2 else flink = clink end end end
local name = args["name"] if not name then local cname = string.find(me,"e") and (data["name alias-"..amap[avar].altvar] or data["shortname alias"] or data.alias) or country if mn
"" and "" or space2emp((pref or "").." ")..nthe..cname..space2emp(" "..(suff or "")) else name = cname end end
--Image parameters local pimage = args["image"] local placeholder = "Flag placeholder.svg" local variant = args["variant"] or args[3] or "" local image_map = if pimage then --Remove namespace pimage = string.gsub(pimage,"^[Ff][Ii][Ll][Ee]:","") pimage = string.gsub(pimage,"^[Ii][Mm][Aa][Gg][Ee]:","") end local iname = image_map[pimage] or pimage
local size = args["size"] or args["sz"] local size_map = if size
if iname then size = size or "23x15px" if yn_map[border]
0 then border = "" else border = "|border" end else local autoborder = data["border-"..variant] or data["border-"..amap[avar].altvar] or data.border if autoborder and autoborder~="border" then border = "" else border = "|border" end end end
local am = "" if args["alt"] or string.find(me,"a") then am = args["alt"] or args["name"] or country am = am.."|"..am end --Build display name local text = args["text"] if not text then if mn
"p" or mn
"*" then --prefix/suffix link text = flink
"*" and clink ~= flink then text = text:sub(1, -3) .. "\226\128\175*]]" end elseif mn
"" and pref.." " or ""..pref.." ") or "" local sufflink = suff and (flink
"" and "" or nthe)..(clink
"d" then --data template local title = mw.title.new("Template:Country data "..country) --check if redirect if title.isRedirect then text = "
["..title:fullUrl("redirect=no").." "..name.."]" else text = ""..name.."" end elseif mn"a" then --abbr text = clink
"" and name or ""..name.."" end if string.find(me,"p") then text = "("..text..")" end end if type(text)
--Define separator local separator = " " --non-breaking space (n) if ms
"l" then --line break separator = "
" end --Add preftext, if used local preftext = args["preftext"] if (preftext or "") ~= "" then text = preftext..separator..text end --Build image local ilink = args["ilink"] if not ilink then if mi
placeholder and pimage~=placeholder) then --no image/invisible image iname = placeholder border = "" ilink = "|link=" am = "" elseif mi
"c" then --country link ilink = "|link="..clink..(clink
"p" or mi
"" and "" or fsec) elseif mi
"" and string.find(me,"l") then am = mw.ustring.sub(ilink,7,-1) end local image = ""
if iname
false then iname = image = "" end if (args["missingcategory"] or ) ~= then image = image..args["missingcategory"] end if string.find(me,"b") then text = end end
--Combine image and name with separator local align_map = local align = align_map[args["align"] or args["al"]] local nalign = align_map[args["nalign"] or args["nal"]] local out if string.find(me,"r") then --image right of name if (ms
"x") or (string.find(me,"o") and iname
"x" or ms
"l" then --no separator, non-breaking space, or line break out = text.."
"..separator..image.."" elseif ms"x") or (string.find(me,"o") and iname
"x" or ms
"l" then --no separator, non-breaking space, or line break out = "
"..image..separator..""..text elseif ms--Tracking categories local cat = "" if pimage and not image_map[pimage] and country~="" and data["flag alias"] and not args.demo then cat = "" end
return out..cat
end
return p