Jump to content

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
end
local imageFilename = protectionObj.bannerConfig.image
 
if imageFilename then
function BannerTemplate:setImageFilename(filename, protectionObj)
self._imageFilename = imageFilename
if filename then
else
self._imageFilename = filename
local action = protectionObj.action
return nil
local level = protectionObj.level
end
local expiry = protectionObj.expiry
 
local namespace = protectionObj.title.namespace
local action = protectionObj.action
local level = protectionObj.level
-- Deal with special cases first.
local expiry = protectionObj.expiry
if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespace check?
local namespace = protectionObj.title.namespace
and action == 'edit'
and level == 'sysop'
-- Deal with special cases first.
and not expiry
if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespace check?
then
and action == 'edit'
-- Fully protected modules and templates get the special red "indef"
and level == 'sysop'
-- padlock.
and not expiry
self._imageFilename = self._cfg.msg['image-filename-indef']
then
else
-- Fully protected modules and templates get the special red "indef"
-- Deal with regular protection types.
-- padlock.
local images = self._cfg.images
self._imageFilename = self._cfg.msg['image-filename-indef']
if images[action] then
return nil
if images[action][level] then
end
self._imageFilename = images[action][level]
 
elseif images[action].default then
-- Deal with regular protection types.
self._imageFilename = images[action].default
local images = self._cfg.images
end
if images[action] then
end
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)
end
self:setImageTooltip(blurbObj:makeAltText()) -- Large banners use the alt text for the tooltip.
 
self._reasonText = blurbObj:makeReasonText()
function Banner:setReasonText(s)
self._explanationText = blurbObj:makeExplanationText()
self._reasonText = s
self._page = protectionObj.title.prefixedText -- This only affects Module:Message box if the page specified is not the current page.
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)
end
self:setImageTooltip(blurbObj:makeTooltipText())
 
self._imageAlt = blurbObj:makeAltText()
function Padlock:setImageAlt(alt)
self._imageLink = blurbObj:makeLinkText()
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
-- Get the banner object
ret[#ret + 1] = tostring(
local bannerObj
(yesno(args.small) and Padlock or Banner)
if yesno(args.small) then
:new(protectionObj, blurbObj, cfg)
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
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.