Module:Protection banner: Difference between revisions
Content added Content deleted
Enwikipedia>Mr. Stradivarius (add a p.getPagetype function) |
Enwikipedia>Mr. Stradivarius (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. |
function p.renderImageLink(image, size, link, text, alt) |
||
--[[ |
--[[ |
||
-- Renders the |
-- Renders the image link wikitext All parameters are optional |
||
-- |
-- 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. |
|||
-- |
-- |
||
-- |
-- @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') |
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 = |
:css{display = 'none', right = right or '55px'} |
||
:wikitext( |
: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( |
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. |
||
-- |
-- |
||
-- |
-- @parameters: |
||
-- page - demo page parameter to pass to {{mbox}} |
|||
-- data.page |
|||
-- |
-- image - the image wikitext |
||
-- |
-- 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 = |
page = page, |
||
type = 'protection', |
type = 'protection', |
||
image = |
image = image, |
||
text = |
text = text |
||
} |
} |
||
return mMessageBox.main('mbox', mbargs) |
return mMessageBox.main('mbox', mbargs) |