The editors' meeting has been canceled for technical reasons.
Module:Message box
Jump to navigation
Jump to search
Template:Documentation header 此模块用于实现{{Message box}}。使用方法见模板文档。
依赖项
- Module:Direct link
- Module:ProcessArgs
- Module:Sprite
- mw:extension:TemplateStyles:{{Message box/styles.css}}
-- Define a new module
local p = {}
-- Function to generate a sprite with comments
function commentSprite(pos, link)
if not pos or mw.text.trim(pos) == '' then
return ''
end
return require('Module:Sprite').base{
name = 'Comment',
pos = pos,
image = 'CommentCSS.png',
sheetsize = 48,
stylesheet = 1,
link = link
}
end
-- Main function
function p.main(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
-- Process title and text arguments
local rawTitle = frame:preprocess(frame:getParent().args.title)
local rawText = frame:preprocess(frame:getParent().args.text)
-- Create the main message box container
local result = mw.html.create('div')
:addClass('msgbox searchaux')
:addClass('msgbox-' .. (args.type or 'notice'))
:addClass(args.class)
:cssText(args.css)
:css{
['background-color'] = args.bgcol,
['border-left-color'] = args.linecol,
['font-size'] = args['font-size'],
['width'] = args.width or (args.compat and 'fit-content' or nil),
}
if args.mini then
result:addClass('msgbox-mini')
end
-- Add optional icon or image
if args.icon or args.image then
result:addClass('has-image')
local resultOpt = mw.html.create('div')
:addClass('msgbox-icon-image')
:cssText(args.imagecss)
local imagefield = ''
if args.icon then
imagefield = imagefield .. commentSprite(args.icon, args.iconlink)
end
if args.image then
imagefield = table.concat{
imagefield, '[[',
'File:', mw.text.split(args.image, '|', true)[1],
'|link=', mw.text.split(args.imagelink or '', '|', true)[1],
'|', args.imagesize or (args.mini and '16px' or '32px'),
args.imageclass and ('|class=' .. args.imageclass) or '',
'|', 'text-top',
']]'
}
end
resultOpt:wikitext(
frame:preprocess(args.imagetextbefore or '') ..
imagefield ..
frame:preprocess(args.imagetextafter or '')
)
result:node(resultOpt)
end
-- Create the body of the message box
local resultNext = mw.html.create('div')
:addClass('msgbox-body')
:addClass('align-' .. (args['text-align'] or 'left'))
:cssText(args.textcss)
-- Add optional title
if args.title then
local resultNextTitle = mw.html.create('div'):addClass('msgbox-title')
local resultNextTitleText = "<b>" .. rawTitle .. "</b>"
if args.customaction then
resultNextTitleText = resultNextTitleText .. '<sup>' .. frame:preprocess(args.customaction) .. '</sup>'
end
if args.discuss or args.discussPage or args.discussAnchor then
local directLinkTarget = args.discussPage or mw.title.getCurrentTitle().talkPageTitle.fullText
if args.discussAnchor then
directLinkTarget = directLinkTarget .. '#' .. args.discussAnchor
end
local discussText = ' <sup>' .. require('Module:Direct link').main{directLinkTarget, 'Discuss'} .. '</sup>'
if args.linkshere then
discussText = discussText .. ' <sup>[[Special:WhatLinksHere/' .. mw.title.getCurrentTitle().fullText .. '|' .. require('Module:STConversion').call{['en'] = 'Links here'} .. ']]</sup>'
end
resultNextTitleText = resultNextTitleText .. discussText
end
resultNextTitle:wikitext(resultNextTitleText)
resultNext:node(resultNextTitle)
end
-- Add optional text content
if args.text then
resultNext:tag('div'):addClass('msgbox-text'):wikitext('<p>\n' .. rawText .. '\n</p>')
end
-- Add the body to the main container
result:node(resultNext)
-- Load template styles
result = require('Module:TSLoader').call('Template:Message box/styles.css') .. tostring(result)
-- Add tracking categories
if args.bgcol then
result = result .. '[[Category:Pages using the bgcol parameter in Message box]]'
end
if args.linecol then
result = result .. '[[Category:Pages using the linecol parameter in Message box]]'
end
return result
end
return p