Anonymous user
Module:Protection banner: Difference between revisions
(edit conflict) replace Protection getter functions with public attributes
Enwikipedia>Jackmcbarn (get rid of the config class while still allowing replacing it for testing) |
Enwikipedia>Mr. Stradivarius ((edit conflict) replace Protection getter functions with public attributes) |
||
Line 10:
-- 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, field 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
end
end
function Config:getConfigTable(key)
local blacklist = {
banners = true,
defaultBanners = true,
masterBanner = true
}
if not blacklist[key] then
return self._cfg[key]
else
return nil
end
end
function Config:getMessage(key)
return self._msg[key]
end
--------------------------------------------------------------------------------
Line 28 ⟶ 97:
}
if args.action and actions[args.action] then
self.
else
self.
end
end
Line 36 ⟶ 105:
-- Set level
do
local level = effectiveProtectionLevel(self.
if level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
Line 42 ⟶ 111:
level = 'templateeditor'
end
if self.
-- Users need to be autoconfirmed to move pages anyway, so treat
-- semi-move-protected pages as unprotected.
level = '*'
end
self.
end
Line 68 ⟶ 137:
-- Set expiry
if args.expiry then
local indefStrings = configObj
if indefStrings[args.expiry] then
self.
elseif type(args.expiry) == 'number' then
self.
else
self.
end
end
Line 82 ⟶ 151:
local reason = args.reason or args[1]
if reason then
self.
end
end
-- Set protection date
self.
end
function Protection:isProtected()
return self._level ~= '*'
end
Line 154 ⟶ 172:
self._configObj = configObj
self._protectionObj = protectionObj
self._bannerConfig = configObj:getBannerConfig(protectionObj
self._titleObj = titleObj
end
Line 183 ⟶ 201:
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj
return self:_substituteParameters(msg)
end
Line 232 ⟶ 250:
-- A link to the page history or the move log, depending on the kind of
-- protection.
local action = self._protectionObj
local pagename = self._titleObj.prefixedText
if action == 'move' then
Line 260 ⟶ 278:
function Blurb:_makeDisputeBlurbParameter()
local expiry = self._protectionObj
if type(expiry) == 'number' then
return self:_getExpandedMessage('dispute-blurb-expiry')
Line 287 ⟶ 305:
function Blurb:_makeEditRequestParameter()
local mEditRequest = require('Module:Submit an edit request')
local action = self._protectionObj
local level = self._protectionObj
-- Get the display message key.
Line 314 ⟶ 332:
function Blurb:_makeExpiryParameter()
local expiry = self._protectionObj
if expiry == 'indef' then
return nil
Line 326 ⟶ 344:
function Blurb:_makeExplanationBlurbParameter()
local action = self._protectionObj
local level = self._protectionObj
local namespace = self._titleObj.namespace
local isTalk = self._titleObj.isTalkPage
Line 358 ⟶ 376:
function Blurb:_makeImageLinkParameter()
local imageLinks = self._configObj
local action = self._protectionObj
local level = self._protectionObj
local msg
if imageLinks[action][level] then
Line 373 ⟶ 391:
function Blurb:_makeIntroBlurbParameter()
local expiry = self._protectionObj
if type(expiry) == 'number' then
return self:_getExpandedMessage('intro-blurb-expiry')
Line 382 ⟶ 400:
function Blurb:_makeOfficeBlurbParameter()
local protectionDate = self._protectionObj
if protectionDate then
return self:_getExpandedMessage('office-blurb-protectiondate')
Line 391 ⟶ 409:
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj
local namespace = self._titleObj.namespace
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined')
Line 397 ⟶ 415:
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj
local action = self._protectionObj
local level = self._protectionObj
local msg
if protectionBlurbs[action][level] then
Line 414 ⟶ 432:
function Blurb:_makeProtectionDateParameter()
local protectionDate = self._protectionObj
if type(protectionDate) == 'number' then
return Blurb.formatDate(protectionDate)
Line 423 ⟶ 441:
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj
local action = self._protectionObj
local level = self._protectionObj
local msg
if protectionLevels[action][level] then
Line 440 ⟶ 458:
function Blurb:_makeProtectionLogParameter()
local action = self._protectionObj
local pagename = self._titleObj.prefixedText
if action == 'autoreview' then
Line 460 ⟶ 478:
function Blurb:_makeResetBlurbParameter()
local protectionDate = self._protectionObj
if protectionDate then
return self:_getExpandedMessage('reset-blurb-protectiondate')
Line 481 ⟶ 499:
function Blurb:_makeTooltipBlurbParameter()
local expiry = self._protectionObj
if type(expiry) == 'number' then
return self:_getExpandedMessage('tooltip-blurb-expiry')
Line 553 ⟶ 571:
end
local action = protectionObj
local level = protectionObj
local expiry = protectionObj
local namespace = titleObj.namespace
Line 566 ⟶ 584:
-- Fully protected modules and templates get the special red "indef"
-- padlock.
self._imageFilename = self._configObj
return nil
end
-- Deal with regular protection types.
local images = self._configObj
if images[action] then
if images[action][level] then
Line 595 ⟶ 613:
function BannerTemplate:renderImage()
local filename = self._imageFilename
or self._configObj
or 'Transparent.gif'
return newFileLink(filename)
Line 729 ⟶ 747:
-- Get the expiry.
local expiry = protectionObj
if type(expiry) == 'number' then
expiry = 'temp'
Line 740 ⟶ 758:
do
local namespace = titleObj.namespace
local categoryNamespaces = configObj
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
Line 748 ⟶ 766:
-- Get the other inputs.
local reason = protectionObj
local action = protectionObj
local level = protectionObj
--[[
Line 775 ⟶ 793:
local configOrder = {}
do
local reasonsWithNamespacePriority = configObj
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
Line 844 ⟶ 862:
-- pos field in the property table.
--]]
local cats = configObj
local cat
for i = 1, 2^noActive do
Line 881 ⟶ 899:
function ExpiryCategory:render()
local
local expiryCheckActions = self._configObj:getConfigTable('expiryCheckActions')
local expiry = self._protectionObj.expiry
local action = self._protectionObj.action
local reason = self._protectionObj.reason
if not expiry
Line 895 ⟶ 910:
and not reasonsWithoutExpiryCheck[reason]
then
self:setName(configObj
end
return Category.render(self)
Line 909 ⟶ 924:
local configObj = self._configObj
local protectionObj = self._protectionObj
local expiry = protectionObj.expiry
local
local
if not protectionObj:isProtected()
or type(expiry) == 'number' and expiry < os.time()
then
self:setName(configObj
end
return Category.render(self)
Line 935 ⟶ 949:
function TemplateCategory:render()
local configObj = self._configObj
local
local
local namespace = self._titleObj.namespace
if level == 'templateeditor'
Line 948 ⟶ 959:
)
then
self:setName(configObj
end
return Category.render(self)
Line 969 ⟶ 980:
-- Get data objects
local configObj = Config:new()
local protectionObj = Protection:new(args, configObj, titleObj)
Line 995 ⟶ 1,003:
-- Set the image fields
local bannerConfig = configObj:getBannerConfig(protectionObj
bannerObj:setImageFilename(bannerConfig.image, protectionObj, titleObj)
if isPadlock then
Line 1,035 ⟶ 1,043:
return {
Protection = Protection,
Config = Config,
Blurb = Blurb,
BannerTemplate = BannerTemplate,
|