Module:Protection banner: Difference between revisions
try to merge the edit conflict, one variable at a time, starting with action
((edit conflict) replace Protection getter functions with public attributes) |
(try to merge the edit conflict, one variable at a time, starting with action) |
||
Line 10: | Line 10: | ||
-- Lazily initialise modules and objects we don't always need. | -- Lazily initialise modules and objects we don't always need. | ||
local mArguments, mMessageBox, lang | local mArguments, mMessageBox, lang, config | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Line 116: | Line 47: | ||
level = '*' | level = '*' | ||
end | end | ||
self. | self._level = level or '*' | ||
end | end | ||
Line 137: | Line 68: | ||
-- Set expiry | -- Set expiry | ||
if args.expiry then | if args.expiry then | ||
local indefStrings = configObj | local indefStrings = configObj.cfg.indefStrings | ||
if indefStrings[args.expiry] then | if indefStrings[args.expiry] then | ||
self. | self._expiry = 'indef' | ||
elseif type(args.expiry) == 'number' then | elseif type(args.expiry) == 'number' then | ||
self. | self._expiry = args.expiry | ||
else | else | ||
self. | self._expiry = validateDate(args.expiry, 'expiry date') | ||
end | end | ||
end | end | ||
Line 151: | Line 82: | ||
local reason = args.reason or args[1] | local reason = args.reason or args[1] | ||
if reason then | if reason then | ||
self. | self._reason = reason:lower() | ||
end | end | ||
end | end | ||
-- Set protection date | -- Set protection date | ||
self. | self._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 | |||
end | |||
end | end | ||
Line 172: | Line 134: | ||
self._configObj = configObj | self._configObj = configObj | ||
self._protectionObj = protectionObj | self._protectionObj = protectionObj | ||
self._bannerConfig = | self._bannerConfig = protectionObj.bannerConfig | ||
self._titleObj = titleObj | self._titleObj = titleObj | ||
end | end | ||
Line 201: | Line 163: | ||
function Blurb:_getExpandedMessage(msg) | function Blurb:_getExpandedMessage(msg) | ||
local msg = self._configObj | local msg = self._configObj.msg[msg] | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
end | end | ||
Line 278: | Line 240: | ||
function Blurb:_makeDisputeBlurbParameter() | function Blurb:_makeDisputeBlurbParameter() | ||
local expiry = self._protectionObj | 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 306: | Line 268: | ||
local mEditRequest = require('Module:Submit an edit request') | local mEditRequest = require('Module:Submit an edit request') | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj | local level = self._protectionObj:getLevel() | ||
-- Get the display message key. | -- Get the display message key. | ||
Line 332: | Line 294: | ||
function Blurb:_makeExpiryParameter() | function Blurb:_makeExpiryParameter() | ||
local expiry = self._protectionObj | local expiry = self._protectionObj:getExpiry() | ||
if expiry == 'indef' then | if expiry == 'indef' then | ||
return nil | return nil | ||
Line 345: | Line 307: | ||
function Blurb:_makeExplanationBlurbParameter() | function Blurb:_makeExplanationBlurbParameter() | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj | 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 376: | Line 338: | ||
function Blurb:_makeImageLinkParameter() | function Blurb:_makeImageLinkParameter() | ||
local imageLinks = self._configObj | local imageLinks = self._configObj.cfg.imageLinks | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj | local level = self._protectionObj:getLevel() | ||
local msg | local msg | ||
if imageLinks[action][level] then | if imageLinks[action][level] then | ||
Line 391: | Line 353: | ||
function Blurb:_makeIntroBlurbParameter() | function Blurb:_makeIntroBlurbParameter() | ||
local expiry = self._protectionObj | 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 400: | Line 362: | ||
function Blurb:_makeOfficeBlurbParameter() | function Blurb:_makeOfficeBlurbParameter() | ||
local protectionDate = self._protectionObj | local protectionDate = self._protectionObj:getProtectionDate() | ||
if protectionDate then | if protectionDate then | ||
return self:_getExpandedMessage('office-blurb-protectiondate') | return self:_getExpandedMessage('office-blurb-protectiondate') | ||
Line 409: | Line 371: | ||
function Blurb:_makePagetypeParameter() | function Blurb:_makePagetypeParameter() | ||
local pagetypes = self._configObj | local pagetypes = self._configObj.cfg.pagetypes | ||
local namespace = self._titleObj.namespace | local namespace = self._titleObj.namespace | ||
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined') | return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined') | ||
Line 415: | Line 377: | ||
function Blurb:_makeProtectionBlurbParameter() | function Blurb:_makeProtectionBlurbParameter() | ||
local protectionBlurbs = self._configObj | local protectionBlurbs = self._configObj.cfg.protectionBlurbs | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj | local level = self._protectionObj:getLevel() | ||
local msg | local msg | ||
if protectionBlurbs[action][level] then | if protectionBlurbs[action][level] then | ||
Line 432: | Line 394: | ||
function Blurb:_makeProtectionDateParameter() | function Blurb:_makeProtectionDateParameter() | ||
local protectionDate = self._protectionObj | local protectionDate = self._protectionObj:getProtectionDate() | ||
if type(protectionDate) == 'number' then | if type(protectionDate) == 'number' then | ||
return Blurb.formatDate(protectionDate) | return Blurb.formatDate(protectionDate) | ||
Line 441: | Line 403: | ||
function Blurb:_makeProtectionLevelParameter() | function Blurb:_makeProtectionLevelParameter() | ||
local protectionLevels = self._configObj | local protectionLevels = self._configObj.cfg.protectionLevels | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj | local level = self._protectionObj:getLevel() | ||
local msg | local msg | ||
if protectionLevels[action][level] then | if protectionLevels[action][level] then | ||
Line 478: | Line 440: | ||
function Blurb:_makeResetBlurbParameter() | function Blurb:_makeResetBlurbParameter() | ||
local protectionDate = self._protectionObj | local protectionDate = self._protectionObj:getProtectionDate() | ||
if protectionDate then | if protectionDate then | ||
return self:_getExpandedMessage('reset-blurb-protectiondate') | return self:_getExpandedMessage('reset-blurb-protectiondate') | ||
Line 499: | Line 461: | ||
function Blurb:_makeTooltipBlurbParameter() | function Blurb:_makeTooltipBlurbParameter() | ||
local expiry = self._protectionObj | 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 572: | Line 534: | ||
local action = protectionObj.action | local action = protectionObj.action | ||
local level = protectionObj | local level = protectionObj:getLevel() | ||
local expiry = protectionObj | local expiry = protectionObj:getExpiry() | ||
local namespace = titleObj.namespace | local namespace = titleObj.namespace | ||
Line 584: | Line 546: | ||
-- Fully protected modules and templates get the special red "indef" | -- Fully protected modules and templates get the special red "indef" | ||
-- padlock. | -- padlock. | ||
self._imageFilename = self._configObj | self._imageFilename = self._configObj.msg['image-filename-indef'] | ||
return nil | return nil | ||
end | end | ||
-- Deal with regular protection types. | -- Deal with regular protection types. | ||
local images = self._configObj | local images = self._configObj.cfg.images | ||
if images[action] then | if images[action] then | ||
if images[action][level] then | if images[action][level] then | ||
Line 613: | Line 575: | ||
function BannerTemplate:renderImage() | function BannerTemplate:renderImage() | ||
local filename = self._imageFilename | local filename = self._imageFilename | ||
or self._configObj | or self._configObj.msg['image-filename-default'] | ||
or 'Transparent.gif' | or 'Transparent.gif' | ||
return newFileLink(filename) | return newFileLink(filename) | ||
Line 747: | Line 709: | ||
-- Get the expiry. | -- Get the expiry. | ||
local expiry = protectionObj | local expiry = protectionObj:getExpiry() | ||
if type(expiry) == 'number' then | if type(expiry) == 'number' then | ||
expiry = 'temp' | expiry = 'temp' | ||
Line 758: | Line 720: | ||
do | do | ||
local namespace = titleObj.namespace | local namespace = titleObj.namespace | ||
local categoryNamespaces = configObj | local categoryNamespaces = configObj.cfg.categoryNamespaceKeys | ||
nskey = categoryNamespaces[namespace] | nskey = categoryNamespaces[namespace] | ||
if not nskey and namespace % 2 == 1 then | if not nskey and namespace % 2 == 1 then | ||
Line 766: | Line 728: | ||
-- Get the other inputs. | -- Get the other inputs. | ||
local reason = protectionObj | local reason = protectionObj:getReason() | ||
local action = protectionObj.action | local action = protectionObj.action | ||
local level = protectionObj | local level = protectionObj:getLevel() | ||
--[[ | --[[ | ||
Line 793: | Line 755: | ||
local configOrder = {} | local configOrder = {} | ||
do | do | ||
local reasonsWithNamespacePriority = configObj | local reasonsWithNamespacePriority = configObj.cfg.reasonsWithNamespacePriority | ||
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false | local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false | ||
for propertiesKey, t in pairs(properties) do | for propertiesKey, t in pairs(properties) do | ||
Line 862: | Line 824: | ||
-- pos field in the property table. | -- pos field in the property table. | ||
--]] | --]] | ||
local cats = configObj | local cats = configObj.cfg.protectionCategories | ||
local cat | local cat | ||
for i = 1, 2^noActive do | for i = 1, 2^noActive do | ||
Line 899: | Line 861: | ||
function ExpiryCategory:render() | function ExpiryCategory:render() | ||
local | local configObj = self._configObj | ||
local expiryCheckActions = | local protectionObj = self._protectionObj | ||
local expiry = | |||
local action = | local reasonsWithoutExpiryCheck = configObj.cfg.reasonsWithoutExpiryCheck | ||
local reason = | local expiryCheckActions = configObj.cfg.expiryCheckActions | ||
local expiry = protectionObj:getExpiry() | |||
local action = protectionObj.action | |||
local reason = protectionObj:getReason() | |||
if not expiry | if not expiry | ||
Line 910: | Line 875: | ||
and not reasonsWithoutExpiryCheck[reason] | and not reasonsWithoutExpiryCheck[reason] | ||
then | then | ||
self:setName(configObj | self:setName(configObj.msg['tracking-category-expiry']) | ||
end | end | ||
return Category.render(self) | return Category.render(self) | ||
Line 924: | Line 889: | ||
local configObj = self._configObj | local configObj = self._configObj | ||
local protectionObj = self._protectionObj | local protectionObj = self._protectionObj | ||
local expiry = protectionObj | |||
local expiry = protectionObj:getExpiry() | |||
local action = protectionObj.action | local action = protectionObj.action | ||
local level = protectionObj | local level = protectionObj:getLevel() | ||
if not protectionObj:isProtected() | if not protectionObj:isProtected() | ||
or type(expiry) == 'number' and expiry < os.time() | or type(expiry) == 'number' and expiry < os.time() | ||
then | then | ||
self:setName(configObj | self:setName(configObj.msg['tracking-category-incorrect']) | ||
end | end | ||
return Category.render(self) | return Category.render(self) | ||
Line 949: | Line 915: | ||
function TemplateCategory:render() | function TemplateCategory:render() | ||
local configObj = self._configObj | local configObj = self._configObj | ||
local | local protectionObj = self._protectionObj | ||
local | local titleObj = self._titleObj | ||
local namespace = | |||
local action = protectionObj.action | |||
local level = protectionObj:getLevel() | |||
local namespace = titleObj.namespace | |||
if level == 'templateeditor' | if level == 'templateeditor' | ||
Line 959: | Line 928: | ||
) | ) | ||
then | then | ||
self:setName(configObj | self:setName(configObj.msg['tracking-category-template']) | ||
end | end | ||
return Category.render(self) | return Category.render(self) | ||
Line 980: | Line 949: | ||
-- Get data objects | -- Get data objects | ||
local configObj = | if not config then | ||
config = mw.loadData('Module:Protection banner/config') | |||
end | |||
local configObj = config | |||
local protectionObj = Protection:new(args, configObj, titleObj) | local protectionObj = Protection:new(args, configObj, titleObj) | ||
Line 1,003: | Line 975: | ||
-- Set the image fields | -- Set the image fields | ||
local bannerConfig = | local bannerConfig = protectionObj.bannerConfig | ||
bannerObj:setImageFilename(bannerConfig.image, protectionObj, titleObj) | bannerObj:setImageFilename(bannerConfig.image, protectionObj, titleObj) | ||
if isPadlock then | if isPadlock then | ||
Line 1,043: | Line 1,015: | ||
return { | return { | ||
Protection = Protection, | Protection = Protection, | ||
Blurb = Blurb, | Blurb = Blurb, | ||
BannerTemplate = BannerTemplate, | BannerTemplate = BannerTemplate, |