Modul:Protection banner: Unterschied zwischen den Versionen
make the Protection class be in charge of the title, and some other tweaks
(config isn't an object anymore) |
(make the Protection class be in charge of the title, and some other tweaks) |
||
Zeile 10: | Zeile 10: | ||
-- Lazily initialise modules and objects we don't always need. | -- Lazily initialise modules and objects we don't always need. | ||
local | local getArgs, makeMessageBox, lang | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Zeile 67: | Zeile 67: | ||
} | } | ||
function Protection:initialize(args, cfg | function Protection:initialize(args, cfg) | ||
self._cfg = cfg | self._cfg = cfg | ||
self. | if args.title then | ||
self.title = mw.title.new(args.title) | |||
if not self.title then | |||
error('Invalid title "' .. args.title .. '"', 2) | |||
end | |||
else | |||
self.title = mw.title.getCurrentTitle() | |||
end | |||
-- Set action | -- Set action | ||
Zeile 84: | Zeile 91: | ||
-- Set level | -- Set level | ||
do | do | ||
self.level = effectiveProtectionLevel(self.action, | self.level = effectiveProtectionLevel(self.action, self.title) | ||
if self.level == 'accountcreator' then | if self.level == 'accountcreator' then | ||
-- Lump titleblacklisted pages in with template-protected pages, | -- Lump titleblacklisted pages in with template-protected pages, | ||
Zeile 147: | Zeile 154: | ||
function Protection:makeProtectionCategory() | function Protection:makeProtectionCategory() | ||
local cfg = self._cfg | local cfg = self._cfg | ||
local | local title = self.title | ||
-- Exit if the page is not protected. | -- Exit if the page is not protected. | ||
Zeile 165: | Zeile 172: | ||
local nskey | local nskey | ||
do | do | ||
local namespace = | local namespace = title.namespace | ||
local categoryNamespaces = cfg.categoryNamespaceKeys | local categoryNamespaces = cfg.categoryNamespaceKeys | ||
nskey = categoryNamespaces[namespace] | nskey = categoryNamespaces[namespace] | ||
Zeile 326: | Zeile 333: | ||
function Protection:makeTemplateCategory() | function Protection:makeTemplateCategory() | ||
local cfg = self._cfg | local cfg = self._cfg | ||
local | local title = self.title | ||
local cat | local cat | ||
Zeile 332: | Zeile 339: | ||
and ( | and ( | ||
(self.action ~= 'edit' and self.action ~= 'move') | (self.action ~= 'edit' and self.action ~= 'move') | ||
or ( | or (title.namespace ~= 10 and title.namespace ~= 828) | ||
) | ) | ||
then | then | ||
Zeile 346: | Zeile 353: | ||
local Blurb = class('Blurb') | local Blurb = class('Blurb') | ||
function Blurb:initialize(cfg, protectionObj | function Blurb:initialize(cfg, protectionObj) | ||
self._cfg = cfg | self._cfg = cfg | ||
self._protectionObj = protectionObj | self._protectionObj = protectionObj | ||
self._bannerConfig = protectionObj.bannerConfig | self._bannerConfig = protectionObj.bannerConfig | ||
self. | self._title = protectionObj.title | ||
end | end | ||
Zeile 428: | Zeile 435: | ||
-- protection. | -- protection. | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local pagename = self. | local pagename = self._title.prefixedText | ||
if action == 'move' then | if action == 'move' then | ||
-- We need the move log link. | -- We need the move log link. | ||
Zeile 470: | Zeile 477: | ||
return string.format( | return string.format( | ||
'[[%s:%s#%s|%s]]', | '[[%s:%s#%s|%s]]', | ||
mw.site.namespaces[self. | mw.site.namespaces[self._title.namespace].talk.name, | ||
self. | self._title.text, | ||
section, | section, | ||
disputes | disputes | ||
Zeile 523: | Zeile 530: | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj.level | local level = self._protectionObj.level | ||
local namespace = self. | local namespace = self._title.namespace | ||
local isTalk = self. | local isTalk = self._title.isTalkPage | ||
-- @TODO: add semi-protection and pending changes blurbs | -- @TODO: add semi-protection and pending changes blurbs | ||
Zeile 587: | Zeile 594: | ||
function Blurb:_makePagetypeParameter() | function Blurb:_makePagetypeParameter() | ||
local pagetypes = self._cfg.pagetypes | local pagetypes = self._cfg.pagetypes | ||
local namespace = self. | local namespace = self._title.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') | ||
end | end | ||
Zeile 636: | Zeile 643: | ||
function Blurb:_makeProtectionLogParameter() | function Blurb:_makeProtectionLogParameter() | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local pagename = self. | local pagename = self._title.prefixedText | ||
if action == 'autoreview' then | if action == 'autoreview' then | ||
-- We need the pending changes log. | -- We need the pending changes log. | ||
Zeile 668: | Zeile 675: | ||
return string.format( | return string.format( | ||
'[[%s:%s#%s|%s]]', | '[[%s:%s#%s|%s]]', | ||
mw.site.namespaces[self. | mw.site.namespaces[self._title.namespace].talk.name, | ||
self. | self._title.text, | ||
section or 'top', | section or 'top', | ||
display | display | ||
Zeile 687: | Zeile 694: | ||
local mVandalM = require('Module:Vandal-m') | local mVandalM = require('Module:Vandal-m') | ||
local username = self._username | local username = self._username | ||
username = username or self. | username = username or self._title.baseText | ||
return mVandalM._main{username} | return mVandalM._main{username} | ||
end | end | ||
Zeile 742: | Zeile 749: | ||
end | end | ||
function BannerTemplate:setImageFilename(filename, protectionObj | function BannerTemplate:setImageFilename(filename, protectionObj) | ||
if filename then | if filename then | ||
self._imageFilename = filename | self._imageFilename = filename | ||
Zeile 751: | Zeile 758: | ||
local level = protectionObj.level | local level = protectionObj.level | ||
local expiry = protectionObj.expiry | local expiry = protectionObj.expiry | ||
local namespace = | local namespace = protectionObj.title.namespace | ||
-- Deal with special cases first. | -- Deal with special cases first. | ||
Zeile 827: | Zeile 834: | ||
function Banner:__tostring() | function Banner:__tostring() | ||
-- Renders the banner. | -- Renders the banner. | ||
makeMessageBox = makeMessageBox or require('Module:Message box').main | |||
local reasonText = self._reasonText or error('no reason text set') | local reasonText = self._reasonText or error('no reason text set') | ||
local explanationText = self._explanationText | local explanationText = self._explanationText | ||
Zeile 840: | Zeile 847: | ||
) | ) | ||
} | } | ||
return | return makeMessageBox('mbox', mbargs) | ||
end | end | ||
Zeile 877: | Zeile 884: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Exports | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local | local p = {} | ||
function | function p._exportClasses() | ||
-- This is used for testing purposes. | |||
return { | |||
Protection = Protection, | |||
Blurb = Blurb, | |||
BannerTemplate = BannerTemplate, | |||
Banner = Banner, | |||
Padlock = Padlock, | |||
} | |||
end | end | ||
function | function p._main(args, cfg) | ||
cfg = | if not cfg then | ||
cfg = mw.loadData('Module:Protection banner/config') | |||
end | |||
-- Initialise protection and blurb objects | -- Initialise protection and blurb objects | ||
local protectionObj = Protection:new(args, cfg | local protectionObj = Protection:new(args, cfg) | ||
local blurbObj = Blurb:new(cfg, protectionObj | local blurbObj = Blurb:new(cfg, protectionObj) | ||
blurbObj:setDeletionDiscussionPage(args.xfd) | blurbObj:setDeletionDiscussionPage(args.xfd) | ||
blurbObj:setUsername(args.user) | blurbObj:setUsername(args.user) | ||
Zeile 914: | Zeile 927: | ||
-- Set the image fields | -- Set the image fields | ||
local bannerConfig = protectionObj.bannerConfig | local bannerConfig = protectionObj.bannerConfig | ||
bannerObj:setImageFilename(bannerConfig.image, protectionObj | bannerObj:setImageFilename(bannerConfig.image, protectionObj) | ||
if isPadlock then | if isPadlock then | ||
bannerObj:setImageTooltip(blurbObj:makeTooltipText()) | bannerObj:setImageTooltip(blurbObj:makeTooltipText()) | ||
Zeile 928: | Zeile 941: | ||
bannerObj:setReasonText(blurbObj:makeReasonText()) | bannerObj:setReasonText(blurbObj:makeReasonText()) | ||
bannerObj:setExplanationText(blurbObj:makeExplanationText()) | bannerObj:setExplanationText(blurbObj:makeExplanationText()) | ||
bannerObj:setPage( | bannerObj:setPage(protectionObj.title.prefixedText) | ||
end | end | ||
Zeile 945: | Zeile 958: | ||
end | end | ||
function | function p.main(frame) | ||
if not getArgs then | |||
getArgs = require('Module:Arguments').getArgs | |||
end | |||
return p._main(getArgs(frame)) | |||
end | end | ||
return | return p |