Module:Biblio/Lim Vouèbe

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

La documentation pour ce module peut être créée à Module:Biblio/Lim Vouèbe/doc

local Lim = { }

local Comon = require( 'Module:Biblio/Comon' )
local References = require( 'Module:Biblio/Rèferences' )
local TableBuilder = require( 'Module:TableBuilder' )


local function formatLim( args, dead )
	-- La table wiki va recevoir tout les petits bouts de texte, et sera concaténée à la fin.
	-- Elle utilise la meta-table de TableBuilder, permettant d'utiliser les fonctions de la
	-- library table comme des méthodes. minsert permet d'insérer plusieurs éléments en une
	-- seule fois en, ignorant les valeurs nil.
	local wiki = TableBuilder.new()
	local modelo = '[[Modèlo:Lim Vouèbe|{{Lim Vouèbe}}]]'
	if dead then
		modelo = '[[Modèlo:Lim câsso|{{Lim câsso}}]]'
	end
	
	-- validArg renvoie le premier paramètre non vide, ou nil s'ils sont tous vides.
	-- Seuls les noms des paramètres doivent être transmis à la fonction.
	local validArg = function ( ... ) return Comon.validTextArg( args, ... ) end
	
	-- Variables servant à la catégorisation
	args.categ = {}
	if validArg( 'dead-url', 'deadurl', 'câsso lo', 'lim câsso' ) then
		dead = true
	end
	
	-- Span initial, id
	local spanInitial, spanFinal = Comon.spanInitial ( args, validArg )
	wiki.minsert( spanInitial,  Comon.libela( args ) )
	
	-- indication de langue
	local endicLengoua, codeLengoua = Comon.endicacionDeLengoua ( args, validArg )
	if endicLengoua and endicLengoua ~= '' then
		wiki.minsert( endicLengoua, ' ' )
	end
	
	-- Liste des auteurs et de leurs responsabilités (principales et secondaires)
	local otor = validArg( 'nom1', 'nom', 'ôtor1', 'ôtor', 'ôtors', 'ôtor enstitucionâl', 'last1', 'last', 'author1', 'author' )
	if otor then
		if validArg( 'ôtors' ) then
			wiki.minsert( args.otors )
		else
			wiki.minsert( Comon.responsabilitatPrincipala( args, validArg, true ) )
		end
		local cootor = validArg( 'co-ôtor', 'coôtors', 'coôtor', 'coauthors' )
		if cootor then
			wiki.minsert( ', ', cootor )
		end
		wiki.minsert( Comon.responsabilitatSecondera( args, validArg ), ', ' )
	end
	
	local url = validArg( 'url', 'liére en legne', 'url tèxto', 'lim' )
	local archiveUrl = validArg( 'archive-url', 'archiveurl' )
	local titro = validArg( 'titro', 'title' )
	local descripcion = validArg( 'dèscripcion' )
	-- url
	if url then
		-- remplacement des crochets et espaces par leur équivalent HTML
		url = url:gsub( '%[', '%%5B' ):gsub( '%]', '%%5D' ):gsub( ' ', '%%20' )
		-- ajout http:// si nécessaire :
		if not ( url:match( '^https?://' ) or url:match( '^ftp://' ) or url:match( '^//' ) ) then
			url = 'http://' .. url
		end
		if dead or archiveUrl then
			wiki.minsert( '<span class="noarchive">' )
		end
		if codeLengoua and titro then
			wiki.minsert( '<span lang="' .. codeLengoua .. '">' )
		end
		wiki.minsert( '[', url )
	elseif not validArg( 'pmid', 'pmcid', 'doi', 'jstor', 'bibcod', 'math reviews', 'zbl', 'zbmath', 'arxiv' ) then
		args.categ.url = true
	end
	
	-- titre
	if titro then
		-- suppression des retours ligne éventuels, sinon MediaWiki ne reconnaît pas le lien externe
		-- et remplacement des crochets par leur équivalent HTML (uniquement le crochet de fermeture)
		titro = titro:gsub( '\n', ' ' ):gsub ( '%]', '&#93;' )
		
		-- on teste d'abord si titre contient déjà des guillemets 
		if titro:match( '^«.+»$' ) then
			wiki.minsert( ' ', titro, url and ']' )
		else
			local sotTitro = validArg( 'sot-titro' )
			if sotTitro then
				sotTitro = ' : ' .. sotTitro
			end
			local color = dead and not archiveUrl and ' color:red;'
			wiki.minsert( ' « <cite style="font-style: normal;', color, '">', titro, sotTitro, '</cite> »', url and ']' )
		end
		if codeLengoua and url then
			wiki.minsert( '</span>' )
		end
		
		-- traduction titre
		local traduccionTitro = validArg( 'traduccion titro' )
		if traduccionTitro and traduccionTitro ~= args.titro then
			wiki.minsert( ' [« ', traduccionTitro, ' »]' )
		end
		if descripcion then
			wiki.minsert( ', ', descripcion )
		end
	elseif descripcion then
		if dead and not archiveUrl then
			wiki.minsert( ' <span style="color:red;">', descripcion, '</span>', url and ']' )
		else
			wiki.minsert( ' ', descripcion, url and ']' )
		end
	else
		args.categ.titro = true
		if url then 
			wiki.minsert( ' ',  url, ']' )
		end
	end
	
	-- message d'erreur
	if args.categ.url or args.categ.titro then
		local absent = { }
		if args.categ.url then
			table.insert( absent, '« <code>url</code> »' )
		end
		if args.categ.titro then
			table.insert( absent, '« <code>titro</code> »' )
		end
		wiki.insert( 1, '<span class="error">Modèlo '
			.. modelo .. ' : paramètro' .. ( #absent > 1 and 's ' or ' ' )
			.. mw.text.listToText( absent ) .. ' manquent' .. ( #absent > 1 and 's' or '' )
			.. '.&ensp;</span>'
		)
	end

	-- liens archives pour les liens brisés
	if url and dead and not archiveUrl then
		wiki.minsert( '<sup class="plainlinks">(',
			'[http://web.archive.org/web/*/', url, ' Archive] • ',
			'[http://archive.wikiwix.com/cache/?url=', url, ' Wikiwix] • ',
			'[http://archive.is/', url, ' Archive.is] • ',
			'[https://www.google.fr/search?q=cache:', url, ' Google] • ',
			'[[Projèt:Corrèccion des lims de defôr#J’é trovâ un lim môrt, que fâre ?|Que fâre ?]])',
			'</sup>'
		)
	elseif archiveUrl then
		if not ( archiveUrl:match( '^http' ) or archiveUrl:match( '^//' ) ) then
			archiveUrl = 'http://' .. archiveUrl
		end
		local textArchive = ' arch·ives'
		local dataArchive = validArg( 'arch·ives-dâta', 'arch·ivesdâta' )
		if dataArchive then
			dataArchive = Comon.enscripcionData{ date = dataArchive }
			textArchive = ' arch·ives du '
		end
		wiki.minsert( ' <small class="plainlinks cachelinks">[[', archiveUrl, textArchive, dataArchive, ']]</small>' )
	end
	if url and ( dead or archiveUrl ) then
		wiki.minsert( '</span>' )
	end
	
	-- format
	wiki.minsert( References.endicacionDeFormat( validArg( 'format èlèctronico', 'format' ) ) )
	
	-- série, site, éditeur
	local seria = validArg( 'sèria', 'work' )
	if seria then
		wiki.minsert( ', <span class="etalico">', seria, '</span>' )
		args.categ.work = validArg( 'work' )	-- il y a ambiguïté sur l'utilisation de ce paramètre
	end
	local seto = validArg( 'seto', 'website' )
	if seto then
		wiki.minsert( ', dessus <span class="etalico">', seto, '</span>' )
	end
	local periodico = validArg( 'pèriodico' )
	if periodico then
		wiki.minsert( ', <i>', periodico, '</i>' )
	end	
	local endret = validArg( 'endrêt', 'endrêt èdicion', 'locacion' )
	if endret then
		wiki.minsert( ', ', endret )
	end	
	local editor = validArg( 'èditor', 'publisher', 'editor' )
	if editor then
		local limEditor = validArg( 'lim èditor' )
		if limEditor then
			wiki.minsert( ', [[', limEditor, '|', editor, ']]' )
		else
			wiki.minsert( ', ', editor )
		end
	end
	
	-- date
	if validArg( 'an', 'dâta', 'year', 'en legne lo', 'en legne' ) then
		local Lengoua = require( 'Module:Lengoua' )
		args.categ.enLegneLo = validArg( 'dâta' ) and validArg( 'en legne lo' ) and args.date ~= args['en legne lo']
		args.date = validArg( 'dâta', 'en legne lo', 'en legne' )
		local lrm
		if Lengoua.pasLatin( wiki.concat() ) then
			lrm = '&lrm; '
		end
		wiki.minsert( ',', lrm, ' ', Comon.enscripcionData( args ) )
	end
	
	-- liens externe (isbn, doi...) et "consulté le" entre parenthèses, et en plus petit, sauf en note
	wiki.minsert( References.afichajoLimsDeDefor( args, validArg, false, true ) )
	
	-- fin du span
	wiki.minsert( spanFinal )
	
	-- citation et passage
	local citacion = validArg( 'citacion', 'èxtrèt', 'quote' )
	if citacion then
		local Lengoua = require( 'Module:Lengoua' )
		if codeLengoua then
			citacion = Lengoua.lang{ codeLengoua, citacion }
		end
		wiki.minsert( ' : <span class="citacion">« ', citacion, ' »</span>' )
	end
	local passajo = validArg( 'pâge', 'pâges', 'passâjo' )
	if passajo then
		if passajo:match( '^[%dIVXLCM]' ) then
			wiki.minsert( ', ', Comon.page, passajo )
		else
			wiki.minsert( ', ', passajo )
		end
	end
	
	-- Ponctuation
	local patternPonct = '[,.;:!?] ?»?$'
	local ponctuacion = mw.ustring.match( wiki.concat():gsub( '%b<>', '' ), patternPonct )
	if not ponctuacion then
		local ponctuacionFinala = validArg( 'ponctuacion finâla' )
		if ponctuacionFinala == ';' then
			ponctuacionFinala = ' ;'
		end
		wiki.minsert( ponctuacionFinala )
	end
	
	if mw.title.getCurrentTitle().namespace == 0 then
		wiki.minsert(
		args.categ.lengoua and '[[Catègorie:Pâge du modèlo Lim Vouèbe que contint na fôta|lengoua]]',
		args.categ.url and '[[Catègorie:Pâge du modèlo Lim Vouèbe que contint na fôta|url]]',
		args.categ.titro and '[[Catègorie:Pâge du modèlo Lim Vouèbe que contint na fôta|titro]]',
		args.categ.enLegneLo and '[[Catègorie:Pâge du modèlo Lim Vouèbe que contint na fôta|enLegneLo]]',
		args.categ.isbnInvalid and '[[Catègorie:Pâge avouéc ISBN envalido]]',
		args.categ.issnInvalid and '[[Catègorie:Pâge avouéc ISSN envalido]]',
		dead and not validArg( 'nocat' ) and '[[Catègorie:Articllo que contint un lim môrt]]'
		)
	elseif dead and not validArg( 'nocat' ) then
		wiki.minsert( '[[Catègorie:Pâge que contint un lim môrt]]' )
	end
	
	return wiki.concat()
end

function Lim.limVouebe( args )
	return formatLim( args, false )
end

function Lim.limCasso( args )
	args.titro = Comon.validTextArg( args, 'titro', 'title', 'url', 'liére en legne', 'url tèxto', 'lim' )
	return formatLim( args, true )
end

return Lim