Jump to content

Module:Protection banner: Difference between revisions

expand category matching code - still buggy
Enwikipedia>Mr. Stradivarius
(add namespace parser)
Enwikipedia>Mr. Stradivarius
(expand category matching code - still buggy)
Line 114:
if not nskey and ns % 2 == 1 then
nskey = 'talk'
elseif not nskey then
else
nskey = 'all'
end
Line 120:
end
 
function p.matchCategory(cats, protType, protLevel, namespace, expiryreason, reasonexpiry)
-- Preprocess parameters
local nskey = p.parseNamespace(namespace)
cats = cats or categories
protType = protType or 'all'
protLevel = protLevel or 'all'
local nskeynamespace = 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
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.