}
local reasonBehaviors behaviors = {
vandalism = 'namespaceFirst',
dispute = 'reasonFirst',
-- Define often-used functions as local variables.
local tconcat = table.concat
local floor = math.floor
local p = {}
expiry = 'temp'
end
--[[ -- Define the key table and the order to test it in. -- The idiosyncracies of the old template system have been distilled down to -- two basic behaviors - templates that prioritise matching the reason over -- matching the namespace, and templates that prioritise matching the -- namespace over matching the reason. In each case the function tries to -- match specific keys, and if there is no match, it proceeds to match -- increasingly generic keys, until eventually it will match the key -- "all-all-all-all-all". --]] local protectionProperties properties = {protTypeexpiry, namespace, protLevel, namespaceprotType, reason, expiry} local reasonBehavior behavior = reasonBehaviorsbehaviors[reason] local attemptOrder if reasonBehavior behavior == 'namespaceFirst' then attemptOrder = { -- typetinsert(properties, leveltable.remove(properties, ns, reason, expiry 2)) -- true corresponds move namespace to the original protectionProperties key, -- and false corresponds to the key "all". {true, true, true, true, true}, -- 1 {true, true, true, true, false}, -- 2 {true, true, true, false, true}, -- 3 {true, true, true, false, false}, -- 4 {true, false, true, true, true}, -- 5 {true, false, true, true, false}, -- 6 {true, false, true, false, true}, -- 7 {true, false, true, false, false}, -- 8 {false, false, true, false, false}, -- 9 {true, true, false, true, true}, -- 10 {true, true, false, true, false}, -- 11 {true, true, false, false, true}, -- 12 {true, false, false, true, true}, -- 13 {true, false, false, true, false}, -- 14 {true, false, false, false, true}, -- 15 {true, false, false, false, false}, -- 16 {false, false, false, false, false} -- 17 }end elseif reasonBehavior =behavior ~= 'reasonFirst' or and reason =~= 'all' then attemptOrder = { -- type, level, ns, reason, expiry {true, true, true, true, true}, -- 1 {true, true, true, true, false}, -- 2 {true, true, false, true, true}, -- 3 {true, true, false, true, false}, -- 4 {true, false, true, true, true}, -- 5 {true, false, true, true, false}, -- 6 {true, false, false, true, true}, -- 7 {true, false, false, true, false}, -- 8 {false, false, false, true, false}, -- 9 {true, true, true, false, true}, -- 10 {true, true, true, false, false}, -- 11 {true, true, false, false, true}, -- 12 {true, false, true, false, true}, -- 13 {true, false, true, false, false}, -- 14 {true, false, false, false, true}, -- 15 {true, false, false, false, false}, -- 16 {false, false, false, false, false} -- 17 } else
error(reason .. ' is not a valid reason')
end
local activeProperties = {}
for i, property in ipairs(properties) do
if property ~= 'all' then
activeProperties[#activeProperties + 1] = property
end
end
local noActiveProperties = #activeProperties
-- Try successively generic matches until we run out of key combinations
for i= 1, t in ipairs(attemptOrder) 2^noActiveProperties do
local key = {}
for jpos = 1, useProperty in ipairs(t) 5 do if useProperty pos > noActiveProperties then key[jpos] = protectionProperties[j]'all'
else
local quotient = i / 2 ^ (pos - 1) quotient = floor(quotient) if quotient % 2 == 1 then key[pos] = protectionProperties[j] else -- quotient % 2 == 0 key[pos] = 'all' end
end
end
end
error('No category match found; please define the category for key "all-all-all-all-all"')
end
return p