Editing Module:Message box
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
-- This is a meta-module for producing message box templates, including | |||
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}. | |||
-- Load necessary modules. | |||
require('Module:No globals') | require('Module:No globals') | ||
local getArgs | local getArgs | ||
local categoryHandler = require('Module:Category handler')._main | |||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
-- Get a language object for formatDate and ucfirst. | |||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Line 68: | Line 72: | ||
local ns = obj.title.namespace | local ns = obj.title.namespace | ||
-- boxType is "mbox" or invalid input | -- boxType is "mbox" or invalid input | ||
if | if ns == 0 then | ||
obj.cfg = cfg.ambox -- main namespace | obj.cfg = cfg.ambox -- main namespace | ||
elseif ns == 6 then | elseif ns == 6 then | ||
Line 115: | Line 106: | ||
obj.categories = {} | obj.categories = {} | ||
obj.classes = {} | obj.classes = {} | ||
return setmetatable(obj, MessageBox) | return setmetatable(obj, MessageBox) | ||
Line 130: | Line 119: | ||
cat = string.format('[[Category:%s]]', cat) | cat = string.format('[[Category:%s]]', cat) | ||
end | end | ||
self.categories[ns] = self.categories[ns] or {} | self.categories[ns] = self.categories[ns] or {} | ||
table.insert(self.categories[ns], cat) | table.insert(self.categories[ns], cat) | ||
Line 166: | Line 154: | ||
-- Add attributes, classes and styles. | -- Add attributes, classes and styles. | ||
if cfg.allowId then | |||
self.id = args.id | |||
if | |||
self | |||
end | end | ||
self:addClass( | |||
cfg.usePlainlinksParam and yesno(args.plainlinks or true) and 'plainlinks' | |||
) | |||
for _, class in ipairs(cfg.classes or {}) do | for _, class in ipairs(cfg.classes or {}) do | ||
self:addClass(class) | self:addClass(class) | ||
Line 196: | Line 182: | ||
and cfg.templateCategoryRequireName | and cfg.templateCategoryRequireName | ||
then | then | ||
self.name = args.name | |||
if self.name then | if self.name then | ||
local templateName = mw.ustring.match( | local templateName = mw.ustring.match( | ||
Line 207: | Line 194: | ||
and mw.title.equals(self.title, self.templateTitle) | and mw.title.equals(self.title, self.templateTitle) | ||
end | end | ||
-- Process data for collapsible text fields. At the moment these are only | -- Process data for collapsible text fields. At the moment these are only | ||
-- used in {{ambox}}. | -- used in {{ambox}}. | ||
Line 261: | Line 248: | ||
end | end | ||
if talkTitle and talkTitle.exists then | if talkTitle and talkTitle.exists then | ||
local talkText = 'Relevant discussion may be found on' | |||
if talkArgIsTalkPage then | |||
talkText = string.format( | |||
'%s [[%s|%s]].', | |||
talkText, | |||
talk, | |||
talkTitle.prefixedText | |||
) | |||
else | |||
talkText = string.format( | |||
'%s the [[%s#%s|talk page]].', | |||
talkText, | |||
talkTitle.prefixedText, | |||
talk | |||
) | |||
end | |||
self.talk = talkText | self.talk = talkText | ||
end | end | ||
Line 296: | Line 277: | ||
end | end | ||
if date then | if date then | ||
self.date = string.format(" < | self.date = string.format(" <small>''(%s)''</small>", date) | ||
end | end | ||
self.info = args.info | self.info = args.info | ||
end | end | ||
Line 318: | Line 296: | ||
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv | self.imageCellDiv = not self.isSmall and cfg.imageCellDiv | ||
self.imageEmptyCell = cfg.imageEmptyCell | self.imageEmptyCell = cfg.imageEmptyCell | ||
if cfg.imageEmptyCellStyle then | |||
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px' | |||
end | |||
-- Left image settings. | -- Left image settings. | ||
Line 339: | Line 320: | ||
self.imageRight = imageRight | self.imageRight = imageRight | ||
end | end | ||
end | end | ||
Line 448: | Line 425: | ||
function MessageBox:renderCategories() | function MessageBox:renderCategories() | ||
-- Convert category tables to strings and pass them through | -- Convert category tables to strings and pass them through | ||
-- [[Module:Category handler]]. | -- [[Module:Category handler]]. | ||
return | return categoryHandler{ | ||
main = table.concat(self.categories[0] or {}), | main = table.concat(self.categories[0] or {}), | ||
template = table.concat(self.categories[10] or {}), | template = table.concat(self.categories[10] or {}), | ||
Line 476: | Line 447: | ||
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | ||
)) | )) | ||
end | end | ||
Line 516: | Line 472: | ||
-- image width to 52px. If any images in a div are wider than that, | -- image width to 52px. If any images in a div are wider than that, | ||
-- they may overlap with the text or cause other display problems. | -- they may overlap with the text or cause other display problems. | ||
imageLeftCell = imageLeftCell:tag('div'): | imageLeftCell = imageLeftCell:tag('div'):css('width', '52px') | ||
end | end | ||
imageLeftCell:wikitext(self.imageLeft or nil) | imageLeftCell:wikitext(self.imageLeft or nil) | ||
Line 526: | Line 482: | ||
row:tag('td') | row:tag('td') | ||
:addClass('mbox-empty-cell') | :addClass('mbox-empty-cell') | ||
:cssText(self.imageEmptyCellStyle or nil) | |||
end | end | ||
Line 534: | Line 491: | ||
-- collapsible. At the moment, only ambox uses this. | -- collapsible. At the moment, only ambox uses this. | ||
textCell:cssText(self.textstyle or nil) | textCell:cssText(self.textstyle or nil) | ||
local | local textCellSpan = textCell:tag('span') | ||
textCellSpan | |||
:addClass('mbox-text-span') | :addClass('mbox-text-span') | ||
:wikitext(self.issue or nil) | :wikitext(self.issue or nil) | ||
if | if not self.isSmall then | ||
textCellSpan:tag('span') | |||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:wikitext(self.talk and (' ' .. self.talk) or nil) | :wikitext(self.talk and (' ' .. self.talk) or nil) | ||
:wikitext(self.fix and (' ' .. self.fix) or nil) | :wikitext(self.fix and (' ' .. self.fix) or nil) | ||
end | end | ||
textCellSpan:wikitext(self.date and (' ' .. self.date) or nil) | |||
if | if not self.isSmall then | ||
textCellSpan | |||
:tag('span') | :tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:wikitext(self.info and (' ' .. self.info) or nil) | :wikitext(self.info and (' ' .. self.info) or nil) | ||
end | end | ||
else | else | ||
Line 570: | Line 521: | ||
-- If we are using a div, redefine imageRightCell so that the image | -- If we are using a div, redefine imageRightCell so that the image | ||
-- is inside it. | -- is inside it. | ||
imageRightCell = imageRightCell:tag('div'): | imageRightCell = imageRightCell:tag('div'):css('width', '52px') | ||
end | end | ||
imageRightCell | imageRightCell | ||
Line 589: | Line 540: | ||
if self.invalidTypeError then | if self.invalidTypeError then | ||
root:tag('div') | root:tag('div') | ||
: | :css('text-align', 'center') | ||
:wikitext(string.format( | :wikitext(string.format( | ||
'This message box is using an invalid "type=%s" parameter and needs fixing.', | 'This message box is using an invalid "type=%s" parameter and needs fixing.', | ||
Line 616: | Line 567: | ||
function p.main(boxType, args, cfgTables) | function p.main(boxType, args, cfgTables) | ||
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData( | local box = MessageBox.new(boxType, args, cfgTables or mw.loadData('Module:Message box/configuration')) | ||
box:setParameters() | box:setParameters() | ||
box:setCategories() | box:setCategories() |