Module:Message box:修订间差异

zhwiki>Shizhao
ep
 
云云​(留言 | 贡献)
小 已保护“Module:Message box”​([编辑=仅允许管理员](无限期)​[移动=仅允许管理员](无限期))
 
(未显示4个用户的6个中间版本)
第1行: 第1行:
-- This is a meta-module for producing message box templates, including {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
-- This is a meta-module for producing message box templates, including {{mbox}}, {{ambox}}, {{tmbox}}, {{ombox}} and {{fmbox}}.


-- Require necessary modules.
-- Require necessary modules.
第60行: 第60行:
table.sort(nums)
table.sort(nums)
return nums
return nums
end
local function insertStyle(cfg)
-- Create the templatestyles tag.
local frame = mw.getCurrentFrame()
return frame:extensionTag{
name = 'templatestyles',
args = { src = cfgTables['@global'].templatestyles },
} .. frame:extensionTag{
name = 'templatestyles',
args = { src = cfg.templatestyles },
}
end
end


第107行: 第93行:
if nsid == 0 then
if nsid == 0 then
return 'ambox' -- main namespace
return 'ambox' -- main namespace
elseif nsid == 6 then
return 'imbox' -- file namespace
elseif nsid == 14 then
return 'cmbox' -- category namespace
else
else
local nsTable = mw.site.namespaces[nsid]
local nsTable = mw.site.namespaces[nsid]
第134行: 第116行:
nsVals[i] = format('"%s"', val)
nsVals[i] = format('"%s"', val)
end
end
error('無效的ns參數傳送到box:addCat;有效的數值為' .. mw.text.listToText(nsVals, '、', '或'))
error('无效的ns参数传送到box:addCat;有效的数值为' .. mw.text.listToText(nsVals, '、', '或'))
end
end
self[tname] = self[tname] or {}
self[tname] = self[tname] or {}
第170行: 第152行:
end
end
tinsert(boxTypes, '"mbox"')
tinsert(boxTypes, '"mbox"')
error(format('無效的訊息框類型「%s」;有效的類型為%s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
error(format('无效的消息框类型「%s」;有效的类型为%s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
end
end
self.cfg = cfg
return cfg
return cfg
end
end


function box:removeBlankArgs(args)
function box:removeBlankArgs(cfg, args)
-- Only allow blank arguments for the parameter names listed in cfg.allowBlankParams.
-- Only allow blank arguments for the parameter names listed in cfg.allowBlankParams.
local newArgs = {}
local newArgs = {}
第184行: 第165行:
end
end
end
end
for i, param in ipairs(self.cfg.allowBlankParams or {}) do
for i, param in ipairs(cfg.allowBlankParams or {}) do
newArgs[param] = args[param]
newArgs[param] = args[param]
end
end
第190行: 第171行:
end
end


function box:setBoxParameters(args)
function box:setBoxParameters(cfg, args)
local cfg = self.cfg
 
-- Get type data.
-- Get type data.
self.type = args.type
self.type = args.type
第225行: 第204行:
end
end
end
end
self:addClass(cfg.usePlainlinksParam and yesno(args.plainlinks or true) and 'plainlinks')
for _, class in ipairs(cfg.classes or {}) do
for _, class in ipairs(cfg.classes or {}) do
self:addClass(class)
self:addClass(class)
第241行: 第219行:
-- Set text style.
-- Set text style.
self.textstyle = args.textstyle
self.textstyle = args.textstyle
self.abovestyle= args.abovestyle
self.belowstyle= args.belowstyle


-- Find if we are on the template page or not. This functionality is only used if useCollapsibleTextFields is set,
-- Find if we are on the template page or not. This functionality is only used if useCollapsibleTextFields is set,
第263行: 第243行:
local sect
local sect
if args.sect == '' then
if args.sect == '' then
sect = '此' .. (cfg.sectionDefault or '頁面')
sect = '此' .. (cfg.sectionDefault or '页面')
elseif type(args.sect) == 'string' then
elseif type(args.sect) == 'string' then
sect = '此' .. args.sect
sect = '此' .. args.sect
第298行: 第278行:
end
end
if talkTitle and talkTitle.exists then
if talkTitle and talkTitle.exists then
local talkText = '相關討論可見於'
local talkText = '相关讨论可见于'
if talkArgIsTalkPage then
if talkArgIsTalkPage then
talkText = format('%s[[%s|%s]]。', talkText, talk, talkTitle.prefixedText)
talkText = format('%s[[%s|%s]]。', talkText, talk, talkTitle.prefixedText)
else
else
talkText = format('%s[[%s#%s|討論頁]]。', talkText, talkTitle.prefixedText, talk)
talkText = format('%s[[%s#%s|讨论页]]。', talkText, talkTitle.prefixedText, talk)
end
end
self.talk = talkText
self.talk = talkText
第327行: 第307行:
end
end
if args.fix and args.fix ~= '' then
if args.fix and args.fix ~= '' then
self.fix = format("<br /><small>%s</small>", args.fix)
self.fix = format("<br><small>%s</small>", args.fix)
else
else
self.fix = ''
self.fix = ''
第341行: 第321行:
self.text = args.text
self.text = args.text
end
end
-- Set the above row.
self.above = args.above


-- Set the below row.
-- Set the below row.
self.below = cfg.below and args.below
self.below = args.below


-- General image settings.
-- General image settings.
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv and true or false
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv and true or false
self.imageEmptyCell = cfg.imageEmptyCell
self.imageEmptyCell = cfg.imageEmptyCell
if cfg.imageEmptyCellStyle then
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px'
end


-- Left image settings.
-- Left image settings.
第359行: 第339行:
self.imageLeft = imageLeft
self.imageLeft = imageLeft
if not imageLeft then
if not imageLeft then
local imageSize = self.isSmall and (cfg.imageSmallSize or '30x30px') or '40x40px'
local imageSize = self.isSmall and (cfg.imageSmallSize or '30x30px') or '40px'
self.imageLeft = format('[[File:%s|%s|link=|alt=]]', self.typeImage or 'Imbox notice.png', imageSize)
local imageFile = self.typeImage or 'Information Mark (Blue).svg'
self.imageLeft = format('[[File:%s|%s|link=File:%s|alt=]]', imageFile, imageSize, imageFile)
end
end
end
end
第504行: 第485行:
end
end
if self.isSubstituted then
if self.isSubstituted then
self:addCat('all', '錯誤使用替換引用的頁面')
self:addCat('all', '错误使用替换引用的页面')
end
end


第531行: 第512行:
))
))
end
end
root:wikitext(insertStyle(self.cfg))


-- Create the box table.
-- Create the box table.
local boxTable = root:tag('table')
local boxTable = root:tag('div')
boxTable
boxTable
:attr('id', self.id)
:attr('id', self.id)
第547行: 第526行:


-- Add the left-hand image.
-- Add the left-hand image.
local row = boxTable:tag('tr')
local row = boxTable:tag('div'):addClass('mbox-body')
if self.imageLeft then
if self.imageLeft then
local imageLeftCell = row:tag('td'):addClass('mbox-image')
local imageLeftCell = row:tag('div'):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.
第555行: 第534行:
-- 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:tag('div'):css('width', '52px')  
imageLeftCell = imageLeftCell:tag('div') --:css('width', '52px')  
end
end
imageLeftCell
imageLeftCell
第563行: 第542行:
-- 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:tag('td')
row:tag('div')
:addClass('mbox-empty-cell')  
:addClass('mbox-empty-cell')  
:cssText(self.imageEmptyCellStyle)
end
 
local textCell = row:tag('div'):addClass('mbox-text')
 
-- Add the above row.
if self.above then
textCell
:tag('div')
:attr('colspan', self.imageRight and '3' or '2')
:addClass('mbox-above')
:cssText(self.abovestyle)
:wikitext(self.above)
end
end


-- Add the text.
-- Add the text.
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
第575行: 第564行:
textCell
textCell
:cssText(self.textstyle)
:cssText(self.textstyle)
local textCellSpan = textCell:tag('div')
local textCellSpan = textCell:tag('span')
textCellSpan
textCellSpan
:addClass('mbox-text-span')
:addClass('mbox-text-span')
第604行: 第593行:
:cssText(self.textstyle)
:cssText(self.textstyle)
:wikitext(self.text)
:wikitext(self.text)
end
-- Add the below row.
if self.below then
textCell
:tag('div')
:attr('colspan', self.imageRight and '3' or '2')
:addClass('mbox-below')
:cssText(self.belowstyle)
:wikitext(self.below)
end
end


-- Add the right-hand image.
-- Add the right-hand image.
if self.imageRight then
if self.imageRight then
local imageRightCell = row:tag('td'):addClass('mbox-imageright')
local imageRightCell = row:tag('div'):addClass('mbox-imageright')
if self.imageCellDiv then
if self.imageCellDiv then
imageRightCell = imageRightCell:tag('div'):css('width', '52px') -- If we are using a div, redefine imageRightCell so that the image is inside it.
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)
:wikitext(self.imageRight)
end
-- Add __DISAMBIG__ for {{dmbox|type=disambig}}
if self.type == 'disambig' then
if self.nsid == '10' then
root:wikitext('[[Category:消歧义消息模板]]')
elseif self.nsid == 0 then
root:wikitext('__DISAMBIG__'):wikitext('[[Category:全部消歧义页面]]')
else
root:wikitext('<!-- omitted -->')
end
end
end


