Modul:Protection banner: Unterschied zwischen den Versionen
move image code to the BannerTemplate class, and simplify it
(move section, username and deletion discussion methods out of the ProtectionStatus class, as they don't really have anything to do with protection status) |
(move image code to the BannerTemplate class, and simplify it) |
||
Zeile 422: | Zeile 422: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- BannerTemplate class | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local | local BannerTemplate = class('BannerTemplate') | ||
function | function BannerTemplate:initialize(configObj) | ||
self._configObj = configObj | self._configObj = configObj | ||
end | end | ||
function | function BannerTemplate:setImageFilename(filename, action, level, namespace, expiry) | ||
if filename then | if filename then | ||
self. | self._imageFilename = filename | ||
return nil | |||
end | |||
if not action or not level then | |||
-- 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, | |||
-- however. | |||
action | return nil | ||
end | |||
-- Deal with special cases first. | |||
if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespace check? | |||
and action == 'edit' | |||
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 | |||
end | |||
-- Deal with regular protection types. | |||
local images = self._configObj:getConfigTable('images') | |||
if images[action] then | |||
if images[action][level] then | |||
self._imageFilename = images[action][level] | |||
return nil | |||
elseif images[action].default then | |||
self._imageFilename = images[action].default | |||
return nil | |||
end | end | ||
end | |||
return nil | |||
end | end | ||
function | function BannerTemplate:setImageWidth(width) | ||
self. | self._imageWidth = width | ||
end | end | ||
function | function BannerTemplate:setImageAlt(alt) | ||
self. | self._imageAlt = alt | ||
end | end | ||
function | function BannerTemplate:setImageLink(link) | ||
self. | self._imageLink = link | ||
end | end | ||
function | function BannerTemplate:setImageCaption(caption) | ||
self. | self._imageCaption = caption | ||
end | end | ||
function | function BannerTemplate:renderImage() | ||
local filename = self._filename | |||
:width(self. | or self._configObj:getMessage('image-filename-default') | ||
:alt(self. | or 'Transparent.gif' | ||
:link(self. | return mFileLink.new(filename) | ||
:caption(self. | :width(self._imageWidth or 20) | ||
:alt(self._imageAlt) | |||
:link(self._imageLink) | |||
:caption(self._imageCaption) | |||
:render() | :render() | ||
end | end | ||
function BannerTemplate:render() | function BannerTemplate:render() | ||
-- Dummy method, to be implemented by the subclasses. | |||
return '' | |||
end | end | ||
Zeile 527: | Zeile 509: | ||
local Banner = BannerTemplate:subclass('Banner') | local Banner = BannerTemplate:subclass('Banner') | ||
function Banner:initialize() | |||
self:setImageWidth(40) | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Zeile 533: | Zeile 519: | ||
local Padlock = BannerTemplate:subclass('Padlock') | local Padlock = BannerTemplate:subclass('Padlock') | ||
function Padlock:initialize() | |||
self:setImageWidth(20) | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Zeile 773: | Zeile 763: | ||
theBanner:setUsername(args.user) | theBanner:setUsername(args.user) | ||
theBanner:setSection(args.section) | theBanner:setSection(args.section) | ||
ret[#ret + 1] = theBanner: | ret[#ret + 1] = theBanner:render() | ||
-- Render the categories | -- Render the categories |