Module:ISO 3166 and Module:ISO 3166/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
restrict tracking to articlespace per request |
Fail faster if parameter exists but is blank |
||
Line 7: | Line 7: | ||
local p = {} |
local p = {} |
||
local getArgs = require("Module:Arguments").getArgs |
local getArgs = require("Module:Arguments").getArgs |
||
local data = mw.loadData("Module:ISO 3166/data/National") |
local data = mw.loadData("Module:ISO 3166/data/National") |
||
--[[----------F I N D N A M E----------]]-- -- Finds the name in the database |
--[[----------F I N D N A M E----------]]-- -- Finds the name in the database |
||
Line 54: | Line 54: | ||
function p.strip(text) |
function p.strip(text) |
||
if not text then return nil end |
|||
⚫ | |||
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A", -- accent list |
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A", -- accent list |
||
["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E", |
["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E", |
||
Line 70: | Line 72: | ||
} |
} |
||
text = mw.text.unstripNoWiki(text) -- Remove <nowiki> tags |
|||
text = mw.ustring.upper(text) -- Case insensitivity |
text = mw.ustring.upper(text) -- Case insensitivity |
||
text = mw.ustring.gsub(text,"[À-Ý]",accents) -- Deaccent |
text = mw.ustring.gsub(text,"[À-Ý]",accents) -- Deaccent |
||
Line 101: | Line 104: | ||
function p.luacode(args) |
function p.luacode(args) |
||
.(args[1]) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
args["codetype"]="alpha3" |
|||
⚫ | |||
local eot = args.error or "" |
local eot = args.error or "" |
||
Line 119: | Line 116: | ||
or '[[Category:Wikipedia page with obscure subdivision]]' |
or '[[Category:Wikipedia page with obscure subdivision]]' |
||
if |
if then |
||
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end |
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end |
||
return catnocountry, '<span style="font-size:100%" class="error">"No parameter for the country given"</span>' |
return catnocountry, '<span style="font-size:100%" class="error">"No parameter for the country given"</span>' |
||
end |
end |
||
if |
if then --3166-1 code |
||
for alpha2,cdata in pairs(data) do |
for alpha2,cdata in pairs(data) do |
||
if findname(alpha2,cdata, |
if findname(alpha2,cdata,) then |
||
if args["codetype"]=="numeric" or args["codetype"]=="alpha3" then |
if args["codetype"]=="numeric" or args["codetype"]=="alpha3" then |
||
return cdata[args["codetype"]] |
return cdata[args["codetype"]] |
||
Line 133: | Line 130: | ||
end |
end |
||
end |
end |
||
⚫ | |||
if string.find(args[1] or '',"%-") then |
|||
⚫ | |||
⚫ | |||
end |
end |
||
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end |
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end |
||
Line 138: | Line 139: | ||
else --3166-2 code |
else --3166-2 code |
||
for alpha2,cdata in pairs(data) do |
for alpha2,cdata in pairs(data) do |
||
if findname(alpha2,cdata, |
if findname(alpha2,cdata,) then |
||
if mw.ustring.match(alpha2,"GB") then -- For England, Wales etc. |
if mw.ustring.match(alpha2,"GB") then -- For England, Wales etc. |
||
alpha2 = "GB" |
alpha2 = "GB" |
||
Line 147: | Line 148: | ||
if type(scdata)=="table" then |
if type(scdata)=="table" then |
||
empty = false |
empty = false |
||
if findname(scode,scdata, |
if findname(scode,scdata,) then |
||
return alpha2.."-"..scode |
return alpha2.."-"..scode |
||
end |
end |
||
end |
end |
||
end |
|||
if string.find(args[2] or '',"%-") then |
|||
code1, args[2] = string.match(args[2] or '',"^([^%-]*)%-(.*)$") |
|||
args[1] = args[1].."-"..code1 |
|||
return p.luacode(args) |
|||
end |
end |
||
if mw.title.getCurrentTitle().namespace ~= 0 then catnosubdivision = '' end |
if mw.title.getCurrentTitle().namespace ~= 0 then catnosubdivision = '' end |
||
return catnosubdivision |
return catnosubdivision |
||
end |
end |
||
⚫ | |||
if string.find(args[1] or '',"%-") then |
|||
args[1] = string.match(args[1] or '',"^([^%-]*)%-(.*)$") |
|||
return p.luacode(args) |
|||
end |
end |
||
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end |
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end |