|
|
(3 intermediate revisions by 3 users not shown) |
Line 3: |
Line 3: |
|
| |
|
| -- Load necessary modules. | | -- Load necessary modules. |
| require('Module:No globals') | | require('strict') |
| local getArgs | | local getArgs |
| local yesno = require('Module:Yesno') | | local yesno = require('Module:Yesno') |
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'} |
| local TEMPLATE_STYLES = 'Module:Message box/%s.css'
| |
|
| |
|
| -------------------------------------------------------------------------------- | | -------------------------------------------------------------------------------- |
Line 67: |
Line 66: |
| 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. |
Line 84: |
Line 81: |
| -- 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 |
Line 201: |
Line 190: |
| self:addClass(args.class) | | self:addClass(args.class) |
| self.style = args.style | | self.style = args.style |
| | self.lang = args.lang |
| | self.dir = args.dir or (args.lang and 'auto' or nil) |
| self.attrs = args.attrs | | self.attrs = args.attrs |
|
| |
|
Line 488: |
Line 479: |
| )) | | )) |
| 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 | | local boxTable = root:tag('table') |
| -- 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 |
Line 516: |
Line 490: |
| :attr('role', 'presentation') | | :attr('role', 'presentation') |
|
| |
|
| | if self.lang then |
| | boxTable:attr('lang', self.lang) |
| | end |
| | if self.dir then |
| | boxTable:attr('dir', self.dir) |
| | end |
| if self.attrs then | | if self.attrs then |
| boxTable:attr(self.attrs) | | boxTable:attr(self.attrs) |