Module:Protection banner: Difference between revisions

shorter names - use protectionObj instead of protectionStatusObj, and Protection instead of ProtectionStatus
Enwikipedia>Mr. Stradivarius
(change BannerTemplate:setImageFilename to accept protection objects and title objects rather than individual parameters)
Enwikipedia>Mr. Stradivarius
(shorter names - use protectionObj instead of protectionStatusObj, and Protection instead of ProtectionStatus)
Line 25:
end
 
function Config:getBannerConfig(protectionStatusObjprotectionObj)
if self._bannerConfigTables[protectionStatusObjprotectionObj] then
return self._bannerConfigTables[protectionStatusObjprotectionObj]
else
local ret = {}
local cfg = self._cfg
local action = protectionStatusObjprotectionObj:getAction()
local level = protectionStatusObjprotectionObj:getLevel()
local reason = protectionStatusObjprotectionObj:getReason()
local fields = {
'text',
Line 58:
end
end
self._bannerConfigTables[protectionStatusObjprotectionObj] = ret
return ret
end
Line 81:
 
--------------------------------------------------------------------------------
-- ProtectionStatusProtection class
--------------------------------------------------------------------------------
 
local ProtectionStatusProtection = class('ProtectionStatusProtection')
 
function ProtectionStatusProtection:initialize(args, configObj, titleObj)
-- Set action
do
Line 158:
end
 
function ProtectionStatusProtection:getAction()
return self._action
end
 
function ProtectionStatusProtection:getLevel()
return self._level
end
 
function ProtectionStatusProtection:isProtected()
return self._level ~= '*'
end
 
function ProtectionStatusProtection:getReason()
return self._reason
end
 
function ProtectionStatusProtection:getExpiry()
return self._expiry
end
 
function ProtectionStatusProtection:getProtectionDate()
return self._protectionDate
end
Line 188:
local Blurb = class('Blurb')
 
function Blurb:initialize(configObj, protectionStatusObjprotectionObj, titleObj)
self._configObj = configObj
self._protectionObj = protectionObj
self._protectionStatusObj = protectionStatusObj
self._bannerConfig = configObj:getBannerConfig(protectionStatusObjprotectionObj)
self._titleObj = titleObj
end
Line 268:
-- A link to the page history or the move log, depending on the kind of
-- protection.
local action = self._protectionStatusObj_protectionObj:getAction()
local pagename = self._titleObj.prefixedText
if action == 'move' then
Line 296:
 
function Blurb:_makeDisputeBlurbParameter()
local expiry = self._protectionStatusObj_protectionObj:getExpiry()
if type(expiry) == 'number' then
return self:_getExpandedMessage('dispute-blurb-expiry')
Line 323:
function Blurb:_makeEditRequestParameter()
local mEditRequest = require('Module:Submit an edit request')
local action = self._protectionStatusObj_protectionObj:getAction()
local level = self._protectionStatusObj_protectionObj:getLevel()
-- Get the display message key.
Line 350:
 
function Blurb:_makeExpiryParameter()
local expiry = self._protectionStatusObj_protectionObj:getExpiry()
if expiry == 'indef' then
return nil
Line 362:
 
function Blurb:_makeExplanationBlurbParameter()
local action = self._protectionStatusObj_protectionObj:getAction()
local level = self._protectionStatusObj_protectionObj:getLevel()
local namespace = self._titleObj.namespace
local isTalk = self._titleObj.isTalkPage
Line 394:
 
function Blurb:_makeIntroBlurbParameter()
local expiry = self._protectionStatusObj_protectionObj:getExpiry()
if type(expiry) == 'number' then
return self:_getExpandedMessage('intro-blurb-expiry')
Line 403:
 
function Blurb:_makeOfficeBlurbParameter()
local protectionDate = self._protectionStatusObj_protectionObj:getProtectionDate()
if protectionDate then
return self:_getExpandedMessage('office-blurb-protectiondate')
Line 419:
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj:getConfigTable('protectionBlurbs')
local action = self._protectionStatusObj_protectionObj:getAction()
local level = self._protectionStatusObj_protectionObj:getLevel()
local msg
if protectionBlurbs[action][level] then
Line 435:
 
function Blurb:_makeProtectionDateParameter()
local protectionDate = self._protectionStatusObj_protectionObj:getProtectionDate()
if type(protectionDate) == 'number' then
return Blurb.formatDate(protectionDate)
Line 445:
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj:getConfigTable('protectionLevels')
local action = self._protectionStatusObj_protectionObj:getAction()
local level = self._protectionStatusObj_protectionObj:getLevel()
local msg
if protectionLevels[action][level] then
Line 461:
 
function Blurb:_makeProtectionLogParameter()
local action = self._protectionStatusObj_protectionObj:getAction()
local pagename = self._titleObj.prefixedText
if action == 'autoreview' then
Line 481:
 
function Blurb:_makeResetBlurbParameter()
local protectionDate = self._protectionStatusObj_protectionObj:getProtectionDate()
if protectionDate then
return self:_getExpandedMessage('reset-blurb-protectiondate')
Line 502:
 
function Blurb:_makeTooltipBlurbParameter()
local expiry = self._protectionStatusObj_protectionObj:getExpiry()
if type(expiry) == 'number' then
return self:_getExpandedMessage('tooltip-blurb-expiry')
Line 566:
end
 
function BannerTemplate:setImageFilename(filename, protectionStatusObjprotectionObj, titleObj)
if filename then
self._imageFilename = filename
Line 572:
end
 
local action = protectionStatusObjprotectionObj:getAction()
local level = protectionStatusObjprotectionObj:getAction()
local expiry = protectionStatusObjprotectionObj:getExpiry()
local namespace = titleObj.namespace
Line 707:
local Category = class('Category')
 
function Category:initialize(configObj, protectionStatusObjprotectionObj)
self._configObj = configObj
self._protectionObj = protectionObj
self._protectionStatusObj = protectionStatusObj
end
 
Line 732:
local ProtectionCategory = Category:subclass('ProtectionCategory')
 
function ProtectionCategory:initialize(configObj, protectionStatusObjprotectionObj, titleObj)
Category.initialize(self, configObj, protectionStatusObjprotectionObj)
self._titleObj = titleObj
end
Line 739:
function ProtectionCategory:render()
local configObj = self._configObj
local protectionStatusObjprotectionObj = self._protectionStatusObj_protectionObj
local titleObj = self._titleObj
-- Get the level and exit if the page is not protected.
if not protectionStatusObjprotectionObj:isProtected() then
return ''
end
-- Get the expiry.
local expiry = protectionStatusObjprotectionObj:getExpiry()
if type(expiry) == 'number' then
expiry = 'temp'
Line 767:
 
-- Get the other inputs.
local reason = protectionStatusObjprotectionObj:getReason()
local action = protectionStatusObjprotectionObj:getAction()
local level = protectionStatusObjprotectionObj:getLevel()
--[[
Line 901:
function ExpiryCategory:render()
local configObj = self._configObj
local protectionStatusObjprotectionObj = self._protectionStatusObj_protectionObj
local reasonsWithoutExpiryCheck = configObj:getConfigTable('reasonsWithoutExpiryCheck')
local expiryCheckActions = configObj:getConfigTable('expiryCheckActions')
local expiry = protectionStatusObjprotectionObj:getExpiry()
local action = protectionStatusObjprotectionObj:getAction()
local reason = protectionStatusObjprotectionObj:getReason()
if not expiry
Line 927:
function ErrorCategory:render()
local configObj = self._configObj
local protectionStatusObjprotectionObj = self._protectionStatusObj_protectionObj
local expiry = protectionStatusObjprotectionObj:getExpiry()
local action = protectionStatusObjprotectionObj:getAction()
local level = protectionStatusObjprotectionObj:getLevel()
 
if not protectionStatusObjprotectionObj:isProtected()
or type(expiry) == 'number' and expiry < os.time()
then
Line 947:
local TemplateCategory = Category:subclass('TemplateCategory')
 
function TemplateCategory:initialize(configObj, protectionStatusObjprotectionObj, titleObj)
Category.initialize(self, configObj, protectionStatusObjprotectionObj)
self._titleObj = titleObj
end
Line 954:
function TemplateCategory:render()
local configObj = self._configObj
local protectionStatusObjprotectionObj = self._protectionStatusObj_protectionObj
local titleObj = self._titleObj
local action = protectionStatusObjprotectionObj:getAction()
local level = protectionStatusObjprotectionObj:getLevel()
local namespace = titleObj.namespace
Line 989:
-- Get data objects
local configObj = Config:new()
local protectionObj = ProtectionStatusProtection:new(args, configObj, titleObj)
 
-- Initialise the blurb object
Line 1,050:
-- This is used to export the classes for testing purposes.
return {
Protection = Protection,
ProtectionStatus = ProtectionStatus,
Config = Config,
Blurb = Blurb,