Changes

Jump to navigation Jump to search

Module:Protection banner

448 bytes added, 01:47, 28 June 2014
(edit conflict) replace Protection getter functions with public attributes
-- Lazily initialise modules and objects we don't always need.
local mArguments, mMessageBox, lang ---------------------------------------------------------------------------------- Config class-------------------------------------------------------------------------------- local Config = class('Config') function Config:initialize(data) data = data or mw.loadData('Module:Protection banner/config') self._cfg = data.cfg self._msg = data.msg self._bannerConfigTables = {}end function Config:getBannerConfig(protectionObj) if self._bannerConfigTables[protectionObj] then return self._bannerConfigTables[protectionObj] else local ret = {} local cfg = self._cfg local action = protectionObj.action local level = protectionObj.level local reason = protectionObj.reason local fields = { 'text', 'explanation', 'tooltip', 'alt', 'link', 'image' } local configTables = {} if cfg.banners[action] then configTables[#configTables + 1] = cfg.banners[action][reason] end if cfg.defaultBanners[action] then configTables[#configTables + 1] = cfg.defaultBanners[action][level] configTables[#configTables + 1] = cfg.defaultBanners[action].default end configTables[#configTables + 1] = cfg.masterBanner for i, configfield in ipairs(fields) do for j, t in ipairs(configTables) do if t[field] then ret[field] = t[field] break end end end self._bannerConfigTables[protectionObj] = ret return ret endend function Config:getConfigTable(key) local blacklist = { banners = true, defaultBanners = true, masterBanner = true } if not blacklist[key] then return self._cfg[key] else return nil endend function Config:getMessage(key) return self._msg[key]end
--------------------------------------------------------------------------------
}
if args.action and actions[args.action] then
self._action action = args.action
else
self._action action = 'edit'
end
end
-- Set level
do
local level = effectiveProtectionLevel(self._actionaction, titleObj)
if level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
level = 'templateeditor'
end
if self._action action == 'move' and 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 = level or '*'
end
-- Set expiry
if args.expiry then
local indefStrings = configObj.cfg.:getConfigTable('indefStrings')
if indefStrings[args.expiry] then
self._expiry expiry = 'indef'
elseif type(args.expiry) == 'number' then
self._expiry expiry = args.expiry
else
self._expiry expiry = validateDate(args.expiry, 'expiry date')
end
end
local reason = args.reason or args[1]
if reason then
self._reason reason = reason:lower()
end
end
-- Set protection date
self._protectionDate protectionDate = validateDate(args.date, 'protection date') -- Set banner config do self.bannerConfig = {} local cfg = configObj.cfg local fields = { 'text', 'explanation', 'tooltip', 'alt', 'link', 'image' } local configTables = {} if cfg.banners[self._action] then configTables[#configTables + 1] = cfg.banners[self._action][self._reason] end if cfg.defaultBanners[self._action] then configTables[#configTables + 1] = cfg.defaultBanners[self._action][self._level] configTables[#configTables + 1] = cfg.defaultBanners[self._action].default end configTables[#configTables + 1] = cfg.masterBanner for i, field in ipairs(fields) do for j, t in ipairs(configTables) do if t[field] then self.bannerConfig[field] = t[field] break end end end endend function Protection:getAction() return self._actionend function Protection:getLevel() return self._level
end
function Protection:isProtected()
return self._level ~= '*'
end
 
function Protection:getReason()
return self._reason
end
 
function Protection:getExpiry()
return self._expiry
end
 
function Protection:getProtectionDate()
return self._protectionDate
end
self._configObj = configObj
self._protectionObj = protectionObj
self._bannerConfig = configObj:getBannerConfig(protectionObj.bannerConfig)
self._titleObj = titleObj
end
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj.:getMessage(msg[msg])
return self:_substituteParameters(msg)
end
-- A link to the page history or the move log, depending on the kind of
-- protection.
local action = self._protectionObj:getAction().action
local pagename = self._titleObj.prefixedText
if action == 'move' then
function Blurb:_makeDisputeBlurbParameter()
local expiry = self._protectionObj:getExpiry().expiry
if type(expiry) == 'number' then
return self:_getExpandedMessage('dispute-blurb-expiry')
function Blurb:_makeEditRequestParameter()
local mEditRequest = require('Module:Submit an edit request')
local action = self._protectionObj:getAction().action local level = self._protectionObj:getLevel().level
-- Get the display message key.
function Blurb:_makeExpiryParameter()
local expiry = self._protectionObj:getExpiry().expiry
if expiry == 'indef' then
return nil
function Blurb:_makeExplanationBlurbParameter()
local action = self._protectionObj:getAction().action local level = self._protectionObj:getLevel().level
local namespace = self._titleObj.namespace
local isTalk = self._titleObj.isTalkPage
function Blurb:_makeImageLinkParameter()
local imageLinks = self._configObj.cfg.:getConfigTable('imageLinks') local action = self._protectionObj:getAction().action local level = self._protectionObj:getLevel().level
local msg
if imageLinks[action][level] then
function Blurb:_makeIntroBlurbParameter()
local expiry = self._protectionObj:getExpiry().expiry
if type(expiry) == 'number' then
return self:_getExpandedMessage('intro-blurb-expiry')
function Blurb:_makeOfficeBlurbParameter()
local protectionDate = self._protectionObj:getProtectionDate().protectionDate
if protectionDate then
return self:_getExpandedMessage('office-blurb-protectiondate')
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj.cfg.:getConfigTable('pagetypes')
local namespace = self._titleObj.namespace
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined')
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj.cfg.:getConfigTable('protectionBlurbs') local action = self._protectionObj:getAction().action local level = self._protectionObj:getLevel().level
local msg
if protectionBlurbs[action][level] then
function Blurb:_makeProtectionDateParameter()
local protectionDate = self._protectionObj:getProtectionDate().protectionDate
if type(protectionDate) == 'number' then
return Blurb.formatDate(protectionDate)
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj.cfg.:getConfigTable('protectionLevels') local action = self._protectionObj:getAction().action local level = self._protectionObj:getLevel().level
local msg
if protectionLevels[action][level] then
function Blurb:_makeProtectionLogParameter()
local action = self._protectionObj:getAction().action
local pagename = self._titleObj.prefixedText
if action == 'autoreview' then
function Blurb:_makeResetBlurbParameter()
local protectionDate = self._protectionObj:getProtectionDate().protectionDate
if protectionDate then
return self:_getExpandedMessage('reset-blurb-protectiondate')
function Blurb:_makeTooltipBlurbParameter()
local expiry = self._protectionObj:getExpiry().expiry
if type(expiry) == 'number' then
return self:_getExpandedMessage('tooltip-blurb-expiry')
end
local action = protectionObj:getAction().action local level = protectionObj:getLevel().level local expiry = protectionObj:getExpiry().expiry
local namespace = titleObj.namespace
-- Fully protected modules and templates get the special red "indef"
-- padlock.
self._imageFilename = self._configObj.msg[:getMessage('image-filename-indef'])
return nil
end
-- Deal with regular protection types.
local images = self._configObj.cfg.:getConfigTable('images')
if images[action] then
if images[action][level] then
function BannerTemplate:renderImage()
local filename = self._imageFilename
or self._configObj.msg[:getMessage('image-filename-default'])
or 'Transparent.gif'
return newFileLink(filename)
-- Get the expiry.
local expiry = protectionObj:getExpiry().expiry
if type(expiry) == 'number' then
expiry = 'temp'
do
local namespace = titleObj.namespace
local categoryNamespaces = configObj.cfg.:getConfigTable('categoryNamespaceKeys')
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
-- Get the other inputs.
local reason = protectionObj:getReason().reason local action = protectionObj:getAction().action local level = protectionObj:getLevel().level
--[[
local configOrder = {}
do
local reasonsWithNamespacePriority = configObj.cfg.:getConfigTable('reasonsWithNamespacePriority')
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
-- pos field in the property table.
--]]
local cats = configObj.cfg.:getConfigTable('protectionCategories')
local cat
for i = 1, 2^noActive do
function ExpiryCategory:render()
local configObj reasonsWithoutExpiryCheck = self._configObj:getConfigTable('reasonsWithoutExpiryCheck') local protectionObj expiryCheckActions = self._protectionObj _configObj:getConfigTable('expiryCheckActions') local reasonsWithoutExpiryCheck expiry = configObjself.cfg_protectionObj.reasonsWithoutExpiryCheckexpiry local expiryCheckActions action = configObjself.cfg_protectionObj.expiryCheckActions local expiry = protectionObj:getExpiry() local action = protectionObj:getAction() local reason = protectionObj:getReason()self._protectionObj.reason
if not expiry
and not reasonsWithoutExpiryCheck[reason]
then
self:setName(configObj.msg[:getMessage('tracking-category-expiry']))
end
return Category.render(self)
local configObj = self._configObj
local protectionObj = self._protectionObj
local expiry = protectionObj:getExpiry().expiry local action = protectionObj:getAction().action local level = protectionObj:getLevel().level
if not protectionObj:isProtected()
or type(expiry) == 'number' and expiry < os.time()
then
self:setName(configObj.msg[:getMessage('tracking-category-incorrect']))
end
return Category.render(self)
function TemplateCategory:render()
local configObj = self._configObj
local protectionObj action = self._protectionObj.action local titleObj level = self._titleObj local action = protectionObj:getAction() local _protectionObj.level = protectionObj:getLevel() local namespace = titleObjself._titleObj.namespace
if level == 'templateeditor'
)
then
self:setName(configObj.msg[:getMessage('tracking-category-template']))
end
return Category.render(self)
-- Get data objects
if not config then config local configObj = mw.loadDataConfig:new('Module:Protection banner/config') end local configObj = config
local protectionObj = Protection:new(args, configObj, titleObj)
-- Set the image fields
local bannerConfig = configObj:getBannerConfig(protectionObj.bannerConfig)
bannerObj:setImageFilename(bannerConfig.image, protectionObj, titleObj)
if isPadlock then
return {
Protection = Protection,
Config = Config,
Blurb = Blurb,
BannerTemplate = BannerTemplate,
Anonymous user

Navigation menu