Open main menu

Changes

Module:Protection banner

129 bytes added, 17:18, 28 June 2014
some cleanup
-- 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
 
-- Validation function for the expiry and the protection date
local function validateDate(dateString, dateType)
lang = lang or mw.language.getContentLanguage()
local success, result = pcall(lang.formatDate, lang, 'U', dateString)
if success then
result = tonumber(result)
if result then
return result
end
end
error(string.format(
'invalid %s ("%s")',
dateType,
tostring(dateString)
))
end
--------------------------------------------------------------------------------
local Protection = class('Protection')
 
Protection.supportedActions = {
create = true,
edit = true,
move = true,
autoreview = true
}
 
Protection.bannerConfigFields = {
'text',
'explanation',
'tooltip',
'alt',
'link',
'image'
}
function Protection:initialize(args, configObj, titleObj)
-- Set action
do
local actions = {if not args.action then create self.action = true, 'edit = true, move = true, autoreview = true }' if argselseif self.action and actionssupportedActions[args.action] then
self.action = args.action
else
selferror('Unsupported action ' .. args.action = 'edit', 2)
end
end
-- Set level
do
local self.level = effectiveProtectionLevel(self.action, titleObj) if self.level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
-- since templateeditors can do both.
self.level = 'templateeditor' end if elseif not self.level or (self.action == 'move' and self.level == 'autoconfirmed' ) then
-- Users need to be autoconfirmed to move pages anyway, so treat
-- semi-move-protected pages as unprotected.
level = '*' end self.level = level or '*' 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 else return string.format( '<strong class="error">Error: invalid %s ("%s")</strong>', dateType, tostring(args.expiry) )
end
end
-- Set expiry
if args.expiry then
local indefStrings = if configObj.cfg.indefStrings if indefStrings[args.expiry] then
self.expiry = 'indef'
elseif type(args.expiry) == 'number' then
self.bannerConfig = {}
local cfg = configObj.cfg
local fields = {
'text',
'explanation',
'tooltip',
'alt',
'link',
'image'
}
local configTables = {}
if cfg.banners[self.action] then
end
configTables[#configTables + 1] = cfg.masterBanner
for i, field in ipairs(fieldsself.bannerConfigFields) do
for j, t in ipairs(configTables) do
if t[field] then
function Protection:isProtected()
return self.level ~= '*'
end
 
function Protection._makeCategoryLink(cat)
-- Static method for rendering category wikitext.
if cat then
return string.format(
'[[%s:%s]]',
mw.site.namespaces[14].name,
cat
)
else
return ''
end
end
end
return self._makeCategoryLinkmakeCategoryLink(cat)
end
cat = self._configObj.msg['tracking-category-expiry']
end
return self._makeCategoryLinkmakeCategoryLink(cat)
end
cat = configObj.msg['tracking-category-incorrect']
end
return self._makeCategoryLinkmakeCategoryLink(cat)
end
cat = configObj.msg['tracking-category-template']
end
return self._makeCategoryLinkmakeCategoryLink(cat)
end
Anonymous user