Jump to content

Module:Protection banner: Difference between revisions

expand category matching code - still buggy
(add namespace parser)
(expand category matching code - still buggy)
Line 114: Line 114:
if not nskey and ns % 2 == 1 then
if not nskey and ns % 2 == 1 then
nskey = 'talk'
nskey = 'talk'
else
elseif not nskey then
nskey = 'all'
nskey = 'all'
end
end
Line 120: Line 120:
end
end


function p.matchCategory(cats, protType, protLevel, namespace, expiry, reason)
function p.matchCategory(cats, protType, protLevel, namespace, reason, expiry)
local nskey = p.parseNamespace(namespace)
-- Preprocess parameters
cats = cats or categories
protType = protType or 'all'
protLevel = protLevel or 'all'
namespace = p.parseNamespace(namespace)
reason = reason or 'all'
if not expiry then
expiry = 'all'
elseif expiry ~= 'indef' then
expiry = 'temp'
end
-- Define the key table and the order to test it in
local keyTable = {protType, protLevel, namespace, reason, expiry}
local tryOrder = {5, 4, 3, 2, 1}
-- Try successively generic matches until we run out of key combinations
local function attemptMatch()
local key = table.concat(keyTable, '-')
mw.log(key) -- for debugging
return cats[key]
end
local attempt = attemptMatch()
if attempt then
return attempt
end
for i, keyTableKey in ipairs(tryOrder) do
keyTable[keyTableKey] = 'all'
attempt = attemptMatch()
if attempt then
return attempt
end
end
error('No category match found; please define the category for key "all-all-all-all-all"')
end
end


return p
return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.