Module:Protection banner: Difference between revisions

make the category attempt order more configurable
(more data table restructuring, plus some fiddling around with the category name function; this is a progress save, so the code is horribly broken at the moment)
(make the category attempt order more configurable)
Line 196:
--[[
-- Define the initial order to test properties in. The subtable position
-- is the order the properties will be tested in, and the poskeypos value in
-- each subtable is the position of the value in the category key.
--]]
local properties = {
expiry = {posorder = 1, keypos = 5, val = expiry},
namespace = {'namespace'order = 2, poskeypos = 3, val = p.matchNamespace(namespace)},
reason = {posorder = 3, keypos = 4, val = reason},
level = {posorder = 4, keypos = 2, val = level},
action = {posorder = 5, keypos = 1, val = action}
}
 
Line 214:
-- vandalism categories if they were available.
--]]
categoryOrder local reasonTable = cfg.reasons[reason].categoryOrder
local categoryOrder
local categoryOrder = reasonTable and reasonTable.categoryOrder
if not reason then
local categoryOrderType = type(categoryOrder)
categoryOrder = 'reason'
local configOrder = {}
if categoryOrderType == 'table' then
local posdupes = t.pos{}
for i = 1, 5 do
local propertiesKey = categoryOrder[i]
if not propertiesKey then
error('no properties key')
end
local property = properties[propertiesKey]
if not reasonproperty then
error('invalid properties key')
end
if dupes[property] then
error('dupe detected')
else
dupes[property] = true
end
configOrder[i] = property
end
else
for propertiesKey, t in pairs(properties) do
categoryOrder = cfg.reasons[reason].categoryOrder
configOrder[t.order] = t
end
end
if categoryOrder == 'namespace' then
if categoryOrderType == 'string' then
toTableEnd(properties, 2) -- move namespace to end
local property = properties[categoryOrder]
elseif categoryOrder == 'reason' then
if not property then
toTableEnd(properties, 3) -- move reason to end
error('invalid category order string')
else
end
error(reason .. ' is not a valid reason')
toTableEnd(configOrder, property.order)
end
end
 
Line 237 ⟶ 258:
--]]
local active, inactive = {}, {}
for i, t in ipairs(propertiesconfigOrder) do
if t.val then
active[#active + 1] = t
Line 285 ⟶ 306:
local key = {}
for j, t in ipairs(attemptOrder) do
local pos = t.pos
local val = t.val
if j > noActive then
key[post.keypos] = 'all'
else
local quotient = i / 2 ^ (j - 1)
quotient = ceil(quotient)
if quotient % 2 == 1 then
key[post.keypos] = t.val
else
key[post.keypos] = 'all'
end
end