Module:Protection banner: Difference between revisions

Jump to navigation Jump to search
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)
Line 10:
 
-- Lazily initialise modules and objects we don't always need.
local mArgumentsgetArgs, mMessageBoxmakeMessageBox, lang
 
--------------------------------------------------------------------------------
Line 67:
}
 
function Protection:initialize(args, cfg, titleObj)
self._cfg = cfg
if args.title then
self._titleObj = titleObj
self.title = mw.title.new(args.title)
if not self.title then
error('Invalid title "' .. args.title .. '"', 2)
end
else
titleObj self.title = titleObj or mw.title.getCurrentTitle()
end
 
-- Set action
Line 84 ⟶ 91:
-- Set level
do
self.level = effectiveProtectionLevel(self.action, titleObjself.title)
if self.level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
Line 147 ⟶ 154:
function Protection:makeProtectionCategory()
local cfg = self._cfg
local titleObjtitle = self._titleObjtitle
-- Exit if the page is not protected.
Line 165 ⟶ 172:
local nskey
do
local namespace = titleObjtitle.namespace
local categoryNamespaces = cfg.categoryNamespaceKeys
nskey = categoryNamespaces[namespace]
Line 326 ⟶ 333:
function Protection:makeTemplateCategory()
local cfg = self._cfg
local titleObjtitle = self._titleObjtitle
local cat
Line 332 ⟶ 339:
and (
(self.action ~= 'edit' and self.action ~= 'move')
or (titleObjtitle.namespace ~= 10 and titleObjtitle.namespace ~= 828)
)
then
Line 346 ⟶ 353:
local Blurb = class('Blurb')
 
function Blurb:initialize(cfg, protectionObj, titleObj)
self._cfg = cfg
self._protectionObj = protectionObj
self._bannerConfig = protectionObj.bannerConfig
self._titleObj_title = titleObjprotectionObj.title
end
 
Line 428 ⟶ 435:
-- protection.
local action = self._protectionObj.action
local pagename = self._titleObj_title.prefixedText
if action == 'move' then
-- We need the move log link.
Line 470 ⟶ 477:
return string.format(
'[[%s:%s#%s|%s]]',
mw.site.namespaces[self._titleObj_title.namespace].talk.name,
self._titleObj_title.text,
section,
disputes
Line 523 ⟶ 530:
local action = self._protectionObj.action
local level = self._protectionObj.level
local namespace = self._titleObj_title.namespace
local isTalk = self._titleObj_title.isTalkPage
 
-- @TODO: add semi-protection and pending changes blurbs
Line 587 ⟶ 594:
function Blurb:_makePagetypeParameter()
local pagetypes = self._cfg.pagetypes
local namespace = self._titleObj_title.namespace
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined')
end
Line 636 ⟶ 643:
function Blurb:_makeProtectionLogParameter()
local action = self._protectionObj.action
local pagename = self._titleObj_title.prefixedText
if action == 'autoreview' then
-- We need the pending changes log.
Line 668 ⟶ 675:
return string.format(
'[[%s:%s#%s|%s]]',
mw.site.namespaces[self._titleObj_title.namespace].talk.name,
self._titleObj_title.text,
section or 'top',
display
Line 687 ⟶ 694:
local mVandalM = require('Module:Vandal-m')
local username = self._username
username = username or self._titleObj_title.baseText
return mVandalM._main{username}
end
Line 742 ⟶ 749:
end
 
function BannerTemplate:setImageFilename(filename, protectionObj, titleObj)
if filename then
self._imageFilename = filename
Line 751 ⟶ 758:
local level = protectionObj.level
local expiry = protectionObj.expiry
local namespace = titleObjprotectionObj.title.namespace
-- Deal with special cases first.
Line 827 ⟶ 834:
function Banner:__tostring()
-- Renders the banner.
mMessageBoxmakeMessageBox = mMessageBoxmakeMessageBox or require('Module:Message box').main
local reasonText = self._reasonText or error('no reason text set')
local explanationText = self._explanationText
Line 840 ⟶ 847:
)
}
return mMessageBox.mainmakeMessageBox('mbox', mbargs)
end
 
Line 877 ⟶ 884:
 
--------------------------------------------------------------------------------
-- Exports
-- ProtectionBanner class
--------------------------------------------------------------------------------
 
local ProtectionBannerp = {}
 
function p._exportClasses()
function ProtectionBanner.exportToWiki(frame, cfg, titleObj)
-- This is used to export the classes for testing purposes.
mArguments = mArguments or require('Module:Arguments')
return {
local args = mArguments.getArgs(frame)
Protection = Protection,
return ProtectionBanner.exportToLua(args, cfg, titleObj)
Blurb = Blurb,
BannerTemplate = BannerTemplate,
Banner = Banner,
Padlock = Padlock,
}
end
 
function ProtectionBannerp.exportToLua_main(args, cfg, titleObj)
if not cfg then
cfg = cfg or mw.loadData('Module:Protection banner/config')
titleObj = titleObj or mw.title.getCurrentTitle()
end
 
-- Initialise protection and blurb objects
local protectionObj = Protection:new(args, cfg, titleObj)
local blurbObj = Blurb:new(cfg, protectionObj, titleObj)
blurbObj:setDeletionDiscussionPage(args.xfd)
blurbObj:setUsername(args.user)
Line 914 ⟶ 927:
-- Set the image fields
local bannerConfig = protectionObj.bannerConfig
bannerObj:setImageFilename(bannerConfig.image, protectionObj, titleObj)
if isPadlock then
bannerObj:setImageTooltip(blurbObj:makeTooltipText())
Line 928 ⟶ 941:
bannerObj:setReasonText(blurbObj:makeReasonText())
bannerObj:setExplanationText(blurbObj:makeExplanationText())
bannerObj:setPage(titleObjprotectionObj.title.prefixedText)
end
 
Line 945 ⟶ 958:
end
 
function ProtectionBannerp._exportClassesmain(frame)
if not getArgs then
-- This is used to export the classes for testing purposes.
mArguments getArgs = mArguments or require('Module:Arguments').getArgs
return {
end
Protection = Protection,
return p._main(getArgs(frame))
Blurb = Blurb,
BannerTemplate = BannerTemplate,
Banner = Banner,
Padlock = Padlock,
}
end
 
return ProtectionBannerp
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu