Open main menu

Changes

Module:Protection banner

306 bytes removed, 17:53, 28 June 2014
config isn't an object anymore
}
function Protection:initialize(args, configObjcfg, titleObj) self._configObj _cfg = configObjcfg
self._titleObj = titleObj
-- Set expiry
if args.expiry then
if configObjcfg.indefStrings[args.expiry] then
self.expiry = 'indef'
elseif type(args.expiry) == 'number' then
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
function Protection:makeProtectionCategory()
local configObj cfg = self._configObj_cfg
local titleObj = self._titleObj
do
local namespace = titleObj.namespace
local categoryNamespaces = configObjcfg.categoryNamespaceKeys
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
local configOrder = {}
do
local reasonsWithNamespacePriority = configObjcfg.reasonsWithNamespacePriority
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
-- pos field in the property table.
--]]
local cats = configObjcfg.protectionCategories
local cat
for i = 1, 2^noActive do
function Protection:makeExpiryCategory()
local reasonsWithoutExpiryCheck = self._configObj_cfg.reasonsWithoutExpiryCheck local expiryCheckActions = self._configObj_cfg.expiryCheckActions
local cat
and not reasonsWithoutExpiryCheck[self.reason]
then
cat = self._configObj_cfg.msg['tracking-category-expiry']
end
return makeCategoryLink(cat)
function Protection:makeErrorCategory()
local configObj cfg = 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)
function Protection:makeTemplateCategory()
local configObj cfg = self._configObj_cfg
local titleObj = self._titleObj
)
then
cat = configObjcfg.msg['tracking-category-template']
end
return makeCategoryLink(cat)
local Blurb = class('Blurb')
function Blurb:initialize(configObjcfg, protectionObj, titleObj) self._configObj _cfg = configObjcfg
self._protectionObj = protectionObj
self._bannerConfig = protectionObj.bannerConfig
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj_cfg.msg[msg]
return self:_substituteParameters(msg)
end
function Blurb:_makeImageLinkParameter()
local imageLinks = self._configObj_cfg.imageLinks
local action = self._protectionObj.action
local level = self._protectionObj.level
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')
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj_cfg.protectionBlurbs
local action = self._protectionObj.action
local level = self._protectionObj.level
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj_cfg.protectionLevels
local action = self._protectionObj.action
local level = self._protectionObj.level
local BannerTemplate = class('BannerTemplate')
function BannerTemplate:initialize(configObjcfg) self._configObj _cfg = configObjcfg
end
-- 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
function BannerTemplate:renderImage()
local filename = self._imageFilename
or self._configObj_cfg.msg['image-filename-default']
or 'Transparent.gif'
return newFileLink(filename)
local Banner = BannerTemplate:subclass('Banner')
function Banner:initialize(configObjcfg) BannerTemplate.initialize(self, configObjcfg)
self:setImageWidth(40)
end
local Padlock = BannerTemplate:subclass('Padlock')
function Padlock:initialize(configObjcfg) BannerTemplate.initialize(self, configObjcfg)
self:setImageWidth(20)
end
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) configObj cfg = configObj cfg 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)
local bannerObj
if isPadlock then
bannerObj = Padlock:new(configObjcfg)
else
bannerObj = Banner:new(configObjcfg)
end
Anonymous user