Module:Protection banner: Difference between revisions

Content added Content deleted
Enwikipedia>Mr. Stradivarius
(move section, username and deletion discussion methods out of the ProtectionStatus class, as they don't really have anything to do with protection status)
Enwikipedia>Mr. Stradivarius
(move image code to the BannerTemplate class, and simplify it)
Line 422: Line 422:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Image class
-- BannerTemplate class
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local Image = class('Image')
local BannerTemplate = class('BannerTemplate')


function Image:initialize(configObj, protectionStatusObj, titleObj)
function BannerTemplate:initialize(configObj)
self._configObj = configObj
self._configObj = configObj
self._protectionStatusObj = protectionStatusObj
self._titleObj = titleObj
end
end


function Image:setFilename(filename)
function BannerTemplate:setImageFilename(filename, action, level, namespace, expiry)
if filename then
if filename then
self._filename = filename
self._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
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
end


function Image:setWidth(width)
function BannerTemplate:setImageWidth(width)
self._width = width
self._imageWidth = width
end
end


function Image:setAlt(alt)
function BannerTemplate:setImageAlt(alt)
self._alt = alt
self._imageAlt = alt
end
end


function Image:setLink(link)
function BannerTemplate:setImageLink(link)
self._link = link
self._imageLink = link
end
end


function Image:setCaption(caption)
function BannerTemplate:setImageCaption(caption)
self._caption = caption
self._imageCaption = caption
end
end


function Image:export()
function BannerTemplate:renderImage()
return mFileLink.new(self._filename or 'Transparent.gif')
local filename = self._filename
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)
:caption(self._caption)
:width(self._imageWidth or 20)
:alt(self._imageAlt)
:link(self._imageLink)
:caption(self._imageCaption)
:render()
:render()
end

--------------------------------------------------------------------------------
-- BannerTemplate class
--------------------------------------------------------------------------------

local BannerTemplate = class('BannerTemplate')

function BannerTemplate:initialize()
end
end


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


Line 527: Line 509:


local Banner = BannerTemplate:subclass('Banner')
local Banner = BannerTemplate:subclass('Banner')

function Banner:initialize()
self:setImageWidth(40)
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 533: Line 519:


local Padlock = BannerTemplate:subclass('Padlock')
local Padlock = BannerTemplate:subclass('Padlock')

function Padlock:initialize()
self:setImageWidth(20)
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 773: Line 763:
theBanner:setUsername(args.user)
theBanner:setUsername(args.user)
theBanner:setSection(args.section)
theBanner:setSection(args.section)
ret[#ret + 1] = theBanner:export()
ret[#ret + 1] = theBanner:render()
-- Render the categories
-- Render the categories