Module:Flagg: Difference between revisions

Content deleted Content added
only use sandbox versions when our sandbox versions are used
Copy from sandbox
 
(14 intermediate revisions by 5 users not shown)
Line 51:
 
local country = args[2] or ""
local countryDataCountry = country
if string.find(me, "wi") then --avoid wrapping
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 60 ⟶ 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, countrycountryDataCountry, 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, countrycountryDataCountry, {variant=args["variant"] or args[3]})
avar = ""
amap = {[""]={altvar=""}}
Line 165 ⟶ 172:
am = am.."|"..am
end
 
--Build display name
local text = args["text"]
Line 178 ⟶ 185:
if mn == "*" and clink ~= flink then
text = text:sub(1, -3) .. "\226\128\175*]]" end
elseif msmn=="l" then --linedisplay breaklink target
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 193 ⟶ 202:
elseif mn=="u" then --unlinked
text = name
elseif msmn=="la" then --line breakabbr
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 = "&nbsp;"
if ms=="x" then --no separator
separator = ""
elseif ms=="nl" then --non-breakingline spacebreak
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 230 ⟶ 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
iname text = ''
end
end
end
if (args["missingcategory"] or '') ~= '' then
Line 251 ⟶ 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
out = text.."<span class=\"flagicon\">&nbsp;"..image.."</span>"
elseif ms=="l" then --line break
out = text.."<span class=\"flagicon\"><br/>"..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\">&nbsp;<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=="n" then --non-breaking space
out = "<span class=\"flagicon\">"..image.."&nbsp;</span>"..text
elseif ms=="l" then --line break
out = "<span class=\"flagicon\">"..image.."<br/></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>&nbsp;</span>"..text
end
end
if string.find(me,"w") then --avoid wrapping
out = "<span class=\"nowrap\">"..out.."</span>"
end
Line 297 ⟶ 323:
 
end
 
p[''] = p.main
 
return p