location | warning |
---|---|
Module:labels/data/lang/xnn | subpage missing in table |
local export = {}
-- Provided with all subpages of Module:labels/data/lang, find the
-- discrepancies between them and the table returned by /lang.
function export.show(frame)
arg =
frame.args.arg and frame.args.arg .. "\n" -- slight hack: Lua patterns suck, so an extra newline needs to be tacked on
or error("Please pass a list of subpages of Module:labels/data/lang.")
local m_data = require("Module:labels/data/lang").langs_with_lang_specific_modules
local warnings, subpages = {}, {}
local n = 1
local function ins(...)
warnings = ...
n = n + 1
end
-- Iterate over what is provided, for subpages missing in the table.
for i in arg:gmatch("(+)\n") do
subpages = true
if not m_data then
local lang = require("Module:languages").getByCode(i)
local warning = "subpage missing in table" .. ((not lang and ", but language code is invalid") or "")
ins({ "Module:labels/data/lang/" .. i, warning })
end
end
-- Iterate over table to find bogus subpages. Check whether subpage is already
-- provided, first, so that a bunch of expensive DB checks aren't being done
-- for no reason.
for i, _ in pairs(m_data) do
if not subpages then
local location = "Module:labels/data/lang"
if not mw.title.new(location .. "/" .. i).exists then
ins({ location, "subpage " .. i .. " does not exist" })
else
ins({ location, "subpage " .. i .. " exists but was not passed - update arg" } )
end
end
end
if #warnings == 0 then
return "; No warnings returned."
end
local ret =
"; Number of warnings: " .. #warnings .. [[
{| class="wikitable"
! location
! warning
]]
for _, i in ipairs(warnings) do
ret = ret .. "\n|-\n| .. "]]\n|" .. i
end
return ret .. "\n|}"
end
return export