Module:Protection banner: Difference between revisions
Content deleted Content added
add namespace parser |
expand category matching code - still buggy |
||
Line 114:
if not nskey and ns % 2 == 1 then
nskey = 'talk'
elseif not nskey then
nskey = 'all'
end
Line 120:
end
function p.matchCategory(cats, protType, protLevel, namespace,
-- Preprocess parameters
local nskey = p.parseNamespace(namespace)▼
cats = cats or categories
protType = protType or 'all'
protLevel = protLevel or 'all'
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
|