Changes
move image code to the BannerTemplate class, and simplify it
--------------------------------------------------------------------------------
-- Image BannerTemplate class
--------------------------------------------------------------------------------
local Image BannerTemplate = class('ImageBannerTemplate')
function ImageBannerTemplate:initialize(configObj, protectionStatusObj, titleObj)
self._configObj = configObj
end
function ImageBannerTemplate:setFilenamesetImageFilename(filename, action, level, namespace, expiry)
if filename then
self._filename _imageFilename = filename return nil elseend if not action or not level then local images-- If the filename is not specified, we need the action, and the level -- to find the image name. The namespace and the expiry are optional, reason, -- however. return nil end -- Deal with special cases first. if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespacecheck? doand action == 'edit' local configObj and level == 'sysop' and not expiry then -- Fully protected modules and templates get the special red "indef" -- padlock. self._imageFilename = self._configObj:getMessage('image-filename-indef') return nil local protectionStatusObj = self end -- Deal with regular protection types._protectionStatusObj local titleObj images = self._titleObj images = configObj_configObj:getConfigTable('images') if images[action] then if images[action][level] then self._imageFilename = images[action = protectionStatusObj:getAction()][level] level = protectionStatusObj:getLevel()return nil elseif images[action].default then reason self._imageFilename = protectionStatusObj:getReason()images[action].default namespace = titleObj:getNamespace()return nil
end
end
end
function ImageBannerTemplate:setWidthsetImageWidth(width) self._width _imageWidth = width
end
function ImageBannerTemplate:setAltsetImageAlt(alt) self._alt _imageAlt = alt
end
function ImageBannerTemplate:setLinksetImageLink(link) self._link _imageLink = link
end
function ImageBannerTemplate:setCaptionsetImageCaption(caption) self._caption _imageCaption = caption
end
function ImageBannerTemplate:exportrenderImage() return mFileLinklocal filename = self.new(_filename or self._filename _configObj:getMessage('image-filename-default') or 'Transparent.gif' return mFileLink.new(filename) :width(self._width _imageWidth or 20) :alt(self._alt_imageAlt) :link(self._link_imageLink) :caption(self._caption_imageCaption)
:render()
end
function BannerTemplate:render()
-- Dummy method, to be implemented by the subclasses.
return ''
end
local Banner = BannerTemplate:subclass('Banner')
function Banner:initialize()
self:setImageWidth(40)
end
--------------------------------------------------------------------------------
local Padlock = BannerTemplate:subclass('Padlock')
function Padlock:initialize()
self:setImageWidth(20)
end
--------------------------------------------------------------------------------
theBanner:setUsername(args.user)
theBanner:setSection(args.section)
ret[#ret + 1] = theBanner:exportrender()
-- Render the categories