The editors' meeting has been canceled for technical reasons.

Module:Message box: Difference between revisions

From NeuroWiki
Jump to navigation Jump to search
m 1 revision imported
No edit summary
 
Line 1: Line 1:
-- Define a new module
local p = {}
local p = {}


function commentSprite( pos, link )
-- Function to generate a sprite with comments
if not pos or mw.text.trim( pos ) == '' then
function commentSprite(pos, link)
if not pos or mw.text.trim(pos) == '' then
return ''
return ''
end
end
return require( 'Module:Sprite' ).base{ name = 'Comment', pos = pos, image = 'CommentCSS.png', sheetsize = 48, stylesheet = 1, link = link }
return require('Module:Sprite').base{
name = 'Comment',
pos = pos,
image = 'CommentCSS.png',
sheetsize = 48,
stylesheet = 1,
link = link
}
end
end


function p.main( f )
-- Main function
function p.main(f)
local args = f
local args = f
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
if f == frame then
if f == frame then
args = require( 'Module:ProcessArgs' ).merge( true )
args = require('Module:ProcessArgs').merge(true)
end
end


local rawTitle = frame:preprocess( frame:getParent().args.title )
-- Process title and text arguments
local rawText = frame:preprocess( frame:getParent().args.text )
local rawTitle = frame:preprocess(frame:getParent().args.title)
local rawText = frame:preprocess(frame:getParent().args.text)


-- Create main frame
-- 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{
local result = mw.html.create('div')
[ 'background-color' ] = args.bgcol,
:addClass('msgbox searchaux')
[ 'border-left-color' ] = args.linecol,
:addClass('msgbox-' .. (args.type or 'notice'))
[ 'font-size' ] = args[ 'font-size' ],
:addClass(args.class)
[ 'width' ] = args.width or ( args.compat and 'fit-content' or nil ),
: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
if args.mini then
result:addClass( 'msgbox-mini' )
result:addClass('msgbox-mini')
end
end


-- Create optional icon / image frame
-- Add optional icon or image
if args.icon or args.image then
if args.icon or args.image then
result:addClass( 'has-image' )
result:addClass('has-image')
local resultOpt = mw.html.create( 'div' ):addClass( 'msgbox-icon-image' ):cssText( args.imagecss )
local resultOpt = mw.html.create('div')
:addClass('msgbox-icon-image')
:cssText(args.imagecss)
 
local imagefield = ''
local imagefield = ''
if args.icon then
if args.icon then
imagefield = imagefield .. commentSprite( args.icon, args.iconlink )
imagefield = imagefield .. commentSprite(args.icon, args.iconlink)
end
end
if args.image then
if args.image then
imagefield = table.concat{
imagefield = table.concat{
imagefield, '[[',
imagefield, '[[',
'File:', mw.text.split( args.image, '|', true )[ 1 ],
'File:', mw.text.split(args.image, '|', true)[1],
'|link=', mw.text.split( args.imagelink or '', '|', true )[ 1 ],
'|link=', mw.text.split(args.imagelink or '', '|', true)[1],
'|', args.imagesize or ( args.mini and '16px' or '32px' ),
'|', args.imagesize or (args.mini and '16px' or '32px'),
args.imageclass and ( '|class=' .. args.imageclass ) or '',
args.imageclass and ('|class=' .. args.imageclass) or '',
'|', 'text-top',
'|', 'text-top',
']]'
']]'
}
}
end
end
resultOpt:wikitext( frame:preprocess( args.imagetextbefore or '' ) .. imagefield .. frame:preprocess ( args.imagetextafter or '' ) )
resultOpt:wikitext(
result:node( resultOpt )
frame:preprocess(args.imagetextbefore or '') ..
imagefield ..
frame:preprocess(args.imagetextafter or '')
)
result:node(resultOpt)
end
end


-- Create displaytext frame
-- 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 )
local resultNext = mw.html.create('div')
-- Create optional title frame inside displaytext frame
:addClass('msgbox-body')
:addClass('align-' .. (args['text-align'] or 'left'))
:cssText(args.textcss)
 
