Zum Inhalt springen

Modul:Protection banner: Unterschied zwischen den Versionen

config isn't an object anymore
(simplify further)
(config isn't an object anymore)
Zeile 67: Zeile 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


Zeile 98: Zeile 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
Zeile 122: Zeile 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
Zeile 146: Zeile 146:


function Protection:makeProtectionCategory()
function Protection:makeProtectionCategory()
local configObj = self._configObj
local cfg = self._cfg
local titleObj = self._titleObj
local titleObj = self._titleObj
Zeile 166: Zeile 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
Zeile 201: Zeile 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
Zeile 270: Zeile 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
Zeile 299: Zeile 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
Zeile 308: Zeile 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)
Zeile 314: Zeile 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)
Zeile 325: Zeile 325:


function Protection:makeTemplateCategory()
function Protection:makeTemplateCategory()
local configObj = self._configObj
local cfg = self._cfg
local titleObj = self._titleObj
local titleObj = self._titleObj
Zeile 335: Zeile 335:
)
)
then
then
cat = configObj.msg['tracking-category-template']
cat = cfg.msg['tracking-category-template']
end
end
return makeCategoryLink(cat)
return makeCategoryLink(cat)
Zeile 346: Zeile 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
Zeile 378: Zeile 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
Zeile 553: Zeile 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
Zeile 586: Zeile 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')
Zeile 592: Zeile 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
Zeile 618: Zeile 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
Zeile 738: Zeile 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


Zeile 761: Zeile 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
Zeile 790: Zeile 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)
Zeile 806: Zeile 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
Zeile 849: Zeile 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
Zeile 882: Zeile 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)
Zeile 907: Zeile 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


Anonymer Benutzer