local export = {}
--[=[
Prints out a wikitable with warnings for the following:
- All-uppercased language codes (as GEZ and TI were, before the switch to module)
- Whitespace in language codes (matches stuff like "User ojp" where there should be "ojp")
- Invalid language codes (also checks whether defined in custom_codes)
- Gender switches missing delimiter (like {masculine+feminine} instead of {masculine+feminine+})
- Messages missing proper markup: bolding, category links
]=]--
local m_data = mw.loadData("Module:Babel/data")
local get_by_code = require("Module:languages").getByCode
local sc_get_by_code = require("Module:scripts").getByCode
local char = string.char
local byte = string.byte
local sub = string.sub
local warnings = {}
local n = 1
local function ins(...)
warnings = ...
n = n + 1
end
for code, glyph in pairs(m_data.script_glyphs) do
if not sc_get_by_code(code) then
ins({ = code .. ": invalid script code", is_root = true})
end
if glyph == "A" then
ins({ = glyph .. ": redundant " .. code .. " glyph", is_root = true})
end
end
for code, _ in pairs(m_data.custom_codes) do
if get_by_code(code, false, true) then
ins({ = code .. ": redundant custom code", is_root = true})
end
local has_message = false
local subpage = mw.loadData("Module:Babel/data/" .. sub(code, 1, 1))
for _, i in ipairs{"0", "1", "2", "3", "4", "5", "N"} do
if subpage then
has_message = true
break
end
end
if not has_message then
ins({ = code .. ": custom code does not have any corresponding messages and should be removed", is_root = true})
end
end
for _, content in pairs(m_data.proglangs) do
if not content.link then
ins({ = code .. ": missing link", is_root = true})
end
end
local function get_subpage_warnings(letter)
for lang, message in pairs(mw.loadData("Module:Babel/data/" .. letter)) do
local lang_n = lang
local proficiency = lang:match("$")
lang = lang:gsub("-$", "")
local truncated = lang:gsub("-$", ""):gsub("-%u%l%l%l", "")
if not get_by_code(truncated, false, true) and not m_data.custom_codes then
if mw.language.isKnownLanguageTag(lang:lower()) then
ins({lang, lang .. ": wikimedia language code not in WT:LOL"})
else
ins({lang, lang .. ": invalid language code"})
end
end
if truncated:find("^+$") then
ins({lang, lang .. ": uppercase language code"})
end
if truncated:find("%s") then
ins({lang, lang .. ": space in language code"})
end
if message:find("{+}") and not message:find("%++%+*}") then
ins({lang, lang_n .. ": gender switch missing second delimiter"})
end
if proficiency ~= "0" and not message:find("%]+%]%]") then
ins({lang, lang_n .. ": missing $1 cat link"})
elseif proficiency == "0" and message:find("%]+%]%]") then
ins({lang, lang_n .. ": has extraneous $1 cat link"})
end
if not message:find("%]+%]%]") then
ins({lang, lang_n .. ": missing $2 cat link"})
end
if not message:find("'''") or message:find("%w%|]+%]%]%w") then
ins({lang, lang_n .. ": missing bolding"})
end
if message:find("''' ?'''") then
ins({lang, lang_n .. ": has adjacent bold tags"})
end
if message:find("$3") then
ins({lang, lang_n .. ": missing lang name"})
end
if message:lower():find(":cat")then
ins({lang, lang_n .. ": has raw category link"})
end
end
end
local letter = "a"
local warnings_hash, warnings_res = {}, {}
for i = 1, 26 do
get_subpage_warnings(letter)
letter = char(byte(letter) + 1)
end
for n, i in ipairs(warnings) do
-- remove duplicates from table
if not warnings_hash] then
warnings_res = i
warnings_hash] = true
end
end
function export.show()
local purge = '<span style="color: #0022BB;border:' ..
'1px solid #AAAAAA; background-color:' ..
'#F9F9F9; padding-left: 10px;padding-right:10px;' ..
'font-size:90%;text-weight: none; text-decoration: none;' ..
'font-style:normal;">' ..
'[[Special:ApiSandbox#action=purge&format=json&generator=prefixsearch' ..
'&formatversion=2&gpssearch=Module%3ABabel%2Fdata|Purge all data pages]]' ..
'</span>'
if not warnings then return ";Number of warnings: 0\n" .. purge end
wikitable = '{| class="wikitable"\n!subpage\n!warnings\n|-\n'
for _, i in ipairs(warnings_res) do
local subpage = "/data"
if not i.is_root then subpage = subpage .. "/" .. sub(i, 1, 1) end
wikitable = wikitable .. "|]\n|" .. i .. "\n|-\n"
end
return ";Number of warnings:" .. #warnings_res .. "\n" .. purge .. "\n" .. wikitable .. "|}"
end
return export