Module:Protection banner: Difference between revisions

key components are in the correct order now - property order still a long way off, though
(change this to something that should work if I can get the order figured out)
(key components are in the correct order now - property order still a long way off, though)
Line 84:
local tconcat = table.concat
local tinsert = table.insert
local tremove = table.remove
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))
end
 
local p = {}
Line 92 ⟶ 99:
-- namespace parameter of p.getCategoryName.
if not ns or type(ns) ~= 'number' then
return 'all'nil
end
local nskey = nskeys[ns]
if not nskey and ns % 2 == 1 then
if ns % 2 == 1 then
nskey = 'talk'
else
nskey = 'all'
end
end
return nskey
Line 109 ⟶ 112:
-- the protection type, the protection level, the namespace number, the
-- reason for protection, and the expiry date.
-- Preprocess parameters
cats = cats or categories
local properties = {}
properties.protType = protType or 'all'
properties.protLevel = protLevel or 'all'
properties.namespace = p.matchNamespace(namespace)
properties.reason = reason or 'all'
if not expiry then
properties.expiry = 'all'
elseif expiry ~= 'indef' then
properties.expiry = 'temp'
end
 
local properties = {}
local order = {'expiry', 'namespace', 'protLevel', 'protType', 'reason'}
{pos = 5, val = expiry},
local behavior = behaviors[reason]
{pos = 3, val = namespace},
if behavior == 'namespaceFirst' then
{pos = 2, val = protLevel},
tinsert(order, table.remove(order, 2)) -- move namespace to the end
{pos = 1, val = protType},
elseif behavior ~= 'reasonFirst' and reason ~= 'all' then
error(reason .. '{pos is= not4, aval valid= reason')}
}
 
elseiflocal behavior ~= 'reasonFirst' and reason ~= 'all' then
if not expiryreason then
local behavior = behaviors[reason]
if behavior == 'namespaceFirst' then
tinsert toTableEnd(order, table.remove(orderproperties, 2)) -- move namespace to the end
elseif expirybehavior ~= 'indefreasonFirst' then
error(reason .. ' is not a valid reason')
end
end
 
local activePropertyKeysactive, inactive = {}, {}
for i, propertyKeyt in ipairs(orderproperties) do
if properties[propertyKey] ~= 'all't.val then
activePropertyKeysactive[#activePropertyKeysactive + 1] = propertyKeyt
else
inactive[#inactive + 1] = t
end
end
local noActivePropertiesnoActive = #activePropertyKeysactive
 
local attemptOrder = active
-- Try successively generic matches until we run out of key combinations
for i, =t 1,in 2^noActivePropertiesipairs(inactive) do
attemptOrder[#attemptOrder + 1] = t
local categoryKey = {}
end
for pos = 1, 5 do
 
if pos > noActiveProperties then
for posi = 1, 52^noActive do
categoryKey[pos] = 'all'
local categoryKeykey = {}
for j, t in ipairs(attemptOrder) do
local pos = t.pos
local val = t.val
if nsj %> 2 == 1noActive then
nskey key[pos] = 'all'
else
local quotient = i / 2 ^ (posj - 1)
quotient = floor(quotient)
if quotient % 2 == 1 then
categoryKeykey[pos] = properties[activePropertyKeys[pos]]val
else -- quotient % 2 == 0
categoryKeykey[pos] = 'all'
end
end
end
categoryKeykey = tconcat(categoryKeykey, '-')
mw.log(categoryKeykey) -- for debugging
local attempt = cats[categoryKeykey]
if attempt then
return attempt