-- Add the below row.
-- Add category for {{dmbox|type=setindex}}
if self.below then
if self.type == 'setindex' then  
boxTable:tag('tr')
if self.nsid == '10' then
:tag('td')
root:wikitext('[[Category:消歧义消息模板]]')
:attr('colspan', self.imageRight and '3' or '2')
else
:addClass('mbox-text')
root:wikitext('__DISAMBIG__')
:cssText(self.textstyle)
end
:wikitext(self.below)
root:wikitext('[[Category:全部设置索引条目]]')
end
end
 
-- Add error message for invalid type parameters.
-- Add error message for invalid type parameters.
if self.invalidTypeError then
if self.invalidTypeError then
第631行: 第641行:
:tag('div')
:tag('div')
:css('text-align', 'center')
:css('text-align', 'center')
:wikitext(format('此訊息框使用無效的「type=%s」參數,需要修復。', self.type or ''))
:wikitext(format('此消息框使用无效的「type=%s」参数,需要修复。', self.type or ''))
end
end


第641行: 第651行:
end
end


local function main(boxType, args)
local function main(boxType, args, frame)
local outputBox = box.new()
local outputBox = box.new()
outputBox:setTitle(args)
outputBox:setTitle(args)
outputBox:getConfig(boxType)
local cfg = outputBox:getConfig(boxType)
args = outputBox:removeBlankArgs(args)
args = outputBox:removeBlankArgs(cfg, args)
outputBox:setBoxParameters(args)
outputBox:setBoxParameters(cfg, args)
return outputBox:export()
local out = outputBox:export()
if frame and frame.extensionTag then
out = frame:extensionTag('templatestyles', '', {src = 'Module:Message box/mbox.css'}) .. out
end
return out
end
end


第653行: 第667行:
return function (frame)
return function (frame)
local args = getArgs(frame, {trim = false, removeBlanks = false})
local args = getArgs(frame, {trim = false, removeBlanks = false})
return main(boxType, args)
return main(boxType, args, frame)
end
end
end
local function insertStyleWikitext(frame)
local args = getArgs(frame, {trim = false, removeBlanks = false})
local boxType = args[1] or 'mbox'
-- // ---- // --
local outputBox = box.new()
outputBox:setTitle(args)
local cfg = outputBox:getConfig(boxType)
return insertStyle(cfg)
end
end


local p = {
local p = {
main = main,
main = main,
mbox = makeWrapper('mbox'),
mbox = makeWrapper('mbox')
insertStyle = insertStyleWikitext
}
}


for boxType in pairs(cfgTables) do
for boxType in pairs(cfgTables) do
if boxType:sub(1, 1) ~= '@' then
p[boxType] = makeWrapper(boxType)
p[boxType] = makeWrapper(boxType)
end
end
end


return p
return p