Zum Inhalt springen

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 mArguments, mMessageBox, lang
local getArgs, makeMessageBox, lang


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Zeile 67: Zeile 67:
}
}


function Protection:initialize(args, cfg, titleObj)
function Protection:initialize(args, cfg)
self._cfg = cfg
self._cfg = cfg
self._titleObj = titleObj
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, titleObj)
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 titleObj = self._titleObj
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 = titleObj.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 titleObj = self._titleObj
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 (titleObj.namespace ~= 10 and titleObj.namespace ~= 828)
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, titleObj)
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._titleObj = titleObj
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._titleObj.prefixedText
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._titleObj.namespace].talk.name,
mw.site.namespaces[self._title.namespace].talk.name,
self._titleObj.text,
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._titleObj.namespace
local namespace = self._title.namespace
local isTalk = self._titleObj.isTalkPage
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._titleObj.namespace
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._titleObj.prefixedText
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._titleObj.namespace].talk.name,
mw.site.namespaces[self._title.namespace].talk.name,
self._titleObj.text,
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._titleObj.baseText
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, titleObj)
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 = titleObj.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.
mMessageBox = mMessageBox or require('Module:Message box')
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 mMessageBox.main('mbox', mbargs)
return makeMessageBox('mbox', mbargs)
end
end


Zeile 877: Zeile 884:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- ProtectionBanner class
-- Exports
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local ProtectionBanner = {}
local p = {}


function ProtectionBanner.exportToWiki(frame, cfg, titleObj)
function p._exportClasses()
mArguments = mArguments or require('Module:Arguments')
-- This is used for testing purposes.
local args = mArguments.getArgs(frame)
return {
return ProtectionBanner.exportToLua(args, cfg, titleObj)
Protection = Protection,
Blurb = Blurb,
BannerTemplate = BannerTemplate,
Banner = Banner,
Padlock = Padlock,
}
end
end


function ProtectionBanner.exportToLua(args, cfg, titleObj)
function p._main(args, cfg)
cfg = cfg or mw.loadData('Module:Protection banner/config')
if not cfg then
titleObj = titleObj or mw.title.getCurrentTitle()
cfg = mw.loadData('Module:Protection banner/config')
end


-- Initialise protection and blurb objects
-- Initialise protection and blurb objects
local protectionObj = Protection:new(args, cfg, titleObj)
local protectionObj = Protection:new(args, cfg)
local blurbObj = Blurb:new(cfg, protectionObj, titleObj)
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, titleObj)
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(titleObj.prefixedText)
bannerObj:setPage(protectionObj.title.prefixedText)
end
end


Zeile 945: Zeile 958:
end
end


function ProtectionBanner._exportClasses()
function p.main(frame)
-- This is used to export the classes for testing purposes.
if not getArgs then
return {
getArgs = require('Module:Arguments').getArgs
Protection = Protection,
end
Blurb = Blurb,
return p._main(getArgs(frame))
BannerTemplate = BannerTemplate,
Banner = Banner,
Padlock = Padlock,
}
end
end


return ProtectionBanner
return p
Anonymer Benutzer