Module:Message box and Module:Message box/sandbox/2: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
Copy from sandbox per request |
use require('strict') instead of require('Module:No globals') |
||
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('strict') |
require('strict') |
||
local getArgs |
local getArgs |
||
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() |
||
-- Define constants |
|||
local CONFIG_MODULE = 'Module:Message box/configuration' |
local CONFIG_MODULE = 'Module:Message box/configuration' |
||
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'} |
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'} |
||
Line 155: | Line 162: | ||
self.typeClass = typeData.class |
self.typeClass = typeData.class |
||
self.typeImage = typeData.image |
self.typeImage = typeData.image |
||
self.typeImageNeedsLink = typeData.imageNeedsLink |
|||
-- Find if the box has been wrongly substituted. |
-- Find if the box has been wrongly substituted. |
||
Line 188: | Line 194: | ||
-- Set text style. |
-- Set text style. |
||
self.textstyle = args.textstyle |
self.textstyle = args.textstyle |
||
⚫ | |||
-- Set image classes. |
|||
self.imageRightClass = args.imagerightclass or args.imageclass |
|||
self.imageLeftClass = args.imageleftclass or args.imageclass |
|||
-- Find if we are on the template page or not. This functionality is only |
-- Find if we are on the template page or not. This functionality is only |
||
Line 268: | Line 270: | ||
local talkText |
local talkText |
||
if self.isSmall then |
if self.isSmall then |
||
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. |
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk) |
||
talkText = string.format('([[%s|talk]])', talkLink) |
talkText = string.format('([[%s|talk]])', talkLink) |
||
else |
else |
||
Line 281: | Line 283: | ||
else |
else |
||
talkText = string.format( |
talkText = string.format( |
||
'%s the [[%s |
'%s the [[%s#%s|talk page]].', |
||
talkText, |
talkText, |
||
talkTitle.prefixedText, |
talkTitle.prefixedText, |
||
Line 301: | Line 303: | ||
end |
end |
||
if date then |
if date then |
||
self.date = string.format(" <span class='date-container'> |
self.date = string.format(" <span class='date-container'>''(<span class='date'>%s</span>)''</span>", date) |
||
end |
end |
||
self.info = args.info |
self.info = args.info |
||
Line 323: | Line 325: | ||
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:0;width:1px' |
|||
end |
|||
-- Left image settings. |
-- Left image settings. |
||
Line 334: | Line 339: | ||
and (cfg.imageSmallSize or '30x30px') |
and (cfg.imageSmallSize or '30x30px') |
||
or '40x40px' |
or '40x40px' |
||
self.imageLeft = string.format('[[File:%s|%s |
self.imageLeft = string.format('[[File:%s|%s|link=|alt=]]', self.typeImage |
||
or ' |
or 'Imbox notice.png', imageSize) |
||
end |
end |
||
end |
end |
||
Line 346: | Line 351: | ||
-- set templatestyles |
-- set templatestyles |
||
self.base_templatestyles = cfg.templatestyles |
|||
self.templatestyles = args.templatestyles |
self.templatestyles = args.templatestyles |
||
-- check for using demospace = image to see if we can safely remove it |
|||
if args.demospace == 'image' then |
|||
self.isUsingDemospaceImage = true |
|||
end |
|||
end |
end |
||
Line 440: | Line 449: | ||
if self.isSubstituted then |
if self.isSubstituted then |
||
self:addCat('all', 'Pages with incorrectly substituted templates') |
self:addCat('all', 'Pages with incorrectly substituted templates') |
||
end |
|||
if self.isUsingDemospaceImage then |
|||
self:addCat('all', 'Wikipedia message box demospace parameter using deprecated value image') |
|||
end |
end |
||
end |
end |
||
Line 448: | Line 460: | ||
elseif self.title.namespace == 10 then |
elseif self.title.namespace == 10 then |
||
self:setTemplateCategories() |
self:setTemplateCategories() |
||
end |
|||
self:setAllNamespaceCategories() |
self:setAllNamespaceCategories() |
||
end |
end |
||
Line 482: | Line 494: | ||
)) |
)) |
||
end |
end |
||
⚫ | |||
⚫ | |||
root:wikitext(frame:extensionTag{ |
|||
name = 'templatestyles', |
|||
args = { src = self.base_templatestyles }, |
|||
}) |
|||
-- Add support for a single custom templatestyles sheet. Undocumented as |
-- Add support for a single custom templatestyles sheet. Undocumented as |
||
-- need should be limited and many templates using mbox are substed; we |
-- need should be limited and many templates using mbox are substed; we |
||
-- don't want to spread templatestyles sheets around to arbitrary places |
-- don't want to spread templatestyles sheets around to arbitrary places |
||
-- TODO: Add each template's stylesheet, waiting on [[MediaWiki talk:Common.css/to do]] |
|||
⚫ | |||
if self.templatestyles then |
if self.templatestyles then |
||
root:wikitext(frame:extensionTag{ |
root:wikitext(frame:extensionTag{ |
||
Line 521: | Line 530: | ||
-- 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 |
imageLeftCell:wikitext(self.imageLeft or nil) |
||
:addClass(self.imageLeftClass) |
|||
:wikitext(self.imageLeft or nil) |
|||
elseif self.imageEmptyCell then |
elseif self.imageEmptyCell then |
||
-- Some message boxes define an empty cell if no image is specified, and |
-- Some message boxes define an empty cell if no image is specified, and |
||
Line 533: | Line 540: | ||
row:tag('td') |
row:tag('td') |
||
:addClass('mbox-empty-cell') |
:addClass('mbox-empty-cell') |
||
:cssText(self.imageEmptyCellStyle or nil) |
|||
end |
end |
||
Line 577: | Line 585: | ||
-- 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 |
||
:addClass(self.imageRightClass) |
|||
:wikitext(self.imageRight or nil) |
:wikitext(self.imageRight or nil) |
||
end |
end |
||
Line 597: | Line 604: | ||
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.', |