Content deleted Content added
sync from main, support category for missing countrydata |
Merge? |
||
(42 intermediate revisions by 11 users not shown) | |||
Line 1:
local titleSelf = mw.title.new(... or mw.getCurrentFrame():getTitle())
local titleCountryData = mw.title.new[[Module:CountryData]]
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 = {}
function p.main(frame)
--Get input arguments
local args = require('Module:Arguments').getArgs(frame,{valueFunc =
})
--Call main function
return p.luaMain(frame,args)
end
function p.luaMain(frame,args)
local function emp2nil(x)
end
local function space2emp(x)
end
local function nopx(x)
end
Line 42 ⟶ 51:
local country = args[2] or ""
local countryDataCountry = country
if string.find(me, "i") then
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 48 ⟶ 64:
local data, alink, amap, asuf
if avar then
else
end
Line 69 ⟶ 85:
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
end
local yn_map = {[""]=0; ["0"]=0; ["no"]=0; ["n"]=0; ["1"]=1; ["yes"]=1; ["y"]=1}
Line 78 ⟶ 96:
nthe = nthe and (pref and "t" or "T").."he " or ""
local flink = args["plink"] or args["flink"] or alink
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 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 == false then
if flink2 ~= flink and mw.title.new ( flink2 ).exists == true then
flink = flink2
fsec = fsec2
else
flink = clink
end
end
end
local name = args["name"]
if not name then
name = cname=="" and "" or space2emp((pref or "").." ")..nthe..cname..space2emp(" "..(suff or ""))
name = cname
end
Line 100 ⟶ 137:
local image_map = {[""]=placeholder; ["none"]=placeholder; ["blank"]=placeholder}
if pimage then --Remove namespace
end
local iname = image_map[pimage] or pimage
Line 108 ⟶ 145:
local size_map = {xs="12x8px"; s="17x11px"; m="23x15px"; l="32x21px"; xl="46x30px"}
if size==nil or string.find(size,"^%d*x?%d+px$") then
elseif string.find(size,"^%d*x?%d+$") then --EIS size without "px" suffix
else --size from map, or invalid value
end
local border = args["border"]
if iname then
if yn_map[border]==0 then border = "" else border = "|border" end
size = size or emp2nil(data.size) or "23x15px"
if border then
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
end
--Build display name
local text = args["text"]
if not text then
text = ""
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 = 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 ""
local sufflink = suff and (flink=="" and " "..suff or " [["..flink..fsec.."|"..suff.."]]") or ""
local namelink
text = preflink..namelink..sufflink
elseif mn=="d" then --data template
local title = mw.title.new("Template:Country data "..country)
--check if redirect
if title.isRedirect then
text = "<span class=\"plainlinks\">["..title:fullUrl("redirect=no").." "..name.."]</span>"
else
text = "[["..title.fullText.."|"..name.."]]"
end
elseif mn=="u" then --unlinked
text = name
elseif mn=="a" then --abbr
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 = ""
elseif ms=="l" then --line break
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"]
if not ilink then
iname = placeholder
border = ""
ilink = "|link="
am = ""
ilink = ""
ilink = "|link="..clink..(clink=="" and "" or csec)
ilink = "|link="..flink..(flink=="" and "" or fsec)
local title = mw.title.new("Template:Country data "..country)
--check if redirect
if title.isRedirect then
ilink = "|link="..title:fullUrl("redirect=no")
else
ilink = "|link="..title.fullText
end
else --unlinked (default)
ilink = "|link="
end
end
if am == "" and string.find(me,"l") then
am = mw.ustring.sub(ilink,7,-1)
end
local image = "[[File:"..iname.."|"..size..border..ilink.."|alt="..am.."]]"
if iname==placeholder then
if require('Module:yesno')(args["noredlink"]) == false or args["noredlink"] == "notext" then
if country ~= '' and data.alias == nil then
iname = ''
image = "[[:Template:Country data "..country.."]]"
if args["noredlink"] == "notext" then
text = ''
end
end
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 = {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
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=="t" then --table cell
out = "style=\"text-align:"..(nalign or "left").."\"|"..text.."||style=\"text-align:"..(align or "center").."\"|<span class=\"flagicon\">"..image.."</span>"
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:"..(align or "right").."\">"..image.."</span></span>"
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=="t" then --table cell
out = "style=\"text-align:"..(align or "center")..";\"|<span class=\"flagicon\">"..image.."</span>||style=\"text-align:"..(nalign or "left").."\"|"..text
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:"..(align or "left").."\">"..image.."</span> </span>"..text
end
end
-- align in table
if me:find("t") then
out = 'style="text-align:'..(align or 'left')..'"|'..out
end
Line 242 ⟶ 317:
local cat = ""
if pimage and not image_map[pimage] and country~="" and data["flag alias"] and not args.demo then
end
Line 248 ⟶ 323:
end
p[''] = p.main
return p
|