Jump to content

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: Line 258:
end
end


function p.renderPadlock(data)
function p.renderImageLink(image, size, link, text, alt)
--[[
--[[
-- Renders the padlock seen in the top-right-hand corner or protected pages,
-- Renders the image link wikitext All parameters are optional
-- using the data provided in the data table.
-- apart from the display text.
--
-- @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:
-- data.right
-- image - the image wikitext
-- data.image
-- right - the "right" css property value, as a string
-- data.iconLink
--
-- data.iconText
-- Both parameters are optional.
-- data.altText
--]]
--]]
local root = mw.html.create('div')
local root = mw.html.create('div')
Line 274: Line 303:
:addClass('metadata topicon nopopups')
:addClass('metadata topicon nopopups')
:attr('id', 'protected-icon')
:attr('id', 'protected-icon')
:css{display = 'none', right = data.right or '55px'}
:css{display = 'none', right = right or '55px'}
:wikitext(format(
:wikitext(image)
'[[Image:%s|20px|link=%s|%s|alt=%s]]',
data.image, data.iconLink, data.iconText, data.altText
))
return tostring(root)
return tostring(root)
end
end


function p.renderBanner(data)
function p.renderBanner(page, image, text)
--[[
--[[
-- Renders the large protection banner placed at the top of articles,
-- Renders the large protection banner placed at the top of articles,
-- using the data provided in the data table.
-- using the data provided in the data table.
--  
--  
-- Data fields:
-- @parameters:
-- data.page
-- page - demo page parameter to pass to {{mbox}}
-- data.image
-- image - the image wikitext
-- data.text
-- text - the text to display
--
-- All parameters are optional.
--]]
--]]
mMessageBox = require('Module:Message box')
mMessageBox = require('Module:Message box')
local mbargs = { -- arguments for the message box module
local mbargs = { -- arguments for the message box module
page = data.page,
page = page,
type = 'protection',
type = 'protection',
image = data.image,
image = image,
text = data.text
text = text
}
}
return mMessageBox.main('mbox', mbargs)
return mMessageBox.main('mbox', mbargs)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.