Changes

Jump to navigation Jump to search

Module:Protection banner

214 bytes added, 07:23, 11 March 2014
change this to something that should work if I can get the order figured out
-- Define often-used functions as local variables.
local tconcat = table.concat
local tinsert = table.insert
local floor = math.floor
-- 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 order = {'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 activeProperties activePropertyKeys = {} for i, property propertyKey in ipairs(propertiesorder) do if property properties[propertyKey] ~= 'all' then activePropertiesactivePropertyKeys[#activeProperties activePropertyKeys + 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 key categoryKey = {}
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
key categoryKey = tconcat(keycategoryKey, '-') mw.log(keycategoryKey) -- for debugging local attempt = cats[keycategoryKey]
if attempt then
return attempt
Anonymous user

Navigation menu