Module:Protection banner: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(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
end
if imageFilename then

self._imageFilename = imageFilename
function BannerTemplate:setImageFilename(filename, protectionObj)
else
if filename then
local action = protectionObj.action
self._imageFilename = filename
local level = protectionObj.level
return nil
local expiry = protectionObj.expiry
end
local namespace = protectionObj.title.namespace

local action = protectionObj.action
-- Deal with special cases first.
local level = protectionObj.level
if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespace check?
local expiry = protectionObj.expiry
and action == 'edit'
local namespace = protectionObj.title.namespace
and level == 'sysop'
and not expiry
-- Deal with special cases first.
then
if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespace check?
-- Fully protected modules and templates get the special red "indef"
and action == 'edit'
-- padlock.
and level == 'sysop'
self._imageFilename = self._cfg.msg['image-filename-indef']
and not expiry
else
then
-- Deal with regular protection types.
-- Fully protected modules and templates get the special red "indef"
local images = self._cfg.images
-- padlock.
if images[action] then
self._imageFilename = self._cfg.msg['image-filename-indef']
if images[action][level] then
return nil
self._imageFilename = images[action][level]
end
elseif images[action].default then

self._imageFilename = images[action].default
-- Deal with regular protection types.
end
local images = self._cfg.images
end
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
end

return nil
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.
end
self._reasonText = blurbObj:makeReasonText()

self._explanationText = blurbObj:makeExplanationText()
function Banner:setReasonText(s)
self._page = protectionObj.title.prefixedText -- This only affects Module:Message box if the page specified is not the current page.
self._reasonText = s
end

function Banner:setExplanationText(s)
self._explanationText = s
end

function Banner:setPage(s)
-- This specifies the page to generate the banner for. This only affects
-- Module:Message box if the page specified is not the current page.
self._page = s
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())
end
self._imageAlt = blurbObj:makeAltText()

self._imageLink = blurbObj:makeLinkText()
function Padlock:setImageAlt(alt)
self._imageAlt = alt
end

function Padlock:setImageLink(link)
self._imageLink = link
end
end


Line 890: Line 867:
-- Render the banner
-- Render the banner
if protectionObj:isProtected() then
if protectionObj:isProtected() then
ret[#ret + 1] = tostring(
-- Get the banner object
(yesno(args.small) and Padlock or Banner)
local bannerObj
:new(protectionObj, blurbObj, cfg)
if yesno(args.small) then
)
bannerObj = Padlock:new(cfg)
bannerObj:setImageTooltip(blurbObj:makeTooltipText())
bannerObj:setImageAlt(blurbObj:makeAltText())
bannerObj:setImageLink(blurbObj:makeLinkText())
else
bannerObj = Banner:new(cfg)
-- Large banners use the alt text for the tooltip.
bannerObj:setImageTooltip(blurbObj:makeAltText())
-- Set the text fields and the page name.
bannerObj:setReasonText(blurbObj:makeReasonText())
bannerObj:setExplanationText(blurbObj:makeExplanationText())
bannerObj:setPage(protectionObj.title.prefixedText)
end
-- Set the image fields
local bannerConfig = protectionObj.bannerConfig
bannerObj:setImageFilename(bannerConfig.image, protectionObj)

ret[#ret + 1] = tostring(bannerObj)
end
end