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: | ||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
-- |
-- BannerTemplate class |
||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
local |
local BannerTemplate = class('BannerTemplate') |
||
function |
function BannerTemplate:initialize(configObj) |
||
self._configObj = configObj |
self._configObj = configObj |
||
self._protectionStatusObj = protectionStatusObj |
|||
self._titleObj = titleObj |
|||
end |
end |
||
function |
function BannerTemplate:setImageFilename(filename, action, level, namespace, expiry) |
||
if filename then |
if filename then |
||
self. |
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 |
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 |
|||
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) |
|||
: |
: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: |
ret[#ret + 1] = theBanner:render() |
||
-- Render the categories |
-- Render the categories |