模块:Message box:修订间差异
imported>Jimmy Xu 小 保护 模块:Message box:高风险模板([编辑=仅管理员](无限期)[移动=仅管理员](无限期)) |
imported>Alexander Misel |
||
| 第3行: | 第3行: | ||
-- Require necessary modules. | -- Require necessary modules. | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local categoryHandler = require('Module:Category handler').main | local categoryHandler = require('Module:Category handler').main | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
| 第489行: | 第488行: | ||
function box:export() | function box:export() | ||
local root = | local root = mw.html.create() | ||
-- Add the subst check error. | -- Add the subst check error. | ||
if self.isSubstituted and self.name then | if self.isSubstituted and self.name then | ||
root | root | ||
:tag('b') | |||
:addClass('error') | |||
:wikitext(format( | |||
'模板<code>%s[[Template:%s|%s]]%s</code>被錯誤地替代。', | '模板<code>%s[[Template:%s|%s]]%s</code>被錯誤地替代。', | ||
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | ||
| 第503行: | 第502行: | ||
-- Create the box table. | -- Create the box table. | ||
local boxTable = root | local boxTable = root:tag('table') | ||
boxTable | boxTable | ||
:attr('id', self.id) | |||
for i, class in ipairs(self.classes or {}) do | for i, class in ipairs(self.classes or {}) do | ||
boxTable | boxTable | ||
:addClass(class) | |||
end | end | ||
boxTable | boxTable | ||
:cssText(self.style) | |||
:attr('role', 'presentation') | |||
-- Add the left-hand image. | -- Add the left-hand image. | ||
local row = boxTable | local row = boxTable:tag('tr') | ||
if self.imageLeft then | if self.imageLeft then | ||
local imageLeftCell = row | local imageLeftCell = row:tag('td'):addClass('mbox-image') | ||
if self.imageCellDiv then | if self.imageCellDiv then | ||
-- If we are using a div, redefine imageLeftCell so that the image is inside it. | -- If we are using a div, redefine imageLeftCell so that the image is inside it. | ||
| 第523行: | 第522行: | ||
-- images in a div are wider than that, they may overlap with the text or cause | -- images in a div are wider than that, they may overlap with the text or cause | ||
-- other display problems. | -- other display problems. | ||
imageLeftCell = imageLeftCell | imageLeftCell = imageLeftCell:tag('div'):css('width', '52px') | ||
end | end | ||
imageLeftCell | imageLeftCell | ||
:wikitext(self.imageLeft) | |||
elseif self.imageEmptyCell then | elseif self.imageEmptyCell then | ||
-- Some message boxes define an empty cell if no image is specified, and some don't. | -- Some message boxes define an empty cell if no image is specified, and some don't. | ||
-- The old template code in templates where empty cells are specified gives the following hint: | -- The old template code in templates where empty cells are specified gives the following hint: | ||
-- "No image. Cell with some width or padding necessary for text cell to have 100% width." | -- "No image. Cell with some width or padding necessary for text cell to have 100% width." | ||
row | row:tag('td') | ||
:addClass('mbox-empty-cell') | |||
:cssText(self.imageEmptyCellStyle) | |||
end | end | ||
-- Add the text. | -- Add the text. | ||
local textCell = row | local textCell = row:tag('td'):addClass('mbox-text') | ||
if self.useCollapsibleTextFields then | if self.useCollapsibleTextFields then | ||
-- The message box uses advanced text parameters that allow things to be collapsible. At the | -- The message box uses advanced text parameters that allow things to be collapsible. At the | ||
-- moment, only ambox uses this. | -- moment, only ambox uses this. | ||
textCell | textCell | ||
:cssText(self.textstyle) | |||
local textCellSpan = textCell | local textCellSpan = textCell:tag('span') | ||
textCellSpan | textCellSpan | ||
:addClass('mbox-text-span') | |||
:wikitext(self.issue) | |||
if not self.isSmall then | if not self.isSmall then | ||
textCellSpan | textCellSpan | ||
:tag('span') | |||
:addClass('hide-when-compact') | |||
:wikitext(self.talk and self.talk) | |||
end | end | ||
textCellSpan | textCellSpan | ||
:wikitext(self.date and self.date) | |||
if not self.isSmall and self.fix ~= '' then | if not self.isSmall and self.fix ~= '' then | ||
textCellSpan | textCellSpan | ||
:tag('span') | |||
:addClass('hide-when-compact') | |||
:wikitext(self.fix and self.fix) | |||
end | end | ||
if not self.isSmall then | if not self.isSmall then | ||
textCellSpan | textCellSpan | ||
:tag('span') | |||
:addClass('hide-when-compact') | |||
:wikitext(self.info and self.info) | |||
end | end | ||
else | else | ||
-- Default text formatting - anything goes. | -- Default text formatting - anything goes. | ||
textCell | textCell | ||
:cssText(self.textstyle) | |||
:wikitext(self.text) | |||
end | end | ||
-- Add the right-hand image. | -- Add the right-hand image. | ||
if self.imageRight then | if self.imageRight then | ||
local imageRightCell = row | local imageRightCell = row:tag('td'):addClass('mbox-imageright') | ||
if self.imageCellDiv then | if self.imageCellDiv then | ||
imageRightCell = imageRightCell | imageRightCell = imageRightCell:tag('div'):css('width', '52px') -- If we are using a div, redefine imageRightCell so that the image is inside it. | ||
end | end | ||
imageRightCell | imageRightCell | ||
:wikitext(self.imageRight) | |||
end | end | ||
-- Add the below row. | -- Add the below row. | ||
if self.below then | if self.below then | ||
boxTable | boxTable:tag('tr') | ||
:tag('td') | |||
:attr('colspan', self.imageRight and '3' or '2') | |||
:addClass('mbox-text') | |||
:cssText(self.textstyle) | |||
:wikitext(self.below) | |||
end | end | ||
| 第597行: | 第596行: | ||
if self.invalidTypeError then | if self.invalidTypeError then | ||
root | root | ||
:tag('div') | |||
:css('text-align', 'center') | |||
:wikitext(format('本訊息框使用無效的「type=%s」參數,需要修復。', self.type or '')) | |||
end | end | ||
-- Add categories. | -- Add categories. | ||
root | root | ||
:wikitext(self.categories) | |||
return tostring(root) | return tostring(root) | ||