Module:Protection banner: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(fix "Wikipedia protected categories" key)
(try a different category matching algorithm completely)
Line 136: Line 136:
-- Define the key table and the order to test it in
-- Define the key table and the order to test it in
local keyTable = {protType, protLevel, namespace, reason, expiry}
local keyTable = {protType, protLevel, namespace, reason, expiry}
local tryOrder
local attemptOrder = {
{true, true, true, true, true},
if reason == 'vandalism' then
tryOrder = {5, 4, 3, 2, 1}
{true, true, true, true, false},
{true, true, true, false, true},
else
tryOrder = {5, 3, 4, 2, 1}
{true, true, false, true, true},
{true, true, true, false, false},
end
{true, true, false, true, false},
{true, true, false, false, true},
{true, true, false, false, false},
{true, false, false, false, false},
{false, false, false, false, false}
}
-- Try successively generic matches until we run out of key combinations
-- Try successively generic matches until we run out of key combinations
for i, t in ipairs(attemptOrder) do
local function attemptMatch()
local key = table.concat(keyTable, '-')
local key = {}
for j = 1, 5 do
return cats[key]
if t[j] then
end
key[j] = keyTable[j]
local attempt = attemptMatch()
else
if attempt then
key[j] = 'all'
return attempt
end
end
end
for i, keyTableKey in ipairs(tryOrder) do
key = table.concat(key, '-')
keyTable[keyTableKey] = 'all'
attempt = attemptMatch()
local attempt = cats[key]
if attempt then
if attempt then
return attempt
return attempt