Module:Protection banner: Difference between revisions

config isn't an object anymore
(simplify further)
(config isn't an object anymore)
Line 67: Line 67:
}
}


function Protection:initialize(args, configObj, titleObj)
function Protection:initialize(args, cfg, titleObj)
self._configObj = configObj
self._cfg = cfg
self._titleObj = titleObj
self._titleObj = titleObj


Line 98: Line 98:
-- Set expiry
-- Set expiry
if args.expiry then
if args.expiry then
if configObj.indefStrings[args.expiry] then
if cfg.indefStrings[args.expiry] then
self.expiry = 'indef'
self.expiry = 'indef'
elseif type(args.expiry) == 'number' then
elseif type(args.expiry) == 'number' then
Line 122: Line 122:
self.bannerConfig = {}
self.bannerConfig = {}
local configTables = {}
local configTables = {}
if configObj.banners[self.action] then
if cfg.banners[self.action] then
configTables[#configTables + 1] = configObj.banners[self.action][self.reason]
configTables[#configTables + 1] = cfg.banners[self.action][self.reason]
end
end
if configObj.defaultBanners[self.action] then
if cfg.defaultBanners[self.action] then
configTables[#configTables + 1] = configObj.defaultBanners[self.action][self.level]
configTables[#configTables + 1] = cfg.defaultBanners[self.action][self.level]
configTables[#configTables + 1] = configObj.defaultBanners[self.action].default
configTables[#configTables + 1] = cfg.defaultBanners[self.action].default
end
end
configTables[#configTables + 1] = configObj.masterBanner
configTables[#configTables + 1] = cfg.masterBanner
for i, field in ipairs(self.bannerConfigFields) do
for i, field in ipairs(self.bannerConfigFields) do
for j, t in ipairs(configTables) do
for j, t in ipairs(configTables) do
Line 146: Line 146:


function Protection:makeProtectionCategory()
function Protection:makeProtectionCategory()
local configObj = self._configObj
local cfg = self._cfg
local titleObj = self._titleObj
local titleObj = self._titleObj
Line 166: Line 166:
do
do
local namespace = titleObj.namespace
local namespace = titleObj.namespace
local categoryNamespaces = configObj.categoryNamespaceKeys
local categoryNamespaces = 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 201: Line 201:
local configOrder = {}
local configOrder = {}
do
do
local reasonsWithNamespacePriority = configObj.reasonsWithNamespacePriority
local reasonsWithNamespacePriority = 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 270: Line 270:
-- pos field in the property table.
-- pos field in the property table.
--]]
--]]
local cats = configObj.protectionCategories
local cats = cfg.protectionCategories
local cat
local cat
for i = 1, 2^noActive do
for i = 1, 2^noActive do
Line 299: Line 299:


function Protection:makeExpiryCategory()
function Protection:makeExpiryCategory()
local reasonsWithoutExpiryCheck = self._configObj.reasonsWithoutExpiryCheck
local reasonsWithoutExpiryCheck = self._cfg.reasonsWithoutExpiryCheck
local expiryCheckActions = self._configObj.expiryCheckActions
local expiryCheckActions = self._cfg.expiryCheckActions
local cat
local cat
Line 308: Line 308:
and not reasonsWithoutExpiryCheck[self.reason]
and not reasonsWithoutExpiryCheck[self.reason]
then
then
cat = self._configObj.msg['tracking-category-expiry']
cat = self._cfg.msg['tracking-category-expiry']
end
end
return makeCategoryLink(cat)
return makeCategoryLink(cat)
Line 314: Line 314:


function Protection:makeErrorCategory()
function Protection:makeErrorCategory()
local configObj = self._configObj
local cfg = self._cfg
local cat
local cat
if not self:isProtected()
if not self:isProtected()
or type(self.expiry) == 'number' and self.expiry < os.time()
or type(self.expiry) == 'number' and self.expiry < os.time()
then
then
cat = configObj.msg['tracking-category-incorrect']
cat = cfg.msg['tracking-category-incorrect']
end
end
return makeCategoryLink(cat)
return makeCategoryLink(cat)
Line 325: Line 325:


function Protection:makeTemplateCategory()
function Protection:makeTemplateCategory()
local configObj = self._configObj
local cfg = self._cfg
local titleObj = self._titleObj
local titleObj = self._titleObj
Line 335: Line 335:
)
)
then
then
cat = configObj.msg['tracking-category-template']
cat = cfg.msg['tracking-category-template']
end
end
return makeCategoryLink(cat)
return makeCategoryLink(cat)
Line 346: Line 346:
local Blurb = class('Blurb')
local Blurb = class('Blurb')


function Blurb:initialize(configObj, protectionObj, titleObj)
function Blurb:initialize(cfg, protectionObj, titleObj)
self._configObj = configObj
self._cfg = cfg
self._protectionObj = protectionObj
self._protectionObj = protectionObj
self._bannerConfig = protectionObj.bannerConfig
self._bannerConfig = protectionObj.bannerConfig
Line 378: Line 378:


function Blurb:_getExpandedMessage(msg)
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj.msg[msg]
local msg = self._cfg.msg[msg]
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
end
end
Line 553: Line 553:


function Blurb:_makeImageLinkParameter()
function Blurb:_makeImageLinkParameter()
local imageLinks = self._configObj.imageLinks
local imageLinks = self._cfg.imageLinks
local action = self._protectionObj.action
local action = self._protectionObj.action
local level = self._protectionObj.level
local level = self._protectionObj.level
Line 586: Line 586:


function Blurb:_makePagetypeParameter()
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj.pagetypes
local pagetypes = self._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 592: Line 592:


function Blurb:_makeProtectionBlurbParameter()
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj.protectionBlurbs
local protectionBlurbs = self._cfg.protectionBlurbs
local action = self._protectionObj.action
local action = self._protectionObj.action
local level = self._protectionObj.level
local level = self._protectionObj.level
Line 618: Line 618:


function Blurb:_makeProtectionLevelParameter()
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj.protectionLevels
local protectionLevels = self._cfg.protectionLevels
local action = self._protectionObj.action
local action = self._protectionObj.action
local level = self._protectionObj.level
local level = self._protectionObj.level
Line 738: Line 738:
local BannerTemplate = class('BannerTemplate')
local BannerTemplate = class('BannerTemplate')


function BannerTemplate:initialize(configObj)
function BannerTemplate:initialize(cfg)
self._configObj = configObj
self._cfg = cfg
end
end


Line 761: Line 761:
-- 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.msg['image-filename-indef']
self._imageFilename = self._cfg.msg['image-filename-indef']
return nil
return nil
end
end


-- Deal with regular protection types.
-- Deal with regular protection types.
local images = self._configObj.images
local images = self._cfg.images
if images[action] then
if images[action] then
if images[action][level] then
if images[action][level] then
Line 790: Line 790:
function BannerTemplate:renderImage()
function BannerTemplate:renderImage()
local filename = self._imageFilename
local filename = self._imageFilename
or self._configObj.msg['image-filename-default']
or self._cfg.msg['image-filename-default']
or 'Transparent.gif'
or 'Transparent.gif'
return newFileLink(filename)
return newFileLink(filename)
Line 806: Line 806:
local Banner = BannerTemplate:subclass('Banner')
local Banner = BannerTemplate:subclass('Banner')


function Banner:initialize(configObj)
function Banner:initialize(cfg)
BannerTemplate.initialize(self, configObj)
BannerTemplate.initialize(self, cfg)
self:setImageWidth(40)
self:setImageWidth(40)
end
end
Line 849: Line 849:
local Padlock = BannerTemplate:subclass('Padlock')
local Padlock = BannerTemplate:subclass('Padlock')


function Padlock:initialize(configObj)
function Padlock:initialize(cfg)
BannerTemplate.initialize(self, configObj)
BannerTemplate.initialize(self, cfg)
self:setImageWidth(20)
self:setImageWidth(20)
end
end
Line 882: Line 882:
local ProtectionBanner = {}
local ProtectionBanner = {}


function ProtectionBanner.exportToWiki(frame, configObj, titleObj)
function ProtectionBanner.exportToWiki(frame, cfg, titleObj)
mArguments = mArguments or require('Module:Arguments')
mArguments = mArguments or require('Module:Arguments')
local args = mArguments.getArgs(frame)
local args = mArguments.getArgs(frame)
return ProtectionBanner.exportToLua(args, configObj, titleObj)
return ProtectionBanner.exportToLua(args, cfg, titleObj)
end
end


function ProtectionBanner.exportToLua(args, configObj, titleObj)
function ProtectionBanner.exportToLua(args, cfg, titleObj)
configObj = configObj or mw.loadData('Module:Protection banner/config')
cfg = cfg or mw.loadData('Module:Protection banner/config')
titleObj = titleObj or mw.title.getCurrentTitle()
titleObj = titleObj or mw.title.getCurrentTitle()


-- Initialise protection and blurb objects
-- Initialise protection and blurb objects
local protectionObj = Protection:new(args, configObj, titleObj)
local protectionObj = Protection:new(args, cfg, titleObj)
local blurbObj = Blurb:new(configObj, protectionObj, titleObj)
local blurbObj = Blurb:new(cfg, protectionObj, titleObj)
blurbObj:setDeletionDiscussionPage(args.xfd)
blurbObj:setDeletionDiscussionPage(args.xfd)
blurbObj:setUsername(args.user)
blurbObj:setUsername(args.user)
Line 907: Line 907:
local bannerObj
local bannerObj
if isPadlock then
if isPadlock then
bannerObj = Padlock:new(configObj)
bannerObj = Padlock:new(cfg)
else
else
bannerObj = Banner:new(configObj)
bannerObj = Banner:new(cfg)
end
end


Anonymous user