Module:Protection banner: Difference between revisions

change this to something that should work if I can get the order figured out
(save progress in simplifying the attempt order algorithm)
(change this to something that should work if I can get the order figured out)
Line 83:
-- Define often-used functions as local variables.
local tconcat = table.concat
local tinsert = table.insert
local floor = math.floor
 
Line 111 ⟶ 112:
-- Preprocess parameters
cats = cats or categories
local properties = {}
protType = protType or 'all'
protLevelproperties.protType = protLevelprotType 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 propertiesorder = {'expiry', 'namespace', 'protLevel', 'protType', 'reason'}
local behavior = behaviors[reason]
if behavior == 'namespaceFirst' then
tinsert(propertiesorder, table.remove(propertiesorder, 2)) -- move namespace to the end
elseif behavior ~= 'reasonFirst' and reason ~= 'all' then
error(reason .. ' is not a valid reason')
end
 
local activePropertiesactivePropertyKeys = {}
for i, propertypropertyKey in ipairs(propertiesorder) do
if propertyproperties[propertyKey] ~= 'all' then
activePropertiesactivePropertyKeys[#activePropertiesactivePropertyKeys + 1] = propertypropertyKey
end
end
local noActiveProperties = #activePropertiesactivePropertyKeys
-- Try successively generic matches until we run out of key combinations
for i = 1, 2^noActiveProperties do
local keycategoryKey = {}
for pos = 1, 5 do
if pos > noActiveProperties then
keycategoryKey[pos] = 'all'
else
local quotient = i / 2 ^ (pos - 1)
quotient = floor(quotient)
if quotient % 2 == 1 then
keycategoryKey[pos] = protectionPropertiesproperties[jactivePropertyKeys[pos]]
else -- quotient % 2 == 0
keycategoryKey[pos] = 'all'
end
end
end
keycategoryKey = tconcat(keycategoryKey, '-')
mw.log(keycategoryKey) -- for debugging
local attempt = cats[keycategoryKey]
if attempt then
return attempt