Module:Message box: Difference between revisions
From WikiOasis Meta
More actions
m 1 revision imported |
add i18n |
||
| Line 2: | Line 2: | ||
local getArgs | local getArgs | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local err = require('Module:Error') | |||
local TNT = require('Module:TNT') | |||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
local int_lang = mw.getCurrentFrame():preprocess('{{int:lang}}') | |||
local CONFIG_MODULE = 'Module:Message box/configuration' | local CONFIG_MODULE = 'Module:Message box/configuration' | ||
local DEMOSPACES = {talk = 'tmbox', image = ' | local DEMOSPACES = {talk = 'tmbox', image = 'mbox', file = 'mbox', category = 'mbox', article = 'mbox', main = 'mbox'} | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Helper functions | -- Helper functions | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function errormsg(text) | |||
-- create warning text | |||
return err.error({tag="span", message=text}) | |||
end | |||
local function getTitleObject(...) | local function getTitleObject(...) | ||
| Line 18: | Line 26: | ||
return title | return title | ||
end | end | ||
end | end | ||
| Line 78: | Line 69: | ||
obj.cfg = cfg.tmbox | obj.cfg = cfg.tmbox | ||
else | else | ||
-- default to | -- default to ambox | ||
obj.cfg = cfg. | obj.cfg = cfg.mbox | ||
end | end | ||
elseif ns == 0 then | elseif ns == 0 then | ||
obj.cfg = cfg. | obj.cfg = cfg.mbox -- main namespace | ||
elseif ns == 6 then | elseif ns == 6 then | ||
obj.cfg = cfg. | obj.cfg = cfg.mbox -- file namespace | ||
elseif ns == 14 then | elseif ns == 14 then | ||
obj.cfg = cfg. | obj.cfg = cfg.mbox -- category namespace | ||
else | else | ||
local nsTable = mw.site.namespaces[ns] | local nsTable = mw.site.namespaces[ns] | ||
| Line 92: | Line 83: | ||
obj.cfg = cfg.tmbox -- any talk namespace | obj.cfg = cfg.tmbox -- any talk namespace | ||
else | else | ||
obj.cfg = cfg. | obj.cfg = cfg.mbox -- other namespaces or invalid input | ||
end | end | ||
end | end | ||
| Line 156: | Line 147: | ||
self.typeImage = typeData.image | self.typeImage = typeData.image | ||
self.typeImageNeedsLink = typeData.imageNeedsLink | self.typeImageNeedsLink = typeData.imageNeedsLink | ||
-- Find whether we are using a small message box. | -- Find whether we are using a small message box. | ||
| Line 189: | Line 177: | ||
self.textstyle = args.textstyle | self.textstyle = args.textstyle | ||
-- Set | -- Set width | ||
self. | self.width = args.width | ||
-- Set margin | |||
-- | self.margin = args.margin | ||
self. | |||
-- Set the non-collapsible text field. At the moment this is used by all box | -- Set the non-collapsible text field. At the moment this is used by all box | ||
-- types other than ambox, and also by ambox when small=yes. | -- types other than ambox, and also by ambox when small=yes. | ||
| Line 333: | Line 207: | ||
local imageSize = self.isSmall | local imageSize = self.isSmall | ||
and (cfg.imageSmallSize or '30x30px') | and (cfg.imageSmallSize or '30x30px') | ||
or ' | or '45x45px' | ||
self.imageLeft = string.format('[[File:%s|%s%s|alt=]]', self.typeImage | self.imageLeft = string.format('[[File:%s|%s%s|alt=]]', self.typeImage | ||
or 'Information icon4.svg', imageSize, self.typeImageNeedsLink and "" or "|link=" ) | or 'Information icon4.svg', imageSize, self.typeImageNeedsLink and "" or "|link=" ) | ||
| Line 348: | Line 222: | ||
self.base_templatestyles = cfg.templatestyles | self.base_templatestyles = cfg.templatestyles | ||
self.templatestyles = args.templatestyles | self.templatestyles = args.templatestyles | ||
end | end | ||
| Line 403: | Line 237: | ||
self:addCat(10, cfg.templateCategory) | self:addCat(10, cfg.templateCategory) | ||
end | end | ||
end | end | ||
end | end | ||
function MessageBox:setAllNamespaceCategories() | function MessageBox:setAllNamespaceCategories() | ||
local cfg = self.cfg | |||
-- Set categories for all namespaces. | -- Set categories for all namespaces. | ||
if self.invalidTypeError then | if self.invalidTypeError then | ||
local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText | local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText | ||
self:addCat('all', ' | self:addCat('all', 'Message box parameter needs fixing', allSort) | ||
end | end | ||
if self. | -- Deprecate license type | ||
self:addCat('all', ' | if self.type == 'license' and cfg.deprecateLicense then | ||
self:addCat('all', 'Licensing templates based on Mbox') | |||
end | end | ||
end | end | ||
function MessageBox:setCategories() | function MessageBox:setCategories() | ||
if | if self.title.namespace == 10 then | ||
self:setTemplateCategories() | self:setTemplateCategories() | ||
end | end | ||
| Line 472: | Line 281: | ||
function MessageBox:export() | function MessageBox:export() | ||
local root = mw.html.create() | local root = mw.html.create() | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
root:wikitext(frame:extensionTag{ | root:wikitext(frame:extensionTag{ | ||
| Line 507: | Line 305: | ||
:cssText(self.style or nil) | :cssText(self.style or nil) | ||
:attr('role', 'presentation') | :attr('role', 'presentation') | ||
if self.width then | |||
boxTable:cssText('width: ' .. self.width) | |||
end | |||
if self.margin then | |||
boxTable:cssText('margin: 2px ' .. self.margin) | |||
end | |||
if self.attrs then | if self.attrs then | ||
boxTable:attr(self.attrs) | boxTable:attr(self.attrs) | ||
| Line 523: | Line 326: | ||
imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div') | imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div') | ||
end | end | ||
imageLeftCell | imageLeftCell: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 580: | Line 381: | ||
end | end | ||
imageRightCell | imageRightCell | ||
:wikitext(self.imageRight or nil) | :wikitext(self.imageRight or nil) | ||
end | end | ||
| Line 598: | Line 398: | ||
root:tag('div') | root:tag('div') | ||
:addClass('mbox-invalid-type') | :addClass('mbox-invalid-type') | ||
:wikitext( | :wikitext(errormsg(TNT.formatInLanguage(int_lang, 'I18n/Message box', 'err-type', self.type or ''))) | ||
end | end | ||