Modul:Protection banner: Unterschied zwischen den Versionen
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) |
||
Zeile 794: | Zeile 794: | ||
:caption(self._imageCaption) | :caption(self._imageCaption) | ||
:render() | :render() | ||
end | end | ||
Zeile 820: | Zeile 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(), | ||
Zeile 863: | Zeile 862: | ||
end | end | ||
function Padlock: | function Padlock:__tostring() | ||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
root | root | ||
Zeile 921: | Zeile 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 | ||