Module:Protection banner: Difference between revisions

try making the algorithm more general
Enwikipedia>Mr. Stradivarius
(use the default mediawiki protection level names after all)
Enwikipedia>Mr. Stradivarius
(try making the algorithm more general)
Line 34:
['edit-sysop-all-blp-all'] = 'Wikipedia indefinitely protected biographies of living people',
['edit-autoconfirmed-all-all-indef'] = 'Wikipedia indefinitely semi-protected pages',
['edit-autoconfirmed-category-all-all'] = 'Wikipedia semi-protected categories',
['edit-sysop-category-all-all'] = 'Wikipedia protected categories',
['move-sysop-talk-all-all'] = 'Wikipedia move-protected talk pages',
['move-sysop-all-all-indef'] = 'Wikipedia indefinitely move-protected pages',
['edit-autoconfirmed-all-all-all'] = 'Wikipedia semi-protected pages',
['all-all-all-all-all'] = 'Wikipedia protected pages',
['edit-autoconfirmed-category-all-all'] = 'Wikipedia semi-protected categories',
['edit-sysop-category-all-all'] = 'Wikipedia protected categories',
['move-sysop-all-all-all'] = 'Wikipedia move-protected pages',
['all-all-all-office-all'] = 'Wikipedia Office-protected pages',
['pc-autoconfirmed-all-all-all'] = 'Wikipedia pending changes protected pages (level 1)',
['pc-reviewer-all-all-all'] = 'Wikipedia pending changes protected pages (level 2)',
['all-all-all-all-all'] = 'Wikipedia protected pages',
['all-all-all-office-all'] = 'Wikipedia Office-protected pages',
}
 
Line 140:
local keyTable = {protType, protLevel, namespace, reason, expiry}
local attemptOrder = {
-- type, level, ns, reason, expiry
{true, true, true, true, true}, -- 1
{true, true, true, true, false}, -- 2
Line 148:
{true, true, true, false, false}, -- 6
{true, true, false, false, true}, -- 7
{true, truefalse, falsetrue, falsetrue, falsetrue}, -- 8
{true, false, true, falsetrue, false}, -- 9
{true, false, false, falsetrue, falsetrue}, -- 10
{falsetrue, false, falsetrue, false, falsetrue}, -- 11
{true, false, false, true, false}, -- 12
{true, false, true, false, false}, -- 13
{true, false, false, false, true}, -- 14
{true, false, false, false, false}, -- 15
{false, false, false, false, false} -- 16
}
local reasonFirstreasonBehaviors = {
vandalism = true'namespaceFirst',
dispute = 'reasonFirst',
office = true
blp = 'reasonFirst',
sock = 'reasonFirst',
office = true'reasonOnly',
}
 
local reasonBehavior = reasonBehaviors[reason]
if reasonFirst[reason] then
if reasonBehavior == 'reasonOnly' then
local attempt = cats[reason]
if attempt then
return attempt
else
error('the category for key "' .. reason .. '" is undefined')
end
elseif reasonBehavior == 'namespaceFirst' then
-- Sort the order so that namespace keys are checked before reason matches.
attemptOrder[3], attemptOrder[4] = attemptOrder[4], attemptOrder[3]
attemptOrder[5], attemptOrder[6] = attemptOrder[6], attemptOrder[5]
elseif not reasonBeavior then
table.insert(attemptOrder, 2, {false, false, false, true, false}) -- To deal with office-protection
error(reason .. ' is not a valid reason')
end