Module:Protection banner: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(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

function BannerTemplate:render()
-- Dummy method, to be implemented by the subclasses.
return ''
end
end


Line 820: Line 815:
end
end


function Banner:render(page)
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.
-- The page parameter specifies the page to generate the banner for, for
-- testing purposes.
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,
page = self._page,
type = 'protection',
type = 'protection',
image = self:renderImage(),
image = self:renderImage(),
Line 863: Line 862:
end
end


function Padlock:render()
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:render()
ret[#ret + 1] = tostring(bannerObj)
end
end