Content deleted Content added
Refactored; made output more structured |
Make luacodeimpl() a subfunction (past or present tense summaries??) |
||
Line 105:
-- Returns tuple (code,errorcat,errortext). code is empty string upon error because MW stops at first nil
function p.luacode(args)
local function luacodeimpl(args)
local country, subdivision = args[1], args[2]
if args["codetype"]=="3" then
args["codetype"]="alpha3"
end
local catnocountry = (args.nocat and args.nocat == 'true') and ''
or '[[Category:Wikipedia page with obscure country]]'
local catnosubdivision = (args.nocat and args.nocat == 'true') and ''
or '[[Category:Wikipedia page with obscure subdivision]]'
if not country then
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return '',catnocountry,'<span class="error">ISO 3166: name not specified</span>'
end
if not subdivision then --3166-1 code
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,country) then
if args["codetype"]=="numeric" or args["codetype"]=="alpha3" then
return cdata[args["codetype"]]
else
return alpha2
end
end
end
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return '',catnocountry
else --3166-2 code
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,country) then
if alpha2:sub(1,2) == "GB" then --Treat all UK countries as the UK
alpha2 = "GB"
end
local sdata = mw.loadData("Module:ISO 3166/data/"..alpha2)
local empty = true
for scode,scdata in pairs(sdata) do
if type(scdata) == "table" then
empty = false
if findname(scode,scdata,subdivision) then
return alpha2.."-"..scode
end
end
end
if mw.title.getCurrentTitle().namespace ~= 0 then catnosubdivision = '' end
return '',catnosubdivision
end
end
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return '',catnocountry
end
end
if args[1] then args[1] = p.strip(args[1]) end
Line 125 ⟶ 180:
args[1],args[2] = a1,a2 --Try again without splitting
return luacodeimpl(args)
end
|