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', | ||
['move-sysop-all-all-all'] = 'Wikipedia move-protected pages', | ['move-sysop-all-all-all'] = 'Wikipedia move-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 | |||
{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}, -- | {true, false, true, true, true}, -- 8 | ||
{true, false, true, false, false}, -- | {true, false, true, true, false}, -- 9 | ||
{true, false, false, false, false}, -- | {true, false, false, true, true}, -- 10 | ||
{false, false, false, false, false} -- | {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 | local reasonBehaviors = { | ||
vandalism = | vandalism = 'namespaceFirst', | ||
office = | dispute = 'reasonFirst', | ||
blp = 'reasonFirst', | |||
sock = 'reasonFirst', | |||
office = 'reasonOnly', | |||
} | } | ||
if | 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] | ||
elseif not reasonBeavior then | |||
error(reason .. ' is not a valid reason') | |||
end | end | ||