Jump to content

Module:Protection banner: Difference between revisions

try making the algorithm more general
(use the default mediawiki protection level names after all)
(try making the algorithm more general)
Line 34: Line 34:
['edit-sysop-all-blp-all'] = 'Wikipedia indefinitely protected biographies of living people',
['edit-sysop-all-blp-all'] = 'Wikipedia indefinitely protected biographies of living people',
['edit-autoconfirmed-all-all-indef'] = 'Wikipedia indefinitely semi-protected pages',
['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-talk-all-all'] = 'Wikipedia move-protected talk pages',
['move-sysop-all-all-indef'] = 'Wikipedia indefinitely move-protected pages',
['move-sysop-all-all-indef'] = 'Wikipedia indefinitely move-protected pages',
['edit-autoconfirmed-all-all-all'] = 'Wikipedia semi-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',
['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-autoconfirmed-all-all-all'] = 'Wikipedia pending changes protected pages (level 1)',
['pc-reviewer-all-all-all'] = 'Wikipedia pending changes protected pages (level 2)',
['pc-reviewer-all-all-all'] = 'Wikipedia pending changes protected pages (level 2)',
['all-all-all-all-all'] = 'Wikipedia protected pages',
['office'] = 'Wikipedia Office-protected pages',
}
}


Line 140: Line 140:
local keyTable = {protType, protLevel, namespace, reason, expiry}
local keyTable = {protType, protLevel, namespace, reason, expiry}
local attemptOrder = {
local attemptOrder = {
--   type, level, ns, reason, expiry
-- type, level, ns, reason, expiry
{true, true, true, true, true},    -- 1
{true, true, true, true, true},    -- 1
{true, true, true, true, false},    -- 2
{true, true, true, true, false},    -- 2
Line 148: Line 148:
{true, true, true, false, false},  -- 6
{true, true, true, false, false},  -- 6
{true, true, false, false, true},  -- 7
{true, true, false, false, true},  -- 7
{true, true, false, false, false},  -- 8
{true, false, true, true, true},    -- 8
{true, false, true, false, false},  -- 9
{true, false, true, true, false},  -- 9
{true, false, false, false, false}, -- 10
{true, false, false, true, true},  -- 10
{false, false, false, false, false} -- 11
{true, false, true, false, true},  -- 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 reasonFirst = {
local reasonBehaviors = {
vandalism = true,
vandalism = 'namespaceFirst',
office = true
dispute = 'reasonFirst',
blp = 'reasonFirst',
sock = 'reasonFirst',
office = 'reasonOnly',
}
}
 
if reasonFirst[reason] then
local reasonBehavior = reasonBehaviors[reason]
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[3], attemptOrder[4] = attemptOrder[4], attemptOrder[3]  
attemptOrder[5], attemptOrder[6] = attemptOrder[6], attemptOrder[5]
attemptOrder[5], attemptOrder[6] = attemptOrder[6], attemptOrder[5]
table.insert(attemptOrder, 2, {false, false, false, true, false}) -- To deal with office-protection
elseif not reasonBeavior then
error(reason .. ' is not a valid reason')
end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.