Module:Protection banner: Difference between revisions

config isn't an object anymore
Enwikipedia>Jackmcbarn
(simplify further)
Enwikipedia>Jackmcbarn
(config isn't an object anymore)
Line 67:
}
 
function Protection:initialize(args, configObjcfg, titleObj)
self._configObj_cfg = configObjcfg
self._titleObj = titleObj
 
Line 98:
-- Set expiry
if args.expiry then
if configObjcfg.indefStrings[args.expiry] then
self.expiry = 'indef'
elseif type(args.expiry) == 'number' then
Line 122:
self.bannerConfig = {}
local configTables = {}
if configObjcfg.banners[self.action] then
configTables[#configTables + 1] = configObjcfg.banners[self.action][self.reason]
end
if configObjcfg.defaultBanners[self.action] then
configTables[#configTables + 1] = configObjcfg.defaultBanners[self.action][self.level]
configTables[#configTables + 1] = configObjcfg.defaultBanners[self.action].default
end
configTables[#configTables + 1] = configObjcfg.masterBanner
for i, field in ipairs(self.bannerConfigFields) do
for j, t in ipairs(configTables) do
Line 146:
 
function Protection:makeProtectionCategory()
local configObjcfg = self._configObj_cfg
local titleObj = self._titleObj
Line 166:
do
local namespace = titleObj.namespace
local categoryNamespaces = configObjcfg.categoryNamespaceKeys
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
Line 201:
local configOrder = {}
do
local reasonsWithNamespacePriority = configObjcfg.reasonsWithNamespacePriority
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
Line 270:
-- pos field in the property table.
--]]
local cats = configObjcfg.protectionCategories
local cat
for i = 1, 2^noActive do
Line 299:
 
function Protection:makeExpiryCategory()
local reasonsWithoutExpiryCheck = self._configObj_cfg.reasonsWithoutExpiryCheck
local expiryCheckActions = self._configObj_cfg.expiryCheckActions
local cat
Line 308:
and not reasonsWithoutExpiryCheck[self.reason]
then
cat = self._configObj_cfg.msg['tracking-category-expiry']
end
return makeCategoryLink(cat)
Line 314:
 
function Protection:makeErrorCategory()
local configObjcfg = self._configObj_cfg
local cat
if not self:isProtected()
or type(self.expiry) == 'number' and self.expiry < os.time()
then
cat = configObjcfg.msg['tracking-category-incorrect']
end
return makeCategoryLink(cat)
Line 325:
 
function Protection:makeTemplateCategory()
local configObjcfg = self._configObj_cfg
local titleObj = self._titleObj
Line 335:
)
then
cat = configObjcfg.msg['tracking-category-template']
end
return makeCategoryLink(cat)
Line 346:
local Blurb = class('Blurb')
 
function Blurb:initialize(configObjcfg, protectionObj, titleObj)
self._configObj_cfg = configObjcfg
self._protectionObj = protectionObj
self._bannerConfig = protectionObj.bannerConfig
Line 378:
 
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj_cfg.msg[msg]
return self:_substituteParameters(msg)
end
Line 553:
 
function Blurb:_makeImageLinkParameter()
local imageLinks = self._configObj_cfg.imageLinks
local action = self._protectionObj.action
local level = self._protectionObj.level
Line 586:
 
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj_cfg.pagetypes
local namespace = self._titleObj.namespace
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined')
Line 592:
 
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj_cfg.protectionBlurbs
local action = self._protectionObj.action
local level = self._protectionObj.level
Line 618:
 
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj_cfg.protectionLevels
local action = self._protectionObj.action
local level = self._protectionObj.level
Line 738:
local BannerTemplate = class('BannerTemplate')
 
function BannerTemplate:initialize(configObjcfg)
self._configObj_cfg = configObjcfg
end
 
Line 761:
-- Fully protected modules and templates get the special red "indef"
-- padlock.
self._imageFilename = self._configObj_cfg.msg['image-filename-indef']
return nil
end
 
-- Deal with regular protection types.
local images = self._configObj_cfg.images
if images[action] then
if images[action][level] then
Line 790:
function BannerTemplate:renderImage()
local filename = self._imageFilename
or self._configObj_cfg.msg['image-filename-default']
or 'Transparent.gif'
return newFileLink(filename)
Line 806:
local Banner = BannerTemplate:subclass('Banner')
 
function Banner:initialize(configObjcfg)
BannerTemplate.initialize(self, configObjcfg)
self:setImageWidth(40)
end
Line 849:
local Padlock = BannerTemplate:subclass('Padlock')
 
function Padlock:initialize(configObjcfg)
BannerTemplate.initialize(self, configObjcfg)
self:setImageWidth(20)
end
Line 882:
local ProtectionBanner = {}
 
function ProtectionBanner.exportToWiki(frame, configObjcfg, titleObj)
mArguments = mArguments or require('Module:Arguments')
local args = mArguments.getArgs(frame)
return ProtectionBanner.exportToLua(args, configObjcfg, titleObj)
end
 
function ProtectionBanner.exportToLua(args, configObjcfg, titleObj)
configObjcfg = configObjcfg or mw.loadData('Module:Protection banner/config')
titleObj = titleObj or mw.title.getCurrentTitle()
 
-- Initialise protection and blurb objects
local protectionObj = Protection:new(args, configObjcfg, titleObj)
local blurbObj = Blurb:new(configObjcfg, protectionObj, titleObj)
blurbObj:setDeletionDiscussionPage(args.xfd)
blurbObj:setUsername(args.user)
Line 907:
local bannerObj
if isPadlock then
bannerObj = Padlock:new(configObjcfg)
else
bannerObj = Banner:new(configObjcfg)
end