Module:Flagg: Difference between revisions

Content deleted Content added
Here too
Fix border; consistent whitespace
Line 24:
 
function emp2nil(x)
if x=="" then return nil else return x end
end
function space2emp(x)
if string.find(x,"^%s*$") then return "" else return x end
end
function nopx(x)
if x~=nil and (string.find(x,"^%d+$") or string.find(x,"^%d+px$")) then return string.gsub(x,"^(.*)px","%1") else return nil end
end
 
Line 68:
local pref = args["pref"]
local suff = args["suff"] or asuf
if not pref and not suff then --Default prefix
then pref = "Flag of"
end
local yn_map = {[""]=0; ["0"]=0; ["no"]=0; ["n"]=0; ["1"]=1; ["yes"]=1; ["y"]=1}
Line 100:
local image_map = {[""]=placeholder; ["none"]=placeholder; ["blank"]=placeholder}
if pimage then --Remove namespace
pimage = string.gsub(pimage,"^[Ff][Ii][Ll][Ee]:(.*)$","%1")
pimage = string.gsub(pimage,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1")
end
local iname = image_map[pimage] or pimage
Line 108:
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 --valid EIS size (..px, x..px or ..x..px), or unset
elseif string.find(size,"^%d*x?%d+$")
then size=size.."px" --EIS size without "px" suffix
else size = size_map[size] or nil
end
local border = frame:getParent().args["border"] or frame.args["border"]
Line 124:
if yn_map[border]==0 then border = "" else border = "|border" end
else
iflocal 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
Line 130 ⟶ 131:
local am = ""
if args["alt"] or string.find(me,"a") then
am = args["alt"] or args["name"] or country
am = am.."|"..am
end
 
Line 137 ⟶ 138:
local text = args["text"]
if not text then
if mn=="x" then --no text
then text = ""
elseif mn=="p" or mn=="f" then --prefix/suffix link
then text = "[["..flink.."|"..name.."]]"
elseif mn=="b" then --both prefix/suffix and normal country link
if pref and suff then
then text = "[["..flink.."|"..pref.."]] "..nthe.."[["..clink.."|"..name.."]] [["..flink.."|"..suff.."]]"
ifelseif pref and suffthen
then text = "[["..flink.."|"..pref.."]] "..nthe.."[["..clink.."|"..name.."]] [["..flink.."|"..suff.."]]"
then text = "[["..flink.."|"..pref.."]] "..nthe.."[["..clink.."|"..name.."]]"
elseif prefsuff then
then text = "[["..flink.."|"..pref.."]] "..nthe.."[["..clink.."|"..name.."]]"
then text = nthe.."[["..clink.."|"..name.."]] [["..flink.."|"..suff.."]]"
elseif suff
then text = nthe.."[["..clink.."|"..name.."]] [["..flink.."|"..suff.."]]"
else
text = nthe.."[["..clink.."|"..name.."]]"
end
elseif mn=="d" then --data template
then --check if redirect
if require('Module:Redirect').luaIsRedirect("Template:Country data "..country) then
then text = "<span class=\"plainlinks\">["..mw.title.new("Template:Country data "..country):fullUrl("redirect=no").." "..name.."]</span>"
else
text = "[[Template:Country data "..country.."|"..name.."]]"
end
elseif mn=="u" then --unlinked
then text = name
else --country link (default)
text = "[["..clink.."|"..name.."]]"
end
end
Line 168 ⟶ 169:
local ilink = args["ilink"]
if not ilink then
if mi=="x" or (iname==placeholder and pimage~=placeholder) then --no image/invisible image
then iname = placeholder border = "" ilink = "|link=" am = ""
elseif mi=="i" then --image page link
then ilink = ""
elseif mi=="c" then --country link
then ilink = "|link="..clink
elseif mi=="p" or mi=="f" then --prefix/suffix link
then ilink = "|link="..flink
elseif mi=="d" then --data template
then --check if redirect
if require('Module:Redirect').luaIsRedirect("Template:Country data "..country) then
then ilink = "|link="..mw.title.new("Template:Country data "..country):fullUrl("redirect=no")
else
ilink = "|link=Template:Country data "..country
end
else --unlinked (default)
ilink = "|link="
end
end
Line 193 ⟶ 195:
local align_map = {left="left", l="left", center="center", centre="center", c="center", middle="center", m="center", right="right", r="right"}
local out
if string.find(me,"r") then
then --image right of name
if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
then out = text
elseif ms=="x" then --no separator
then out = text.."<span class=\"flagicon\">"..image.."</span>"
elseif ms=="n" then --non-breaking space
then out = text.."<span class=\"flagicon\">&nbsp;"..image.."</span>"
elseif ms=="l" then --line break
then out = text.."<span class=\"flagicon\"><br/>"..image.."</span>"
elseif ms=="t" then --table cell
then out = "style=\"text-align:"..(align_map[nalign] or "left").."\"|"..text.."||style=\"text-align:"..(align_map[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/size").luawidth(size)
out = text.."<span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(align_map[align] or "right")..";\">"..image.."</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
then out = text
elseif ms=="x" then --no separator
then out = "<span class=\"flagicon\">"..image.."</span>"..text
elseif ms=="n" then --non-breaking space
then out = "<span class=\"flagicon\">"..image.."&nbsp;</span>"..text
elseif ms=="l" then --line break
then out = "<span class=\"flagicon\">"..image.."<br/></span>"..text
elseif ms=="t" then --table cell
then out = "style=\"text-align:"..(align_map[align] or "center")..";\"|<span class=\"flagicon\">"..image.."</span>||style=\"text-align:"..(align_map[nalign] or "left").."\"|"..text
else --fixed-width span box (default)
local width = nopx(args["width"] or args["w"]) or require("Module:Flaglist/size").luawidth(size)
out = "<span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(align_map[align] or "left")..";\">"..image.."</span>"..text
end
end
if string.find(me,"w") then --avoid wrapping
then out = "<span class=\"nowrap\">"..out.."</span>"
end
 
--Tracking categories
local cat = ""
if pimage and not image_map[pimage] and country~="" and data["flag alias"] and not args.demo then
then cat = "[[Category:Pages using Flagg with specified image instead of data template image]]"
end