Modul:Message box: Unterschied zwischen den Versionen
Modul:Message box (Quelltext anzeigen)
Version vom 29. September 2021, 17:41 Uhr
, 17:41, 29. Sep. 2021Special:Diff/4836110; from Special:Diff/4790050
Tt (Diskussion | Beiträge) K (1 Version importiert) |
StadtbahnBI>Mainframe98 |
||
Zeile 13: | Zeile 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'} | ||
local TEMPLATE_STYLES = 'Module:Message box/%s.css' | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Zeile 66: | Zeile 67: | ||
args = args or {} | args = args or {} | ||
local obj = {} | local obj = {} | ||
obj.boxType = boxType | |||
-- Set the title object and the namespace. | -- Set the title object and the namespace. | ||
Zeile 81: | Zeile 84: | ||
-- use template from DEMOSPACES | -- use template from DEMOSPACES | ||
obj.cfg = cfg[DEMOSPACES[demospace]] | obj.cfg = cfg[DEMOSPACES[demospace]] | ||
obj.boxType = 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 | ||
obj.boxType = 'tmbox' | |||
else | else | ||
-- default to ombox | -- default to ombox | ||
obj.cfg = cfg.ombox | obj.cfg = cfg.ombox | ||
obj.boxType = 'ombox' | |||
end | end | ||
elseif ns == 0 then | elseif ns == 0 then | ||
obj.cfg = cfg.ambox -- main namespace | obj.cfg = cfg.ambox -- main namespace | ||
obj.boxType = 'ambox' | |||
elseif ns == 6 then | elseif ns == 6 then | ||
obj.cfg = cfg.imbox -- file namespace | obj.cfg = cfg.imbox -- file namespace | ||
obj.boxType = 'imbox' | |||
elseif ns == 14 then | elseif ns == 14 then | ||
obj.cfg = cfg.cmbox -- category namespace | obj.cfg = cfg.cmbox -- category namespace | ||
obj.boxType = 'cmbox' | |||
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 | ||
obj.boxType = 'tmbox' | |||
else | else | ||
obj.cfg = cfg.ombox -- other namespaces or invalid input | obj.cfg = cfg.ombox -- other namespaces or invalid input | ||
obj.boxType = 'ombox' | |||
end | end | ||
end | end | ||
Zeile 190: | Zeile 201: | ||
self:addClass(args.class) | self:addClass(args.class) | ||
self.style = args.style | self.style = args.style | ||
self.attrs = args.attrs | self.attrs = args.attrs | ||
Zeile 479: | Zeile 488: | ||
)) | )) | ||
end | end | ||
-- Add TemplateStyles | |||
root:wikitext(mw.getCurrentFrame():extensionTag{ | |||
name = 'templatestyles', | |||
args = { src = TEMPLATE_STYLES:format(self.boxType) }, | |||
}) | |||
-- Create the box table. | -- Create the box table. | ||
local boxTable = root:tag('table') | local boxTable | ||
-- Check for fmbox because not all interface messages have mw-parser-output | |||
-- which is necessary for TemplateStyles. Add the wrapper class if it is and | |||
-- then start the actual mbox, else start the mbox. | |||
if self.boxType == 'fmbox' then | |||
boxTable = root:tag('div') | |||
:addClass('mw-parser-output') | |||
:tag('table') | |||
else | |||
boxTable = root:tag('table') | |||
end | |||
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 | ||
Zeile 490: | Zeile 516: | ||
:attr('role', 'presentation') | :attr('role', 'presentation') | ||
if self.attrs then | if self.attrs then | ||
boxTable:attr(self.attrs) | boxTable:attr(self.attrs) |