Changes

Jump to navigation Jump to search

Module:Protection banner

919 bytes added, 01:51, 4 March 2014
expand category matching code - still buggy
if not nskey and ns % 2 == 1 then
nskey = 'talk'
elseelseif not nskey then
nskey = 'all'
end
end
function p.matchCategory(cats, protType, protLevel, namespace, reason, expiry, reason) local nskey -- 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
return p
Anonymous user

Navigation menu