Module:Protection banner: Difference between revisions

add a p.renderImageLink function so that we can share image generation code between the padlock and the banner
(add a p.getPagetype function)
(add a p.renderImageLink function so that we can share image generation code between the padlock and the banner)
Line 258:
end
 
function p.renderPadlockrenderImageLink(dataimage, size, link, text, alt)
--[[
-- Renders the padlockimage seenlink inwikitext theAll top-right-handparameters cornerare or protected pages,optional
-- usingapart the data provided infrom the datadisplay tabletext.
--
-- @parameters:
-- image - the image name
-- size - the image size, as a number
-- link - page linked to by the image
-- text - the tooltip text
-- alt - the alt text
--
-- All parameters are optional apart from the text parameter.
--]]
image = image or 'Transparent.gif'
size = size or 20
if link then
link = '|link=' .. link
else
link = ''
end
text = text or error('No text parameter supplied to p.renderImageLink')
if alt then
alt = '|alt=' .. alt
else
alt = ''
end
return string.format('[[Image:%s|%dpx%s|%s%s]]', image, size, link, text, alt)
end
 
function p.renderPadlock(image, right)
--[[
-- Renders the html of the padlock seen in the top-right-hand corner
-- of protected pages.
--
-- Data fields@parameters:
-- image - the image wikitext
-- data.right
-- right - the "right" css property value, as a string
-- data.image
--
-- data.iconLink
-- Both parameters are optional.
-- data.iconText
-- data.altText
--]]
local root = mw.html.create('div')
Line 274 ⟶ 303:
:addClass('metadata topicon nopopups')
:attr('id', 'protected-icon')
:css{display = 'none', right = data.right or '55px'}
:wikitext(format(image)
'[[Image:%s|20px|link=%s|%s|alt=%s]]',
data.image, data.iconLink, data.iconText, data.altText
))
return tostring(root)
end
 
function p.renderBanner(datapage, image, text)
--[[
-- Renders the large protection banner placed at the top of articles,
-- using the data provided in the data table.
--
-- Data fields@parameters:
-- page - demo page parameter to pass to {{mbox}}
-- data.page
-- data.image - the image wikitext
-- data.text - the text to display
--
-- All parameters are optional.
--]]
mMessageBox = require('Module:Message box')
local mbargs = { -- arguments for the message box module
page = data.page,
type = 'protection',
image = data.image,
text = data.text
}
return mMessageBox.main('mbox', mbargs)