Module:Message box: Difference between revisions
Content added Content deleted
(add tmbox) |
(initial code for ambox) |
||
Line 22: | Line 22: | ||
local function generateBoxStructure() |
local function generateBoxStructure() |
||
local root = htmlBuilder.create() -- Includes error messages and categories added after the box. |
local root = htmlBuilder.create() -- Includes error messages and categories added after the box. |
||
local substCheck = root.tag('b').addClass('error') |
|||
local box = root.tag('table') |
local box = root.tag('table') |
||
local row = box.tag('tr') |
local row = box.tag('tr') |
||
local imageLeftCell = row.tag('td') |
|||
return root, substCheck, box, row, imageLeftCell |
|||
end |
end |
||
Line 53: | Line 55: | ||
local isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false |
local isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false |
||
local image, imageRight, text, imageSize |
local smallClass, image, imageRight, text, imageSize |
||
if isSmall then |
if isSmall then |
||
smallClass = data.smallClass or 'mbox-small' |
|||
image = args.smallimage or args.image |
image = args.smallimage or args.image |
||
imageRight = args.smallimageright or args.imageright |
imageRight = args.smallimageright or args.imageright |
||
text = args.smalltext or args.text |
text = args.smalltext or args.text |
||
imageSize = '30x30px' |
imageSize = data.imageSmallSize or '30x30px' |
||
else |
else |
||
image = args.image |
image = args.image |
||
Line 67: | Line 70: | ||
-- Get the box structure. |
-- Get the box structure. |
||
local root, box, row = generateBoxStructure() |
local root, substCheck, box, row, imageLeftCell = generateBoxStructure() |
||
-- Do the subst check. |
|||
if data.substCheck and args.subst == 'SUBST' then |
|||
if type(args.name) == 'string' then |
|||
substCheck |
|||
.wikitext(mw.ustring.format( |
|||
'Template <code>%s%s%s</code> has been incorrectly substituted.', |
|||
mw.text.nowiki('{{'), |
|||
args.name, |
|||
mw.text.nowiki('}}') |
|||
⚫ | |||
end |
|||
root.wikitext('[[Category:Pages with incorrectly substituted templates]]') -- This puts the category at the *end* of the output, rather than after the subst error message. |
|||
end |
|||
-- Build the box. |
-- Build the box. |
||
Line 77: | Line 94: | ||
end |
end |
||
box |
box |
||
.addClass(isSmall and |
.addClass(isSmall and smallClass) |
||
.addClass(data.classPlainlinksYesno and yesno(args.plainlinks or true) and 'plainlinks') |
.addClass(data.classPlainlinksYesno and yesno(args.plainlinks or true) and 'plainlinks') |
||
.addClass(typeData.class) |
.addClass(typeData.class) |
||
Line 85: | Line 102: | ||
-- Add the left-hand image. |
-- Add the left-hand image. |
||
local imageCheckBlank = data.imageCheckBlank |
|||
⚫ | |||
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then |
|||
⚫ | |||
imageLeftCell |
|||
.addClass('mbox-image') |
.addClass('mbox-image') |
||
if not isSmall and data.imageCellDiv then |
|||
imageLeftCell = imageLeftCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageLeftCell so that the image is inside it. |
|||
end |
|||
imageLeftCell |
|||
.wikitext(image or mw.ustring.format('[[File:%s|%s|link=|alt=]]', typeData.image, imageSize)) |
.wikitext(image or mw.ustring.format('[[File:%s|%s|link=|alt=]]', typeData.image, imageSize)) |
||
elseif data.imageEmptyCell then |
elseif data.imageEmptyCell then |
||
Line 134: | Line 156: | ||
end |
end |
||
return tostring(root) |
return tostring(root) |
||
end |
|||
function p._ambox(args) |
|||
local data = {} |
|||
data.types = { |
|||
speedy = { |
|||
class = 'ambox-speedy', |
|||
image = 'Ambox speedy deletion.png' |
|||
}, |
|||
delete = { |
|||
class = 'ambox-delete', |
|||
image = 'Ambox deletion.png' |
|||
}, |
|||
content = { |
|||
class = 'ambox-content', |
|||
image = 'Ambox content.png' |
|||
}, |
|||
style = { |
|||
class = 'ambox-style', |
|||
image = 'Edit-clear.svg' |
|||
}, |
|||
move = { |
|||
class = 'ambox-move', |
|||
⚫ | |||
}, |
|||
protection = { |
|||
class = 'ambox-protection', |
|||
image = 'Ambox protection.png' |
|||
}, |
|||
notice = { |
|||
class = 'ambox-notice', |
|||
image = 'Ambox notice.png' |
|||
} |
|||
} |
|||
data.default = 'notice' |
|||
data.allowSmall = true |
|||
data.substCheck = true |
|||
data.classes = {'metadata', 'plainlinks', 'ambox'} |
|||
data.smallClass = 'mbox-small-left' |
|||
data.imageEmptyCell = true |
|||
data.imageCheckBlank = true |
|||
data.imageSmallSize = '20x20px' |
|||
data.imageCellDiv = true |
|||
data.talkLink = true |
|||
return p.build(data, args) |
|||
end |
end |
||
Line 355: | Line 422: | ||
end |
end |
||
p.ambox = makeWrapper(p._ambox) |
|||
p.fmbox = makeWrapper(p._fmbox) |
p.fmbox = makeWrapper(p._fmbox) |
||
p.imbox = makeWrapper(p._imbox) |
p.imbox = makeWrapper(p._imbox) |