Module:Protection banner: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(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: | Line 196: | ||
--[[ |
--[[ |
||
-- Define the initial order to test properties in. The subtable position |
-- Define the initial order to test properties in. The subtable position |
||
-- is the order the properties will be tested in, and the |
-- is the order the properties will be tested in, and the keypos value in |
||
-- each subtable is the position of the value in the category key. |
-- each subtable is the position of the value in the category key. |
||
--]] |
--]] |
||
local properties = { |
local properties = { |
||
expiry = { |
expiry = {order = 1, keypos = 5, val = expiry}, |
||
namespace = { |
namespace = {order = 2, keypos = 3, val = p.matchNamespace(namespace)}, |
||
reason = { |
reason = {order = 3, keypos = 4, val = reason}, |
||
level = { |
level = {order = 4, keypos = 2, val = level}, |
||
action = { |
action = {order = 5, keypos = 1, val = action} |
||
} |
} |
||
Line 214: | Line 214: | ||
-- vandalism categories if they were available. |
-- vandalism categories if they were available. |
||
--]] |
--]] |
||
⚫ | |||
⚫ | |||
local categoryOrder = reasonTable and reasonTable.categoryOrder |
|||
⚫ | |||
local categoryOrderType = type(categoryOrder) |
|||
categoryOrder = 'reason' |
|||
local configOrder = {} |
|||
if categoryOrderType == 'table' then |
|||
⚫ | |||
for i = 1, 5 do |
|||
⚫ | |||
if not propertiesKey then |
|||
error('no properties key') |
|||
⚫ | |||
local property = properties[propertiesKey] |
|||
⚫ | |||
error('invalid properties key') |
|||
end |
|||
if dupes[property] then |
|||
error('dupe detected') |
|||
⚫ | |||
dupes[property] = true |
|||
end |
|||
configOrder[i] = property |
|||
end |
|||
else |
else |
||
for propertiesKey, t in pairs(properties) do |
|||
⚫ | |||
configOrder[t.order] = t |
|||
⚫ | |||
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') |
|||
⚫ | |||
end |
|||
error(reason .. ' is not a valid reason') |
|||
toTableEnd(configOrder, property.order) |
|||
end |
|||
end |
end |
||
Line 237: | Line 258: | ||
--]] |
--]] |
||
local active, inactive = {}, {} |
local active, inactive = {}, {} |
||
for i, t in ipairs( |
for i, t in ipairs(configOrder) do |
||
if t.val then |
if t.val then |
||
active[#active + 1] = t |
active[#active + 1] = t |
||
Line 285: | Line 306: | ||
local key = {} |
local key = {} |
||
for j, t in ipairs(attemptOrder) do |
for j, t in ipairs(attemptOrder) do |
||
⚫ | |||
local val = t.val |
|||
if j > noActive then |
if j > noActive then |
||
key[ |
key[t.keypos] = 'all' |
||
else |
else |
||
local quotient = i / 2 ^ (j - 1) |
local quotient = i / 2 ^ (j - 1) |
||
quotient = ceil(quotient) |
quotient = ceil(quotient) |
||
if quotient % 2 == 1 then |
if quotient % 2 == 1 then |
||
key[ |
key[t.keypos] = t.val |
||
else |
else |
||
key[ |
key[t.keypos] = 'all' |
||
end |
end |
||
end |
end |