Module:Message box: Difference between revisions
Jump to navigation
Jump to search
support templatestyles
m (1 revision imported) |
(support templatestyles) |
||
Line 13: | Line 13: | ||
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 67: | Line 66: | ||
args = args or {} | args = args or {} | ||
local obj = {} | local obj = {} | ||
-- Set the title object and the namespace. | -- Set the title object and the namespace. | ||
Line 84: | Line 81: | ||
-- use template from DEMOSPACES | -- use template from DEMOSPACES | ||
obj.cfg = cfg[DEMOSPACES[demospace]] | obj.cfg = cfg[DEMOSPACES[demospace]] | ||
elseif string.find( demospace, 'talk' ) then | elseif string.find( demospace, 'talk' ) then | ||
-- demo as a talk page | -- demo as a talk page | ||
obj.cfg = cfg.tmbox | obj.cfg = cfg.tmbox | ||
else | else | ||
-- default to ombox | -- default to ombox | ||
obj.cfg = cfg.ombox | obj.cfg = cfg.ombox | ||
end | end | ||
elseif ns == 0 then | elseif ns == 0 then | ||
obj.cfg = cfg.ambox -- main namespace | obj.cfg = cfg.ambox -- main namespace | ||
elseif ns == 6 then | elseif ns == 6 then | ||
obj.cfg = cfg.imbox -- file namespace | obj.cfg = cfg.imbox -- file namespace | ||
elseif ns == 14 then | elseif ns == 14 then | ||
obj.cfg = cfg.cmbox -- category namespace | obj.cfg = cfg.cmbox -- category namespace | ||
else | else | ||
local nsTable = mw.site.namespaces[ns] | local nsTable = mw.site.namespaces[ns] | ||
if nsTable and nsTable.isTalk then | if nsTable and nsTable.isTalk then | ||
obj.cfg = cfg.tmbox -- any talk namespace | obj.cfg = cfg.tmbox -- any talk namespace | ||
else | else | ||
obj.cfg = cfg.ombox -- other namespaces or invalid input | obj.cfg = cfg.ombox -- other namespaces or invalid input | ||
end | end | ||
end | end | ||
Line 279: | Line 268: | ||
end | end | ||
if talkTitle and talkTitle.exists then | if talkTitle and talkTitle.exists then | ||
local talkText | |||
if self.isSmall then | |||
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk) | |||
talkText = string.format('([[%s|talk]])', talkLink) | |||
else | |||
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 | |||
end | |||
self.talk = talkText | self.talk = talkText | ||
end | end | ||
Line 308: | Line 303: | ||
end | end | ||
if date then | if date then | ||
self.date = string.format(" < | 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 331: | Line 326: | ||
self.imageEmptyCell = cfg.imageEmptyCell | self.imageEmptyCell = cfg.imageEmptyCell | ||
if cfg.imageEmptyCellStyle then | if cfg.imageEmptyCellStyle then | ||
self.imageEmptyCellStyle = 'border:none;padding: | self.imageEmptyCellStyle = 'border:none;padding:0;width:1px' | ||
end | end | ||
Line 354: | Line 349: | ||
self.imageRight = imageRight | self.imageRight = imageRight | ||
end | end | ||
-- set templatestyles | |||
self.templatestyles = args.templatestyles | |||
end | end | ||
Line 488: | Line 486: | ||
)) | )) | ||
end | end | ||
-- Add | -- Add support for a single custom templatestyles sheet. Undocumented as | ||
-- need should be limited and many templates using mbox are substed; we | |||
-- 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]] | |||
local frame = mw.getCurrentFrame() -- we'll need this unconditionally for the TODO | |||
if self.templatestyles then | |||
root:wikitext(frame:extensionTag{ | |||
name = 'templatestyles', | |||
args = { src = self.templatestyles }, | |||
}) | |||
end | |||
-- Create the box table. | -- Create the box table. | ||
local | local boxTable = root:tag('table') | ||
boxTable:attr('id', self.id or nil) | boxTable:attr('id', self.id or nil) | ||
for i, class in ipairs(self.classes or {}) do | for i, class in ipairs(self.classes or {}) do | ||
Line 552: | Line 545: | ||
:addClass('mbox-text-span') | :addClass('mbox-text-span') | ||
:wikitext(self.issue or nil) | :wikitext(self.issue or nil) | ||
if (self.talk or self.fix) | if (self.talk or self.fix) then | ||
textCellDiv:tag('span') | textCellDiv:tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
Line 566: | Line 559: | ||
end | end | ||
if self.removalNotice then | if self.removalNotice then | ||
textCellDiv:tag(' | textCellDiv:tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:tag('i') | :tag('i') |