Changes
Jump to navigation
Jump to search
allow bannerConfig table fields to be functions
local Blurb = class('Blurb')
Blurb.bannerTextFields = {
text = true,
explanation = true,
tooltip = true,
alt = true,
link = true
}
function Blurb:initialize(protectionObj, args, cfg)
self._cfg = cfg
self._protectionObj = protectionObj
self._username _data = { username = args.user, self._section section = args.section }
end
-- "disputes", with or without a section link
local disputes = self:_getExpandedMessage('dispute-section-link-display')
if self._section _data.section then
return string.format(
'[[%s:%s#%s|%s]]',
mw.site.namespaces[self._protectionObj.title.namespace].talk.name,
self._protectionObj.title.text,
self._section_data.section,
disputes
)
mw.site.namespaces[self._protectionObj.title.namespace].talk.name,
self._protectionObj.title.text,
self._section _data.section or 'top',
self:_getExpandedMessage('talk-page-link-display')
)
function Blurb:_makeVandalTemplateParameter()
return require('Module:Vandal-m')._main{
self._username _data.username or self._protectionObj.title.baseText
}
end
-- Public methods --
function Blurb:makeReasonTextmakeBannerText(key) -- Validate input. if not key or not Blurb.bannerTextFields[key] then error(string.format( '"%s" is not a valid banner field', tostring(key) ), 2) end -- Generate the text. local msg = self._protectionObj.bannerConfig[key] if type(msg) == 'string' then return self:_substituteParameters(msg) elseif type(msg) == 'function' then msg = msg(self.text_protectionObj, self._data) if type(msg ) ~= 'string' then error(string.format( 'bad output from banner config function with key "%s"' .. ' (expected string, got %s)', tostring(key), type(msg) )) end
return self:_substituteParameters(msg)
end
end function Blurb:makeExplanationText() local msg = self._protectionObj.bannerConfig.explanation return self:_substituteParameters(msg)end function Blurb:makeTooltipText() local msg = self._protectionObj.bannerConfig.tooltip return self:_substituteParameters(msg)end function Blurb:makeAltText() local msg = self._protectionObj.bannerConfig.alt return self:_substituteParameters(msg)end function Blurb:makeLinkText() local msg = self._protectionObj.bannerConfig.link return self:_substituteParameters(msg)end
--------------------------------------------------------------------------------
BannerTemplate.initialize(self, protectionObj, cfg) -- This doesn't need the blurb.
self:setImageWidth(40)
self:setImageTooltip(blurbObj:makeAltTextmakeBannerText('alt')) -- Large banners use the alt text for the tooltip. self._reasonText = blurbObj:makeReasonTextmakeBannerText('text') self._explanationText = blurbObj:makeExplanationTextmakeBannerText('explanation')
self._page = protectionObj.title.prefixedText -- Only makes a difference in testing.
end
BannerTemplate.initialize(self, protectionObj, cfg) -- This doesn't need the blurb.
self:setImageWidth(20)
self:setImageTooltip(blurbObj:makeTooltipTextmakeBannerText('tooltip')) self._imageAlt = blurbObj:makeAltTextmakeBannerText('alt') self._imageLink = blurbObj:makeLinkTextmakeBannerText('link')
self._right = cfg.padlockPositions[protectionObj.action]
or cfg.padlockPositions.default
args = args or {}
if not cfg then
cfg = mw.loadDatarequire('Module:Protection banner/config')
end