Module:Protection banner: Difference between revisions
make the banner in charge of setting its own fields
(the only reason to ever use a title other than the current one is for testing, so don't bother exposing it to wikitext) |
(make the banner in charge of setting its own fields) |
||
Line 722: | Line 722: | ||
local BannerTemplate = class('BannerTemplate') | local BannerTemplate = class('BannerTemplate') | ||
function BannerTemplate:initialize(cfg) | function BannerTemplate:initialize(protectionObj, cfg) | ||
self._cfg = cfg | self._cfg = cfg | ||
local imageFilename = protectionObj.bannerConfig.image | |||
if imageFilename then | |||
self._imageFilename = imageFilename | |||
if | else | ||
self._imageFilename = | local action = protectionObj.action | ||
local level = protectionObj.level | |||
local expiry = protectionObj.expiry | |||
local namespace = protectionObj.title.namespace | |||
-- 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._cfg.msg['image-filename-indef'] | |||
else | |||
-- Deal with regular protection types. | |||
local images = self._cfg.images | |||
if images[action] then | |||
if images[action][level] then | |||
self._imageFilename = images[action][level] | |||
elseif images[action].default then | |||
self._imageFilename = images[action].default | |||
end | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
Line 790: | Line 782: | ||
local Banner = BannerTemplate:subclass('Banner') | local Banner = BannerTemplate:subclass('Banner') | ||
function Banner:initialize(cfg) | function Banner:initialize(protectionObj, blurbObj, cfg) | ||
BannerTemplate.initialize(self, cfg) | BannerTemplate.initialize(self, protectionObj, cfg) -- this doesn't need the blurb | ||
self:setImageWidth(40) | self:setImageWidth(40) | ||
self:setImageTooltip(blurbObj:makeAltText()) -- Large banners use the alt text for the tooltip. | |||
self._reasonText = blurbObj:makeReasonText() | |||
self._explanationText = blurbObj:makeExplanationText() | |||
self._reasonText = | self._page = protectionObj.title.prefixedText -- This only affects Module:Message box if the page specified is not the current page. | ||
self._explanationText = | |||
-- | |||
end | end | ||
Line 833: | Line 815: | ||
local Padlock = BannerTemplate:subclass('Padlock') | local Padlock = BannerTemplate:subclass('Padlock') | ||
function Padlock:initialize(cfg) | function Padlock:initialize(protectionObj, blurbObj, cfg) | ||
BannerTemplate.initialize(self, cfg) | BannerTemplate.initialize(self, protectionObj, cfg) -- this doesn't need the blurb | ||
self:setImageWidth(20) | self:setImageWidth(20) | ||
self:setImageTooltip(blurbObj:makeTooltipText()) | |||
self._imageAlt = blurbObj:makeAltText() | |||
self._imageLink = blurbObj:makeLinkText() | |||
self._imageAlt = | |||
self._imageLink = | |||
end | end | ||
Line 890: | Line 867: | ||
-- Render the banner | -- Render the banner | ||
if protectionObj:isProtected() then | if protectionObj:isProtected() then | ||
ret[#ret + 1] = tostring( | |||
(yesno(args.small) and Padlock or Banner) | |||
:new(protectionObj, blurbObj, cfg) | |||
) | |||
end | end | ||