Module:Protection banner: Difference between revisions

Jump to navigation Jump to search
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)
Line 422:
 
--------------------------------------------------------------------------------
-- ImageBannerTemplate class
--------------------------------------------------------------------------------
 
local ImageBannerTemplate = class('ImageBannerTemplate')
 
function ImageBannerTemplate:initialize(configObj, protectionStatusObj, titleObj)
self._configObj = configObj
self._protectionStatusObj = protectionStatusObj
self._titleObj = titleObj
end
 
function ImageBannerTemplate:setFilenamesetImageFilename(filename, action, level, namespace, expiry)
if filename then
self._filename_imageFilename = filename
return nil
else
end
local images, action, level, reason, namespace
do
if not action or not level then
local configObj = self._configObj
-- If the filename is not specified, we need the action and the level
local protectionStatusObj = self._protectionStatusObj
-- to find the image name. The namespace and the expiry are optional,
local titleObj = self._titleObj
-- however.
images = configObj:getConfigTable('images')
return nil
action = protectionStatusObj:getAction()
end
level = protectionStatusObj:getLevel()
reason = protectionStatusObj:getReason()
-- Deal with special cases first.
namespace = titleObj:getNamespace()
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
 
return nil
local image
if reason == 'office' or reason == 'reset' then
image = images.office
elseif namespace == 10 or namespace == 828 then
-- We are in the template or module namespaces.
if level == 'templateeditor' then
image = images.template
elseif level == 'sysop' then
image = images.indef
end
elseif action == 'create' then
image = images.create
elseif action == 'move'
and (
level == 'templateeditor'
or level == 'sysop'
)
then
image = images.move
elseif action == 'edit' then
if level == 'sysop' then
image = images.full
elseif level == 'autoconfirmed' then
image = images.semi
end
elseif action == 'autoreview' then
if level == 'autoconfirmed' then
image = images.pc1
elseif level == 'reviewer' then
image = images.pc2
end
end
self._filename = image
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()
returnlocal filename = mFileLink.new(self._filename or 'Transparent.gif')
or self._configObj:getMessage('image-filename-default')
:width(self._width or 20)
or 'Transparent.gif'
:alt(self._alt)
return mFileLink.new(filename)
:link(self._link)
:captionwidth(self._caption_imageWidth or 20)
:alt(self._imageAlt)
:link(self._imageLink)
:caption(self._imageCaption)
:render()
end
 
--------------------------------------------------------------------------------
-- BannerTemplate class
--------------------------------------------------------------------------------
 
local BannerTemplate = class('BannerTemplate')
 
function BannerTemplate:initialize()
end
 
function BannerTemplate:render()
-- Dummy method, to be implemented by the subclasses.
return ''
end
 
Line 527 ⟶ 509:
 
local Banner = BannerTemplate:subclass('Banner')
 
function Banner:initialize()
self:setImageWidth(40)
end
 
--------------------------------------------------------------------------------
Line 533 ⟶ 519:
 
local Padlock = BannerTemplate:subclass('Padlock')
 
function Padlock:initialize()
self:setImageWidth(20)
end
 
--------------------------------------------------------------------------------
Line 773 ⟶ 763:
theBanner:setUsername(args.user)
theBanner:setSection(args.section)
ret[#ret + 1] = theBanner:exportrender()
-- Render the categories
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu