Anonymous user
Module:ISO 3166: Difference between revisions
add coordinsert wrapper and simplify tracking category code
(Undid revision 859416358 by BrandonXLF (talk) seems to have caused errors in articles, for example, Luonan Subdistrict) |
(add coordinsert wrapper and simplify tracking category code) |
||
Line 105:
local eot = args.error or ""
local
local catnosubdivision = (args.nocat and args.nocat == 'true') and ''
if not args[1] then
Line 121 ⟶ 124:
end
end
return catnocountry
▲ return nocat and '' or '[[Category:Wikipedia page with obscure country]]'
else --3166-2 code
for alpha2,cdata in pairs(data) do
Line 139 ⟶ 142:
end
if empty then
return catnosubdivision
▲ return nocat and '' or '[[Category:Wikipedia page with obscure subdivision]]'
else
return catnosubdivision
return nocat and '' or '[[Category:Wikipedia page with obscure subdivision]]'▼
end
end
end
return catnocountry
return nocat and '' or '[[Category:Wikipedia page with obscure country]]'▼
end
--[[----------P . C O D E---------]]-- -- Calls P.Luacode but using Module:Arguments
Line 207 ⟶ 210:
end
end
--[[----------P.GEOCOORDINSERT---------]]-- -- Wrapper for Module:Coordinates.coordinsert
function p.geocoordinsert(frame)
-- {{#invoke:ISO 3166|geocoordinsert|{{coord|...}}
-- |country=..|subdivision1=...|subdivision2=...
-- |type=...|scale=...|dim=...|source=...|globe=...
-- }}
local args = frame.args
local subdivisionqueried = false
local catnocountry = (args.nocat and args.nocat == 'true') and ''
local catnosubdivision = (args.nocat and args.nocat == 'true') and ''
local tracking = ''
local targs = {}
targs[1] = args[1] or ''
for i, v in pairs(args) do
if i == 'country' and not mw.ustring.find(targs[1], 'region:') then
local country = v
local k, region = 1, ''
-- look for a valid subdivision
while region == '' and k < 3 do
local subdivision = args['subdivision' .. k] or ''
if subdivision ~= '' then
region = p.luacode({country, subdivision, nocat = 'true'})
subdivisionqueried = true
end
k = k + 1
end
-- subdivision lookup failed or never attempted, try country only
if region == '' then
region = p.luacode({country, nocat = 'true'})
if region == '' then
tracking = tracking .. catnocountry
elseif subdivisionqueried == true then
tracking = tracking .. catnosubdivision
end
end
-- something worked, add it to the targs
if region ~= '' then
targs[#targs + 1] = 'region:' .. region
end
elseif i == 'type' or i == 'scale' or i == 'dim'
or i == 'source' or i == 'globe' then
targs[#targs + 1] = i .. ':' .. v
end
end
-- call Module:Coordinates.coordinsert if there is something to insert
if #targs > 1 then
local coordinsert = require('Module:Coordinates').coordinsert
return coordinsert({args = targs}) .. tracking
end
-- otherwise, just return the coordinates
return targs[1] .. tracking
end
--[[----------P . N A M E---------]]-- -- Calls P.Luaname but using Module:Arguments
|