Module:Protection banner: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(use a __tostring metamethod to render the banner objects) |
(some cleanup) |
||
Line 11: | Line 11: | ||
-- Lazily initialise modules and objects we don't always need. |
-- Lazily initialise modules and objects we don't always need. |
||
local mArguments, mMessageBox, lang |
local mArguments, mMessageBox, lang |
||
-------------------------------------------------------------------------------- |
|||
-- Helper functions |
|||
-------------------------------------------------------------------------------- |
|||
local function makeCategoryLink(cat) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if result then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
'invalid %s ("%s")', |
|||
⚫ | |||
⚫ | |||
)) |
|||
⚫ | |||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
Line 17: | Line 50: | ||
local Protection = class('Protection') |
local Protection = class('Protection') |
||
Protection.supportedActions = { |
|||
⚫ | |||
⚫ | |||
move = true, |
|||
⚫ | |||
} |
|||
Protection.bannerConfigFields = { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
function Protection:initialize(args, configObj, titleObj) |
function Protection:initialize(args, configObj, titleObj) |
||
Line 24: | Line 73: | ||
-- Set action |
-- Set action |
||
do |
do |
||
⚫ | |||
local actions = { |
|||
self.action = 'edit' |
|||
elseif self.supportedActions[args.action] then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
self.action = args.action |
self.action = args.action |
||
else |
else |
||
error('Unsupported action ' .. args.action, 2) |
|||
end |
end |
||
end |
end |
||
Line 39: | Line 84: | ||
-- Set level |
-- Set level |
||
do |
do |
||
self.level = effectiveProtectionLevel(self.action, titleObj) |
|||
if level == 'accountcreator' then |
if self.level == 'accountcreator' then |
||
-- Lump titleblacklisted pages in with template-protected pages, |
-- Lump titleblacklisted pages in with template-protected pages, |
||
-- since templateeditors can do both. |
-- since templateeditors can do both. |
||
level = 'templateeditor' |
self.level = 'templateeditor' |
||
⚫ | |||
⚫ | |||
⚫ | |||
-- Users need to be autoconfirmed to move pages anyway, so treat |
-- Users need to be autoconfirmed to move pages anyway, so treat |
||
-- semi-move-protected pages as unprotected. |
-- semi-move-protected pages as unprotected. |
||
level = '*' |
self.level = '*' |
||
⚫ | |||
self.level = level or '*' |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
'<strong class="error">Error: invalid %s ("%s")</strong>', |
|||
⚫ | |||
⚫ | |||
) |
|||
end |
end |
||
end |
end |
||
Line 71: | Line 98: | ||
-- Set expiry |
-- Set expiry |
||
if args.expiry then |
if args.expiry then |
||
if configObj.cfg.indefStrings[args.expiry] then |
|||
if indefStrings[args.expiry] then |
|||
self.expiry = 'indef' |
self.expiry = 'indef' |
||
elseif type(args.expiry) == 'number' then |
elseif type(args.expiry) == 'number' then |
||
Line 96: | Line 122: | ||
self.bannerConfig = {} |
self.bannerConfig = {} |
||
local cfg = configObj.cfg |
local cfg = configObj.cfg |
||
local fields = { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
local configTables = {} |
local configTables = {} |
||
if cfg.banners[self.action] then |
if cfg.banners[self.action] then |
||
Line 113: | Line 131: | ||
end |
end |
||
configTables[#configTables + 1] = cfg.masterBanner |
configTables[#configTables + 1] = cfg.masterBanner |
||
for i, field in ipairs( |
for i, field in ipairs(self.bannerConfigFields) do |
||
for j, t in ipairs(configTables) do |
for j, t in ipairs(configTables) do |
||
if t[field] then |
if t[field] then |
||
Line 126: | Line 144: | ||
function Protection:isProtected() |
function Protection:isProtected() |
||
return self.level ~= '*' |
return self.level ~= '*' |
||
⚫ | |||
function Protection._makeCategoryLink(cat) |
|||
-- Static method for rendering category wikitext. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
Line 291: | Line 296: | ||
end |
end |
||
return |
return makeCategoryLink(cat) |
||
end |
end |
||
Line 306: | Line 311: | ||
cat = self._configObj.msg['tracking-category-expiry'] |
cat = self._configObj.msg['tracking-category-expiry'] |
||
end |
end |
||
return |
return makeCategoryLink(cat) |
||
end |
end |
||
Line 317: | Line 322: | ||
cat = configObj.msg['tracking-category-incorrect'] |
cat = configObj.msg['tracking-category-incorrect'] |
||
end |
end |
||
return |
return makeCategoryLink(cat) |
||
end |
end |
||
Line 333: | Line 338: | ||
cat = configObj.msg['tracking-category-template'] |
cat = configObj.msg['tracking-category-template'] |
||
end |
end |
||
return |
return makeCategoryLink(cat) |
||
end |
end |
||