Module:Protection banner: Difference between revisions
use a __tostring metamethod to render the banner objects
(move the category methods to the Protection class, and get rid of all the category objects) |
(use a __tostring metamethod to render the banner objects) |
||
Line 794: | Line 794: | ||
:caption(self._imageCaption) | :caption(self._imageCaption) | ||
:render() | :render() | ||
end | end | ||
Line 820: | Line 815: | ||
end | end | ||
function Banner: | function Banner:setPage(s) | ||
-- This specifies the page to generate the banner for. This only affects | |||
-- Module:Message box if the page specified is not the current page. | |||
self._page = s | |||
end | |||
function Banner:__tostring() | |||
-- Renders the banner. | -- Renders the banner. | ||
mMessageBox = mMessageBox or require('Module:Message box') | mMessageBox = mMessageBox or require('Module:Message box') | ||
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 | ||
local mbargs = { | local mbargs = { | ||
page = | page = self._page, | ||
type = 'protection', | type = 'protection', | ||
image = self:renderImage(), | image = self:renderImage(), | ||
Line 863: | Line 862: | ||
end | end | ||
function Padlock: | function Padlock:__tostring() | ||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
root | root | ||
Line 921: | Line 920: | ||
end | end | ||
-- Set the text fields | -- Set the text fields and the page name. | ||
if not isPadlock then | if not isPadlock then | ||
bannerObj:setReasonText(blurbObj:makeReasonText()) | bannerObj:setReasonText(blurbObj:makeReasonText()) | ||
bannerObj:setExplanationText(blurbObj:makeExplanationText()) | bannerObj:setExplanationText(blurbObj:makeExplanationText()) | ||
bannerObj:setPage(titleObj.prefixedText) | |||
end | end | ||
ret[#ret + 1] = bannerObj | ret[#ret + 1] = tostring(bannerObj) | ||
end | end | ||