Module:Fix

De Vouiquipèdia, l’enciclopèdia abada.

La documentation pour ce module peut être créée à Module:Fix/doc

local p = {}

local function atfotadeCadro( contegnu )
	if contegnu:match( '\n[ \t]*\n' ) -- ligne vide (donc plusieurs paragraphes)
	or contegnu:match( '\n[*#:]' )    -- liste à puces, liste numérotée, indentation
	then
		return true
	else
		return false
	end
end

-- utilisé par {{Citation}} et {{Citation étrangère}}
function p.atfotadeCadro( frame )
	local contegnu = frame.args[ 1 ]
	if atfotadeCadro( contegnu ) then
		return '1'
	else
		return ''
	end
end

local function afichajoBloco( args )
	local background = args.background or ''
	if background == '' then
		background = 'white'
	end

	local html = mw.html.create( '' )
		:wikitext( '\n' )
		:tag( 'div' )
			:cssText( 'position:relative; margin-top:0.8em;' )
			:tag( 'div' )
				:addClass( 'need_ref' )
				:cssText( 'cursor:help; overflow:hidden; padding-bottom:0;' )
				:css{ background = background }
				:attr{ title = args.titro }
				:wikitext( args[ 1 ], '\n' )
				:done()
			:tag( 'div' )
				:addClass( 'need_ref_tag' )
				:cssText( 'position:absolute; top:-0.6em; left:1em; padding:0 0.5em; font-size:80%; line-height:1em;' )
				:css{ background = background }
				:wikitext( args.message2 )
		:allDone()

	return tostring( html )
end

local function afichajoInline( args, apondreenfobula )
	local html = mw.html.create( '' )

	if args[ 1 ] and args[ 1 ]:match( '%S' ) then
		html:tag( 'span' )
				:addClass( 'need_ref' )
				:cssText( 'cursor:help;' )
				:attr{ title = args.titro }
				:wikitext( mw.text.trim( args[ 1 ] ) )
				:done()
		apondreenfobula = false -- Facultatif, on pourrait accepter l'infobulle sur l'exposant quel que soit le cas.
	end
	if apondreenfobula then
		html:tag( 'sup' )
			:addClass( 'need_ref_tag' )
			:cssText ( 'padding-left:2px;' )
			:attr{ title = args.titro2 }
			:wikitext( args.message2 )
		:allDone()
	else
		html:tag( 'sup' )
			:addClass( 'need_ref_tag' )
			:cssText ( 'padding-left:2px;' )
			:wikitext( args.message2 )
		:allDone()
	end

	return tostring( html )
end

local function generateMessage( args, nommodelo, formaenfobula ) -- Le dernier paramètre sert de booléen pour forcer une infobulle dans le lien interne.
	local formaenfobula = formaenfobula or false
	local messageloc = ''
	local enfobula_mesa = false
	if args.message and args.message ~= '' then
		local ciba
    	if args.message_lim and args.message_lim ~= '' then
    		if args.message_lim == 'non' then
				ciba = false
			else
				ciba = args.message_lim
			end
		else
			ciba = args.message
		end

		if ciba then
			if ciba:sub( 1, 1 ) == ':' then
				ciba = ciba:sub( 2 )
			end
			if formaenfobula == true then -- On force l'infobulle à l'intérieur. Il y aurait peut-être plus smple, avec un seul message et l'ajout d'une classe désactivant les infobulles sur les liens internes
				messageloc = '[[:' .. ciba .. '|' .. '<span title="' .. args.titro2 ..'">&#91;' .. args.message .. '&#93;</span>' .. ']]'
				enfobula_mesa = true
			else
				messageloc = '[[:' .. ciba .. '|&#91;' .. args.message .. '&#93;]]'
				enfobula_mesa = true -- Facultatif mais on peut bien considérer inutile d'ajouter une autre infobulle autour de ce contenu. Cela est encore plus vrai si lien interne créé à la ligne précédente est sur l'intégralité du message.
			end
		else
			messageloc = '&#91;' .. args.message .. '&#93;'
			if not args.message:find( '%[%[' ) then
				args.titro2 = args.titro
			end
		end

		-- trois lignes qui suivent : test temporaire à activer lors de la transition d'affichage pour les appels qui introduisent déjà un lien via le paramètre message
		if ( args.message:find( '%[' ) or args.message:find( '%]' ) ) and ( args.message_lim or '' ) ~= 'nan' then
			messageloc = args.message
		end
	else
		messageloc = '<span class="error">argument « message » manquent dens lo modèlo ' .. nommodelo .. '.</span>'
		args.titro2 = "Fôta dens l’apèl du modèlo Fix"
	end

	return messageloc, enfobula_mesa
end

function p.afichajoFix( frame )
	local args = frame.getParent and frame:getParent().args or frame
	local nommodelo = frame.getParent and frame:getParent():getTitle() or frame:getTitle()
	local messageData = ''
	local messageEde = ' ; v'
	local ponctuacion = '.'
	if args.date and args.date ~= '' then
		messageData = ' (demandâ lo ' .. args.date .. ')'
	else
		local enfobula_texto = mw.text.trim( ( args.enfobula or '' ):gsub( '%b<>', '' ) )
		if enfobula_texto ~= '' then
			if enfobula_texto:match( '[!?…]$' ) then
				messageEde = ' V'
				ponctuacion = ''
			end
		else
			messageEde = 'V'
			ponctuacion = ''
		end
	end
	messageEde = messageEde .. 'êre l\'éde.'
	args.titro = mw.text.trim( ( args.enfobula or '' ):gsub( '[,.;:]$', '' ) ) .. messageData .. ponctuacion
	args.titro2 = mw.text.trim( ( args.enfobula or '' ):gsub( '[,.;:]$', '' ) ) .. messageData .. messageEde

	if args[ 1 ] and args[ 1 ]:match( '%S' ) then
		args.message2, enfobula_mesa = generateMessage( args, nommodelo )
		if atfotadeCadro( args[ 1 ] ) or args.bloco and args.bloco ~= '' then -- attention, on ne trimme pas args[ 1 ]
			return afichajoBloco( args )
		end
	else
		args.message2, enfobula_mesa = generateMessage( args, nommodelo, true )
	end

	return afichajoInline( args, not enfobula_mesa )
end

return p