Anonymous user
Module:Protection banner: Difference between revisions
some cleanup
(use a __tostring metamethod to render the banner objects) |
(some cleanup) |
||
Line 11:
-- Lazily initialise modules and objects we don't always need.
local mArguments, mMessageBox, lang
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
local function makeCategoryLink(cat)
if cat then▼
return string.format(▼
'[[%s:%s]]',▼
mw.site.namespaces[14].name,▼
cat▼
)▼
else▼
return ''▼
end▼
end▼
if result then
end▼
end▼
'invalid %s ("%s")',
))
--------------------------------------------------------------------------------
Line 17 ⟶ 50:
local Protection = class('Protection')
Protection.supportedActions = {
move = true,
}
Protection.bannerConfigFields = {
}
function Protection:initialize(args, configObj, titleObj)
Line 24 ⟶ 73:
-- Set action
do
elseif self.supportedActions[args.action] then
▲ edit = true,
▲ move = true,
▲ autoreview = true
▲ if args.action and actions[args.action] then
self.action = args.action
else
end
end
Line 39 ⟶ 84:
-- Set level
do
if self.level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
-- since templateeditors can do both.
self.level = 'templateeditor'
▲ end
▲ if self.action == 'move' and level == 'autoconfirmed' then
-- Users need to be autoconfirmed to move pages anyway, so treat
-- semi-move-protected pages as unprotected.
self.level = '*'
▲ end
▲ end
▲ -- Validation function for the expiry and the protection date
▲ local function validateDate(date, dateType)
▲ lang = lang or mw.language.getContentLanguage()
▲ local success, expiry = pcall(lang.formatDate, lang, 'U', args.expiry)
▲ expiry = tonumber(expiry)
▲ if success and expiry then
▲ return expiry
▲ return string.format(
▲ dateType,
▲ tostring(args.expiry)
end
end
Line 71 ⟶ 98:
-- Set expiry
if args.expiry then
self.expiry = 'indef'
elseif type(args.expiry) == 'number' then
Line 96 ⟶ 122:
self.bannerConfig = {}
local cfg = configObj.cfg
▲ 'text',
▲ 'explanation',
▲ 'tooltip',
▲ 'alt',
▲ 'link',
▲ 'image'
local configTables = {}
if cfg.banners[self.action] then
Line 113 ⟶ 131:
end
configTables[#configTables + 1] = cfg.masterBanner
for i, field in ipairs(
for j, t in ipairs(configTables) do
if t[field] then
Line 126 ⟶ 144:
function Protection:isProtected()
return self.level ~= '*'
▲end
▲ if cat then
▲ return string.format(
▲ '[[%s:%s]]',
▲ mw.site.namespaces[14].name,
▲ cat
▲ )
▲ else
▲ return ''
▲ end
end
Line 291 ⟶ 296:
end
return
end
Line 306 ⟶ 311:
cat = self._configObj.msg['tracking-category-expiry']
end
return
end
Line 317 ⟶ 322:
cat = configObj.msg['tracking-category-incorrect']
end
return
end
Line 333 ⟶ 338:
cat = configObj.msg['tracking-category-template']
end
return
end
|