Changes

Jump to navigation Jump to search

Module:Protection banner

2,156 bytes added, 14:06, 23 June 2014
Add render methods to the Padlock and Banner classes, and call them from the exportToLua function. Now we have something to look at, yay!
end
-- Set other paramsreason if args.reason then self._reason = args.reason:lower() end  -- Set protection date
self._protectionDate = validateDate(args.date, 'protection date')
end
-- parameter $10
local action = self._protectionStatusObj:getAction()
local pagename = self._titleObj.prefixedText
if action == 'autoreview' then
-- We need the pending changes log.
-- Don't display these links if we are on a talk page.
if not self._titleObj.isTalkPage then
local msg = self._config_configObj:getMessage('semi-subject-page-links') return self.:_substituteParameters(msg)
end
end
function Blurb:makeAltText()
local msg = self._bannerConfig.alt
return self:_substituteParameters(msg)
end
 
function Blurb:makeLinkText()
local msg = self._bannerConfig.link
return self:_substituteParameters(msg)
end
return nil
end
-- Deal with special cases first.
if (namespace == 10 or namespace == 828) -- Maybe we don't need the namespace check?
end
function BannerTemplate:setImageAltsetImageTooltip(alt) self._imageAlt = altend function BannerTemplate:setImageLink(link) self._imageLink = linkend function BannerTemplate:setImageCaption(captiontooltip) self._imageCaption = captiontooltip
end
function BannerTemplate:renderImage()
local filename = self._filename_imageFilename
or self._configObj:getMessage('image-filename-default')
or 'Transparent.gif'
local Banner = BannerTemplate:subclass('Banner')
function Banner:initialize(configObj) BannerTemplate.initialize(self, configObj)
self:setImageWidth(40)
end
 
function Banner:setReasonText(s)
self._reasonText = s
end
 
function Banner:setExplanationText(s)
self._explanationText = s
end
 
function Banner:render(page)
-- Renders the banner.
-- The page parameter specifies the page to generate the banner for, for
-- testing purposes.
mMessageBox = mMessageBox or require('Module:Message box')
local reasonText = self._reasonText or error('no reason text set')
local explanationText = self._explanationText
local mbargs = {
page = page,
type = 'protection',
image = self:renderImage(),
text = string.format(
"'''%s'''%s",
reasonText,
explanationText and '<br />' .. explanationText or ''
)
}
return mMessageBox.main('mbox', mbargs)
end
local Padlock = BannerTemplate:subclass('Padlock')
function Padlock:initialize(configObj) BannerTemplate.initialize(self, configObj)
self:setImageWidth(20)
end
 
function Padlock:setImageAlt(alt)
self._imageAlt = alt
end
 
function Padlock:setImageLink(link)
self._imageLink = link
end
 
function Padlock:setRight(px)
self._right = px
end
 
function Padlock:render()
local root = mw.html.create('div')
root
:addClass('metadata topicon nopopups')
:attr('id', 'protected-icon')
:css{display = 'none', right = self._right or '55px'}
:wikitext(self:renderImage())
return tostring(root)
end
local ProtectionBanner = {}
function ProtectionBanner.exportToWiki(frame, titletitleObj)
mArguments = mArguments or require('Module:Arguments')
local args = mArguments.getArgs(frame)
return ProtectionBanner.exportToLua(args, titletitleObj)
end
function ProtectionBanner.exportToLua(args, titletitleObj) title titleObj = title titleObj or mw.title.getCurrentTitle()
-- Get data objects
local theConfig configObj = Config:new() local theProtectionStatus protectionObj = ProtectionStatus:new(args, theConfigconfigObj, titletitleObj)  -- Initialise the blurb object local blurbObj = Blurb:new(configObj, protectionObj, titleObj) blurbObj:setDeletionDiscussionPage(args.xfd) blurbObj:setUsername(args.user) blurbObj:setSection(args.section)
local ret = {}
-- Render the banner
do -- Get the banner object local theBanner if isPadlock = yesno(args.small) local bannerObj if isPadlock then theBanner bannerObj = Padlock.:new(theConfig, theProtectionStatus, titleconfigObj) else bannerObj = Banner:new(configObj) end  -- Set the image fields local bannerConfig = configObj:getBannerConfig(protectionObj) theBanner local imageFilename = BannerbannerConfig.newimage bannerObj:setImageFilename( imageFilename, protectionObj:getAction(), protectionObj:getLevel(theConfig), theProtectionStatus titleObj.namespace, title protectionObj:getExpiry() ) if isPadlock then bannerObj:setImageTooltip(blurbObj:makeTooltipText()) bannerObj:setImageAlt(blurbObj:makeAltText()) bannerObj:setImageLink(blurbObj:makeLinkText()) else -- Large banners use the alt text for the tooltip. bannerObj:setImageTooltip(blurbObj:makeAltText()) end  -- Set the text fields if not isPadlock then bannerObj:setReasonText(blurbObj:makeReasonText()) bannerObj:setExplanationText(blurbObj:makeExplanationText()) end  ret[#ret + 1] = bannerObj:render()
end
theBanner = Padlock.new(theConfig, theProtectionStatus, title)
theBanner:setDeletionDiscussionPage(args.xfd)
theBanner:setUsername(args.user)
theBanner:setSection(args.section)
ret[#ret + 1] = theBanner:render()
-- Render the categories
return table.concat(ret)
end
Anonymous user

Navigation menu