Content deleted Content added
Use CountryData.getcachedtable |
Copy from sandbox |
||
(17 intermediate revisions by 6 users not shown) | |||
Line 1:
local titleSelf = mw.title.new(... or mw.getCurrentFrame():getTitle())
if titleSelf.isSubpage then
local sandbox = titleSelf.subpageText:match[[^sandbox]]
if sandbox then
titleCountryData = titleCountryData:subPageTitle(sandbox)
end
end
local CountryData = require(tostring(titleCountryData))
local p = {}
▲local CountryData = require('Module:CountryData/sandbox')
function p.main(frame)
Line 43 ⟶ 51:
local country = args[2] or ""
local countryDataCountry = country
local titleIocCountryData = mw.title.new[[Module:Country alias/data]]
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"]
Line 52 ⟶ 67:
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 = {altvar=amap[avar].altvar;mw=amap[avar].mw;age=amap[avar].age;variant=args["variant"] or args[3]}
data = CountryData.getcachedtable(frame,
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,
avar = ""
amap = {[""]={altvar=""}}
Line 70 ⟶ 85:
local pref = args["pref"]
local suff = args["suff"] or asuf
local suff2 = args["suff2"]
if not pref and not suff then --Default prefix
pref = "Flag of"
Line 80 ⟶ 97:
local flink = args["plink"] or args["flink"] or alink
or clink=="" and "" or space2emp((pref or "").." ")..fthe..clink..space2emp(" "..(suff or ""))
local flink2
if args["plink2"] or args["flink2"] or pref2 or suff2 then
flink2 = args["plink2"] or args["flink2"] or clink=="" and "" or space2emp((pref2 or "").." ")..fthe..clink..space2emp(" "..(suff2 or ""))
else
flink2 = flink
end
local fsec = args["psection"] 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 == false then
if flink2 ~= flink and mw.title.new ( flink2 ).exists == true then
flink = clink▼
flink = flink2
fsec = fsec2
else
▲ flink = clink
end
end
end
Line 142 ⟶ 172:
am = am.."|"..am
end
--Build display name
local text = args["text"]
Line 148 ⟶ 178:
if mn=="x" then --no text
text = ""
elseif mn=="p" or mn=="f" or mn == "*" then --prefix/suffix link
text = flink=="" and name or "[["..flink..fsec.."|"..name.."]]"
-- By the principle of least surprise, there should be some
-- indication that the link [[X of Country|Country]] does not
-- go to [[Country]].
if mn == "*" and clink ~= flink then
text = text:sub(1, -3) .. "\226\128\175*]]" end
text = flink=="" and name or "[["..flink..fsec.."|"..(args["name"] or flink).."]]"
elseif mn=="b" then --both prefix/suffix and normal country link
local preflink = pref and (flink=="" and pref.." " or "[["..flink..fsec.."|"..pref.."]] ") or ""
Line 165 ⟶ 202:
elseif mn=="u" then --unlinked
text = name
text = name==country and (clink==country and country or "<abbr title='"..clink.."'>"..country.."</abbr>") or ("<abbr title='"..name.."'>"..country.."</abbr>")
else --country link (default)
text = clink=="" and name or "[["..clink..csec.."|"..name.."]]"
end
if string.find(me,"p") then
text = "("..text..")"
end
end
if type(text) == 'function' then
text = text(data)
end
--Define separator
local separator = " "
if ms=="x" then --no separator
separator = ""
separator = "<br />"
end
--Add preftext, if used
local preftext = args["preftext"]
if (preftext or "") ~= "" then
text = preftext..separator..text
end
--Build image
local ilink = args["ilink"]
Line 202 ⟶ 262:
if iname==placeholder then
if require('Module:yesno')(args["noredlink"]) == false or args["noredlink"] == "notext" then
if country ~= '' and data.alias == nil then
iname = ''▼
iname = ''
image = "[[:Template:Country data "..country.."]]" if args["noredlink"] == "notext" then
end
end
end
if (args["missingcategory"] or '') ~= '' then
Line 215 ⟶ 280:
--Combine image and name with separator
▲ local align = args["align"] or args["al"]
▲ local nalign = args["nalign"] or args["nal"]
local align_map = {left="left", l="left", center="center", centre="center", c="center", middle="center", m="center", right="right", r="right"}
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
Line 223 ⟶ 288:
if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
out = text
elseif ms=="x" or ms=="n" or ms=="l" then --no separator, non-breaking space, or line break
out = text.."<span class=\"flagicon nowrap\">"..separator..image.."</span>"
▲ elseif ms=="n" then --non-breaking space
▲ elseif ms=="l" then --line break
elseif ms=="t" then --table cell
out = "style=\"text-align:"..(
else --fixed-width span box (default)
local width = args["width"] or args["w"] or require("Module:Flaglist").luawidth(size)
out = text.."<span class=\"nowrap\"> <span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(
end
else --image left of name
if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
out = text
elseif ms=="x" or ms=="n" or ms=="l" then --no separator, non-breaking space, or line break
out = "<span class=\"flagicon\">"..image..separator.."</span>"..text
▲ elseif ms=="l" then --line break
elseif ms=="t" then --table cell
out = "style=\"text-align:"..(
else --fixed-width span box (default)
local width = nopx(args["width"] or args["w"]) or require("Module:Flaglist").luawidth(size)
out = "<span class=\"nowrap\"><span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(
end
end
▲ if string.find(me,"w") then --avoid wrapping
-- align in table
if me:find("t") then
out = 'style="text-align:'..(align or 'left')..'"|'..out
end
Line 264 ⟶ 323:
end
p[''] = p.main
return p
|