-- Add optional title
if args.title then
if args.title then
local resultNextTitle = mw.html.create( 'div' ):addClass( 'msgbox-title' )
local resultNextTitle = mw.html.create('div'):addClass('msgbox-title')
local resultNextTitleText = "<b>" .. rawTitle .. "</b>"
local resultNextTitleText = "<b>" .. rawTitle .. "</b>"
if args.customaction then
if args.customaction then
resultNextTitleText = resultNextTitleText .. '<sup>' .. frame:preprocess( args.customaction ) .. '</sup>'
resultNextTitleText = resultNextTitleText .. '<sup>' .. frame:preprocess(args.customaction) .. '</sup>'
end
end
if args.discuss or args.discussPage or args.discussAnchor then
if args.discuss or args.discussPage or args.discussAnchor then
Line 66: Line 93:
directLinkTarget = directLinkTarget .. '#' .. args.discussAnchor
directLinkTarget = directLinkTarget .. '#' .. args.discussAnchor
end
end
local discussText = '&nbsp;<sup>' .. require( 'Module:Direct link' ).main{ directLinkTarget, '讨论' } .. '</sup>'
local discussText = '&nbsp;<sup>' .. require('Module:Direct link').main{directLinkTarget, 'Discuss'} .. '</sup>'
if args.linkshere then
if args.linkshere then
discussText = discussText .. '&nbsp;<sup>[[Special:WhatLinksHere/' .. mw.title.getCurrentTitle().fullText .. '|' .. require( 'Module:STConversion' ).call{ [ 'zh-cn'] = '链入', [ 'zh-tw' ] = '連入' } .. ']]</sup>'
discussText = discussText .. '&nbsp;<sup>[[Special:WhatLinksHere/' .. mw.title.getCurrentTitle().fullText .. '|' .. require('Module:STConversion').call{['en'] = 'Links here'} .. ']]</sup>'
end
end
resultNextTitleText = resultNextTitleText .. discussText
resultNextTitleText = resultNextTitleText .. discussText
end
end
resultNextTitle:wikitext( resultNextTitleText )
resultNextTitle:wikitext(resultNextTitleText)
resultNext:node( resultNextTitle )
resultNext:node(resultNextTitle)
end
end
-- Create optional text frame inside displaytext frame, after optional title frame
 
-- Add optional text content
if args.text then
if args.text then
resultNext:tag( 'div' ):addClass( 'msgbox-text' ):wikitext( '<p>\n' .. rawText .. '\n</p>' )
resultNext:tag('div'):addClass('msgbox-text'):wikitext('<p>\n' .. rawText .. '\n</p>')
end
end
-- Add displaytext frame to main frame
result:node( resultNext )


-- Add templatestyles to final result
-- Add the body to the main container
result = require( 'Module:TSLoader' ).call( 'Template:Message box/styles.css' ) .. tostring( result )
result:node(resultNext)
 
-- Load template styles
result = require('Module:TSLoader').call('Template:Message box/styles.css') .. tostring(result)


-- Append tracking categories
-- Add tracking categories
if args.bgcol then
if args.bgcol then
result = result .. '[[Category:使用Message box的bgcol参数的页面]]'
result = result .. '[[Category:Pages using the bgcol parameter in Message box]]'
end
end
if args.linecol then
if args.linecol then
result = result .. '[[Category:使用Message box的linecol参数的页面]]'
result = result .. '[[Category:Pages using the linecol parameter in Message box]]'
end
end



Latest revision as of 23:26, 12 January 2025

Template:Documentation header 此模块用于实现{{Message box}}。使用方法见模板文档

依赖项




-- 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 = '&nbsp;<sup>' .. require('Module:Direct link').main{directLinkTarget, 'Discuss'} .. '</sup>'
			if args.linkshere then
				discussText = discussText .. '&nbsp;<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