Module:Protection banner: Difference between revisions
Content added Content deleted
Enwikipedia>Mr. Stradivarius (change this to something that should work if I can get the order figured out) |
Enwikipedia>Mr. Stradivarius (key components are in the correct order now - property order still a long way off, though) |
||
Line 84: | Line 84: | ||
local tconcat = table.concat |
local tconcat = table.concat |
||
local tinsert = table.insert |
local tinsert = table.insert |
||
local tremove = table.remove |
|||
local floor = math.floor |
local floor = math.floor |
||
local function toTableEnd(t, pos) |
|||
-- Sends the item at position pos to the end of array t, |
|||
-- and shifts all the other array items down accordingly. |
|||
tinsert(t, tremove(t, pos)) |
|||
⚫ | |||
local p = {} |
local p = {} |
||
Line 92: | Line 99: | ||
-- namespace parameter of p.getCategoryName. |
-- namespace parameter of p.getCategoryName. |
||
if not ns or type(ns) ~= 'number' then |
if not ns or type(ns) ~= 'number' then |
||
return |
return nil |
||
end |
end |
||
local nskey = nskeys[ns] |
local nskey = nskeys[ns] |
||
if not nskey then |
if not nskey and ns % 2 == 1 then |
||
⚫ | |||
nskey = 'talk' |
nskey = 'talk' |
||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
return nskey |
return nskey |
||
Line 109: | Line 112: | ||
-- the protection type, the protection level, the namespace number, the |
-- the protection type, the protection level, the namespace number, the |
||
-- reason for protection, and the expiry date. |
-- reason for protection, and the expiry date. |
||
⚫ | |||
-- Preprocess parameters |
|||
cats = cats or categories |
cats = cats or categories |
||
⚫ | |||
properties.protType = protType or 'all' |
|||
properties.protLevel = protLevel or 'all' |
|||
properties.namespace = p.matchNamespace(namespace) |
|||
properties.reason = reason or 'all' |
|||
⚫ | |||
properties.expiry = 'all' |
|||
⚫ | |||
properties.expiry = 'temp' |
|||
⚫ | |||
⚫ | |||
local order = {'expiry', 'namespace', 'protLevel', 'protType', 'reason'} |
|||
{pos = 5, val = expiry}, |
|||
⚫ | |||
{pos = 3, val = namespace}, |
|||
⚫ | |||
{pos = 2, val = protLevel}, |
|||
⚫ | |||
{pos = 1, val = protType}, |
|||
⚫ | |||
{pos = 4, val = reason} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
error(reason .. ' is not a valid reason') |
|||
⚫ | |||
end |
end |
||
local |
local active, inactive = {}, {} |
||
for i, |
for i, t in ipairs(properties) do |
||
if |
if t.val then |
||
active[#active + 1] = t |
|||
⚫ | |||
inactive[#inactive + 1] = t |
|||
end |
end |
||
end |
end |
||
local |
local noActive = #active |
||
local attemptOrder = active |
|||
-- Try successively generic matches until we run out of key combinations |
|||
for i |
for i, t in ipairs(inactive) do |
||
attemptOrder[#attemptOrder + 1] = t |
|||
⚫ | |||
end |
|||
⚫ | |||
if pos > noActiveProperties then |
|||
⚫ | |||
categoryKey[pos] = 'all' |
|||
⚫ | |||
for j, t in ipairs(attemptOrder) do |
|||
local pos = t.pos |
|||
local val = t.val |
|||
⚫ | |||
⚫ | |||
else |
else |
||
local quotient = i / 2 ^ ( |
local quotient = i / 2 ^ (j - 1) |
||
quotient = floor(quotient) |
quotient = floor(quotient) |
||
if quotient % 2 == 1 then |
if quotient % 2 == 1 then |
||
key[pos] = val |
|||
else |
else |
||
key[pos] = 'all' |
|||
end |
end |
||
end |
end |
||
end |
end |
||
key = tconcat(key, '-') |
|||
mw.log( |
mw.log(key) -- for debugging |
||
local attempt = cats[ |
local attempt = cats[key] |
||
if attempt then |
if attempt then |
||
return attempt |
return attempt |