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