Открыть меню
Открыть персональное меню
Вы не представились системе
Your IP address will be publicly visible if you make any edits.

Модуль:Mbox: различия между версиями

Материал из Create Wiki
м (Защитил страницу Модуль:Mbox: важная техническая страница ([Редактирование=Разрешено только администраторам] (бессрочно) [Переименование=Разрешено только администраторам] (бессрочно)))
м (1 версия импортирована)
 
(не показана 1 промежуточная версия 1 участника)
Строка 2: Строка 2:
local checkType = libraryUtil.checkType
local checkType = libraryUtil.checkType
local mArguments -- lazily initialise [[Module:Arguments]]
local mArguments -- lazily initialise [[Module:Arguments]]
local mError -- lazily initialise [[Module:Error]]
local mError     -- lazily initialise [[Module:Error]]


local p = {}
local p = {}
Строка 13: Строка 13:
local function makeWikitextError( msg )
local function makeWikitextError( msg )
mError = require( 'Module:Error' )
mError = require( 'Module:Error' )
return mError.error{
return mError.error {
message = 'Error: ' .. msg .. '.'
message = 'Error: ' .. msg .. '.'
}
}
Строка 19: Строка 19:


function p.mbox( frame )
function p.mbox( frame )
local args = getArgs( frame )
mArguments = require( 'Module:Arguments' )
local title = args[1] or args[ 'title' ]
local args = mArguments.getArgs( frame )
local text = args[2] or args[ 'text' ]
local title = args[ 1 ] or args[ 'title' ]
if not s then
local text = args[ 2 ] or args[ 'text' ]
return p.makeWikitextError(
if not title or not text then
'no text specified',
return makeWikitextError(
'Template:Mbox#Errors',
'no title or text specified'
args.category
)
)
end
end
Строка 53: Строка 52:


local mboxTitle = mbox:tag( 'div' ):addClass( 'mbox-title' )
local mboxTitle = mbox:tag( 'div' ):addClass( 'mbox-title' )
 
if options.icon and type( options.icon ) == 'string' then
if options.icon and type( options.icon ) == 'string' then
mboxTitle:tag( 'div' )
mboxTitle:tag( 'div' )
Строка 60: Строка 59:
:done()
:done()
:tag( 'div' )
:tag( 'div' )
:wikitext( title )
:wikitext( title )
else
else
mboxTitle:wikitext( title )
mboxTitle:wikitext( title )
Строка 69: Строка 68:
:wikitext( text )
:wikitext( text )


return mw.getCurrentFrame():extensionTag{
return mw.getCurrentFrame():extensionTag {
name = 'templatestyles', args = { src = 'Module:Mbox/styles.css' }
name = 'templatestyles', args = { src = 'Module:Mbox/styles.css' }
} .. tostring(mbox)
} .. tostring( mbox )
end
end


return p
return p

Текущая версия от 22:55, 29 февраля 2024

Для документации этого модуля может быть создана страница Модуль:Mbox/doc

local libraryUtil = require( 'libraryUtil' )
local checkType = libraryUtil.checkType
local mArguments -- lazily initialise [[Module:Arguments]]
local mError     -- lazily initialise [[Module:Error]]

local p = {}

--- Helper function to throw error
--
-- @param msg string - Error message
--
-- @return string - Formatted error message in wikitext
local function makeWikitextError( msg )
	mError = require( 'Module:Error' )
	return mError.error {
		message = 'Error: ' .. msg .. '.'
	}
end

function p.mbox( frame )
	mArguments = require( 'Module:Arguments' )
	local args = mArguments.getArgs( frame )
	local title = args[ 1 ] or args[ 'title' ]
	local text = args[ 2 ] or args[ 'text' ]
	if not title or not text then
		return makeWikitextError(
			'no title or text specified'
		)
	end
	return p._mbox( title, text, {
		extraclasses = args.extraclasses,
		icon = args.icon
	} )
end

function p._mbox( title, text, options )
	checkType( '_mbox', 1, title, 'string' )
	checkType( '_mbox', 2, text, 'string' )
	checkType( '_mbox', 3, options, 'table', true )

	options = options or {}
	local mbox = mw.html.create( 'div' )
	local extraclasses
	if type( options.extraclasses ) == 'string' then
		extraclasses = options.extraclasses
	end

	mbox
		:attr( 'role', 'presentation' )
		:addClass( 'mbox' )
		:addClass( extraclasses )

	local mboxTitle = mbox:tag( 'div' ):addClass( 'mbox-title' )

	if options.icon and type( options.icon ) == 'string' then
		mboxTitle:tag( 'div' )
			:addClass( 'mbox-icon metadata' )
			:wikitext( '[[File:' .. options.icon .. '|14px|link=]]' )
			:done()
			:tag( 'div' )
			:wikitext( title )
	else
		mboxTitle:wikitext( title )
	end

	mbox:tag( 'div' )
		:addClass( 'mbox-text' )
		:wikitext( text )

	return mw.getCurrentFrame():extensionTag {
		name = 'templatestyles', args = { src = 'Module:Mbox/styles.css' }
	} .. tostring( mbox )
end

return p
Сайт использует Cookie для нормальной работы