Module:Protection banner: Difference between revisions
Content added Content deleted
Enwikipedia>Jackmcbarn (config isn't an object anymore) |
Enwikipedia>Jackmcbarn (make the Protection class be in charge of the title, and some other tweaks) |
||
Line 10: | Line 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 |
||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
Line 67: | Line 67: | ||
} |
} |
||
function Protection:initialize(args, cfg |
function Protection:initialize(args, cfg) |
||
self._cfg = cfg |
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 |
|||
⚫ | |||
end |
|||
-- Set action |
-- Set action |
||
Line 84: | Line 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, |
||
Line 147: | Line 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. |
||
Line 165: | Line 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] |
||
Line 326: | Line 333: | ||
function Protection:makeTemplateCategory() |
function Protection:makeTemplateCategory() |
||
local cfg = self._cfg |
local cfg = self._cfg |
||
local |
local title = self.title |
||
local cat |
local cat |
||
Line 332: | Line 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 |
||
Line 346: | Line 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 |
||
Line 428: | Line 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. |
||
Line 470: | Line 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 |
||
Line 523: | Line 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 |
||
Line 587: | Line 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 |
||
Line 636: | Line 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. |
||
Line 668: | Line 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 |
||
Line 687: | Line 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 |
||
Line 742: | Line 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 |
||
Line 751: | Line 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. |
||
Line 827: | Line 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 |
||
Line 840: | Line 847: | ||
) |
) |
||
} |
} |
||
return |
return makeMessageBox('mbox', mbargs) |
||
end |
end |
||
Line 877: | Line 884: | ||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
-- Exports |
|||
-- ProtectionBanner class |
|||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
local |
local p = {} |
||
function p._exportClasses() |
|||
function ProtectionBanner.exportToWiki(frame, cfg, titleObj) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local args = mArguments.getArgs(frame) |
|||
⚫ | |||
return ProtectionBanner.exportToLua(args, cfg, titleObj) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
function |
function p._main(args, 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) |
||
Line 914: | Line 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()) |
||
Line 928: | Line 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 |
||
Line 945: | Line 958: | ||
end |
end |
||
function |
function p.main(frame) |
||
if not getArgs then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
return p._main(getArgs(frame)) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
return |
return p |