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, | function Protection:initialize(args, cfg, titleObj) | ||
self. | 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 | 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 | if cfg.banners[self.action] then | ||
configTables[#configTables + 1] = | configTables[#configTables + 1] = cfg.banners[self.action][self.reason] | ||
end | end | ||
if | if cfg.defaultBanners[self.action] then | ||
configTables[#configTables + 1] = | configTables[#configTables + 1] = cfg.defaultBanners[self.action][self.level] | ||
configTables[#configTables + 1] = | configTables[#configTables + 1] = cfg.defaultBanners[self.action].default | ||
end | end | ||
configTables[#configTables + 1] = | 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 | 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 = | 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 = | 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 = | 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. | local reasonsWithoutExpiryCheck = self._cfg.reasonsWithoutExpiryCheck | ||
local expiryCheckActions = self. | 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. | 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 | 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 = | 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 | local cfg = self._cfg | ||
local titleObj = self._titleObj | local titleObj = self._titleObj | ||
Zeile 335: | Zeile 335: | ||
) | ) | ||
then | then | ||
cat = | 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( | function Blurb:initialize(cfg, protectionObj, titleObj) | ||
self. | 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. | 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. | 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. | 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. | 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. | 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( | function BannerTemplate:initialize(cfg) | ||
self. | 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. | 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. | 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. | 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( | function Banner:initialize(cfg) | ||
BannerTemplate.initialize(self, | 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( | function Padlock:initialize(cfg) | ||
BannerTemplate.initialize(self, | BannerTemplate.initialize(self, cfg) | ||
self:setImageWidth(20) | self:setImageWidth(20) | ||
end | end | ||
Zeile 882: | Zeile 882: | ||
local ProtectionBanner = {} | local ProtectionBanner = {} | ||
function ProtectionBanner.exportToWiki(frame, | 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, | return ProtectionBanner.exportToLua(args, cfg, titleObj) | ||
end | end | ||
function ProtectionBanner.exportToLua(args, | function ProtectionBanner.exportToLua(args, cfg, titleObj) | ||
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, | local protectionObj = Protection:new(args, cfg, titleObj) | ||
local blurbObj = Blurb:new( | 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( | bannerObj = Padlock:new(cfg) | ||
else | else | ||
bannerObj = Banner:new( | bannerObj = Banner:new(cfg) | ||
end | end | ||