Module:Biblio/Ôvra

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

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

local Ovra = { }


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


function Ovra.chapitro( args )
	-- validArg renvoie le premier paramètre non vide, ou nil s'ils sont tous vides.
	-- Seul les noms des paramètres doivent être transmis à la fonction.
	local validArg = function ( ... ) return Comon.validTextArg( args, ... ) end
	
	-- titroChap est un paramètre différent de ceux du modèle ouvrage pour utiliser le même programme
	args.numChap = validArg( 'numerô chapitro' )
	args.titroChap = validArg( 'titro chapitro', 'chap', 'titro', 'title' )
	if args.titro == args.titroChap then
		args.titro = false
	end
	args.titro = validArg( 'titro ôvra', 'ôvra', 'titro', 'title' ) or false
	args['numerô chapitro'] = false
	args['titro chapitro'] = false
	args.chap = false
	args['sot-titro chapitro'] = validArg( 'sot-titro chapitro', 'sot-titro' ) or false
	args['sot-titro'] = validArg( 'sot-titro ôvra', 'sot-titro' )
	if args['sot-titro chapitro'] == args['sot-titro'] then
		args['sot-titro'] = false
	end
	args['lim titro'] = validArg( 'lim titro ôvra', 'lim titro' )
	local preface = validArg( 'téta de lévro' )
	local otorOvra = validArg( 'ôtors ôvra', 'ôtor ôvra' )
	if preface and otorOvra then
		args['ôtors ôvra'] = ( validArg( 'ôtors ôvra', 'ôtor ôvra' ) or '' ) .. ' (téta de l. ' .. preface .. ')'
		args['téta de lévro'] = ''
	end
	return Ovra.ovra( args, true )
end


function Ovra.ovra( args, chapitro )
	-- 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
	-- librairie table comme des méthodes. minsert permet d'insérer plusieurs éléments en une
	-- seule fois en, ignorant les paramètres nil.
	local wiki = TableBuilder.new()
	
	-- validArg renvoie le premier paramètre non vide, ou nil s'ils sont tous vides.
	-- Seul les noms des paramètres doivent être transmis à la fonction.
	local validArg = function ( ... ) return Comon.validTextArg( args, ... ) or false end
	local genro = ( chapitro and 'chapitro' ) or 'ôvra'
	
	--Table servant à la catégorisation
	args.categ = {}

	local formaNormala = not validArg( 'nocat' )
	
	-- Clarification des paramètres  nécessaires pour les COinS
	args.titro = validArg( 'titro', 'title' )
	args['pâges totâles'] = validArg( 'pâges totâles', 'pâges', 'soma' )
	args.pages = ''
	local limDeDefor = validArg( 'liére en legne', 'url tèxto', 'url', 'tèxto' )
	if args.format and not args['format èlèctronico'] and limDeDefor and string.match( args.format,"pdf" ) then
		args['format èlèctronico'] = args.format
		args.format = false
	end
	
	
	-- span initial (id) et libellé
	local spanInitial, spanFinal = Comon.spanInitial ( args, validArg )
	wiki.minsert( spanInitial,  Comon.libela( args ) )
	
	-- Indication de langue
	local endicLengoua, codeLengoua = Comon.endicacionDeLengoua ( args, validArg )
	local dir, atributsLengoua
	if endicLengoua and endicLengoua ~= '' then
		wiki.minsert( endicLengoua, ' ' )
		if codeLengoua then
			dir = Lengoua.direccionLengoua( codeLengoua )
			if dir == 'rtl' then 
				atributsLengoua = ' lang="' .. codeLengoua .. '" dir="rtl"'
			else 
				dir = nil
				atributsLengoua = ' lang="' .. codeLengoua .. '"'
			end
		end
	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 ) )
		end
		local cotor = validArg( 'co-ôtor', 'côtors', 'côtor', 'coauthors' )
		if cotor then
			wiki.minsert( ', ', cotor )
		end
		wiki.minsert( Comon.responsabilitatSecondera( args, validArg ), ', ' )
	end
	
	-- Pour le modèle chapitro : affichage du chapitro
	if chapitro then
		if args.numChap then
			wiki.minsert( Comon.chap, args.numChap, ' ' )
		end
		if args.titroChap then
			wiki.minsert( '<cite style="font-style:normal"', atributsLengoua, '>« ', args.titroChap )
			if args['sot-titro chapitro'] then
				wiki.minsert( ' : ', args['sot-titro chapitro'] )
			end
			wiki.minsert( ' »</cite>' )
		elseif formaNormala then
			wiki.minsert( '<span class="error">[[Modèlo:Chapitro|{{Chapitro}}]] : paramètro <code>titro chapitro</code> manquent</span>' )
			args.categ.titroChapitro = true
		end
		
		wiki.minsert( ', dedens ' )
		
		local otorOvra = validArg( 'ôtors ôvra', 'ôtor ôvra' )
		if otorOvra then
			wiki.minsert( otorOvra, ', ' )
		end
	end
	
	-- Titro
	if args.titro then
		local titro, sotTitro = args.titro, validArg( 'sot-titro' )
		-- retrait italique, ne doit normalement pas être mis mais l'erreur est très fréquente
		titro = titro:gsub( "^''%f[^'](.+)%f[']''$", "%1" )
		if sotTitro then
			-- retrait italique, erreur moins fréquente avec les sous-titres mais autant être consistant
			sotTitro = sotTitro:gsub( "^''%f[^'](.+)%f[']''$", "%1" )
			titro =  titro .. ' : ' .. sotTitro
		end
		titro = Comon.fusionTextoLim( titro, args['lim titro'], args.categ )
		local grafia = ' class="etalico"'
		if Lengoua.pasLatin( titro ) then
			grafia = ' style="font-style:normal"'
		end
		wiki.minsert( '<cite', grafia, atributsLengoua, '>', titro, '</cite>' )
		
	elseif formaNormala then
		if chapitro then
			args.categ.titroOvra = true
			if args.categ.titroChapitro then
				wiki.minsert( '<span class="error">paramètro <code>titro ôvra</code> manquent</span>' )
			else
				wiki.minsert( '<span class="error">[[Modèlo:Chapitro|{{Chapitro}}]] : paramètro <code>titro ôvra</code> manquent</span>' )
			end
		else
			args.categ.titro = true
			wiki.minsert( '<span class="error">[[Modèle:Ôvra|{{Ôvra}}]] : paramètro <code>titro</code> manquent</span>' )
		end
	end
	
	-- Titre original et traducteur
	local original = validArg( 'titro originâl', 'titro vo', 'traduccion titro' )
	if original and original ~= args.titro then
		if validArg( 'lengoua originâla' ) then
			wiki.minsert( ' [« ', Lengoua.lengoua{ args['lengoua originâla'], original }, ' »]' )
		else
			wiki.minsert( ' [« ', original, ' »]' )
		end
	end
	if not otor then
		local responsabilitatSecondera = Comon.responsabilitatSecondera( args, validArg )
		if responsabilitatSecondera then
			wiki.minsert( ' ', responsabilitatSecondera )
		end
	end
		
	-- Volume, tome
	local volumo = validArg( 'volumo', 'vol' )
	if volumo then
		wiki.minsert( ', ', Comon.vol, volumo )
	end
	local levro = validArg( 'lévro' )
	if levro then
		wiki.minsert( ', ', Comon.levro, levro )
	end
	local titroVolLevro = validArg( 'titro volumo', 'titro lévro' )
	if titroVolLevro then
		if volumo or levro then
			wiki.minsert( ' : ' )
		else
			wiki.minsert( ', ' )
		end
		if codeLengoua then
			wiki.minsert( Lengoua.lengoua{ codeLengoua, titroVolLevro, class='etalico' } )
		else
			wiki.minsert( '<span class="etalico">', titroVolLevro,  '</span>' )
		end
		local tradTitroVolLevro = validArg( 'traduccion titro volumo', 'traduccion titro lévro' )
		if tradTitroVolLevro then
			wiki.minsert( ' [« ', tradTitroVolLevro, ' »]' )
		end
	end
	
	-- Nature du document et établissement (pour les thèses...)
	local natura = validArg( 'natura ôvra' )
	if natura then
		wiki.minsert( ' (', natura, ')')
	end
	local etablissement = validArg( 'ètablissement' )
	if etablissement then
		wiki.minsert( ', ', etablissement )
	end
	
	-- Lieu et éditeur
	local endret = validArg( 'endrêt', 'locacion' )
	if endret then
		wiki.minsert( ', ', endret )
	end
	local editor = validArg( 'èditor', 'èdicion', 'edition', 'publisher' )
	if editor then
		local limEditor = validArg( 'lim èditor' )
		wiki.minsert( ', ', Comon.fusionTextoLim( editor, limEditor, args.categ ) )
	end
	
	-- Collecion et numéro
	local coleccion = validArg( 'colèccion', 'series' )
	if coleccion then
		wiki.minsert( ', ', Comon.col, '« ', coleccion )
		local seria = validArg( 'sèria' )
		if seria then
			wiki.minsert( ' / ', seria )
		end
		wiki.minsert( ' »' )
	end
	local numeroColeccion = validArg( 'numerô dedens colèccion', 'numerô dedens la colèccion' )
	if numeroColeccion then
		wiki.minsert( ' (', Comon.numero, numeroColeccion, ')' )
	end
	
	-- Date, réimpression et éditions
	local an = validArg( 'an', 'date', 'year' )
	if an then
		local lrm
		if Lengoua.pasLatin( wiki.concat() ) then
			lrm = '&lrm;'
		end
		wiki.minsert( ',', lrm, ' ', Comon.enscripcionData( args ) )
		-- le &lrm est une marque de texte gauche à droite, utile si le texte qui précède est en droite à gauche (arabe, hébreux...)
	end
	local publi = validArg( 'remprèssion', 'publi' )
	if publi then
		wiki.minsert( ' (', Comon.rempr, publi, ')' )
	end
	local numeroEdicion = validArg( "numerô d’èdicion", "numerô èdicion"  )
	if numeroEdicion then
		wiki.minsert( ', ', Nombro2texto.ordenal( numeroEdicion, true ), Comon.ed )
	end
	local premiereEdicion = validArg( 'an premiére èdition', 'origyear' )
	if premiereEdicion then
		wiki.minsert( ' (', Comon.premiere, Comon.ed, ' ', premiereEdicion, ')' )
	end
	
	-- Pages et format
	local pages = validArg( 'pâges totâles', 'pâges', 'soma' )
	if pages then
		wiki.minsert( ', ', pages, Comon.nbp )
	end
	local format = validArg( 'format lévro', 'format' )
	if format then
		wiki.minsert( ', ', format )
	end
		
	-- Références
	local reference = validArg( 'rèference' )
	if reference then
		wiki.minsert( ' ', Comon.detalyEdicions( reference ) )
	end
	local refSimpla = validArg( 'rèference simplifiâye', 'rèf', 'ref' )
	if refSimpla then
		wiki.minsert( ' ', Comon.detalyEdicion( refSimpla ) )
	end
	

	-- Lien vers l'ouvrage en ligne (isbn, issn, pmid, doi, lire en ligne, résumé...)
	wiki.minsert( References.afichajoLimsDeDefor( args, validArg, true, false ) )
	-- consulté le n'est plus affiché, voir [[Discussion_modèlo:Ôvra#Èvolucion documentacion]]
	
	-- Précision sur le passage concerné
	local partia = validArg( 'partia' )
	if partia then
		if string.match ( partia, '^[%dIVXLCM]+$' ) then
			wiki.minsert( ', partia&nbsp;', partia )
		elseif string.match ( partia, '^[ivxlcmIVXLCM]+$' ) then
			wiki.minsert( ', partia&nbsp;',  Comon.romen( partia ) )
		else
			wiki.minsert( ', ', partia )
		end
	end
	local numeroChapitro = validArg( 'numerô chapitro', 'numerô' )
	if numeroChapitro then
		wiki.minsert( ', ', Comon.chap, numeroChapitro )
	end
	local titroChapitro = validArg( 'titro chapitro', 'chap', 'chapitro', 'chapter' )
	if titroChapitro then
		if numeroChapitro then
			titroChapitro = ' (« ' .. titroChapitro .. ' »)'
		else
			titroChapitro = ', « ' .. titroChapitro .. ' »'
		end
		if codeLengoua then
			titroChapitro = Lengoua.lengoua{ codeLengoua, titroChapitro }
		end
		wiki.minsert( titroChapitro )
		local tradTitroChap = validArg( 'traduccion titro chapitro' )
		if tradTitroChap then
			wiki.minsert( ' [« ', tradTitroChap, ' »]' )
		end
	end
	local passajo = validArg( 'passâjo', 'pâge' )
	if passajo then
		if string.match ( passajo, '^[%dIVXLCM]' ) then
			wiki.minsert( ', ', Comon.page, passajo )
		else
			wiki.minsert( ', ', passajo )
		end
	end
	
	-- Ajout des méthadonnées COinS (ContextObjects in Spans)
	wiki.minsert( Comon.COinS( args, validArg, genro ) )
	
	-- Fin du span (id) et de la description de l'ouvrage
	wiki.minsert( spanFinal )
	
	-- Plume "Ôvra utilisé pour la rédaction de l'article"
	if validArg( 'ploma' ) then
		local patternPonct = '[,.;:!?]$'
		local ponctuacion = wiki.concat():gsub( '%b<>', '' ):match( patternPonct )
		if not ponctuacion then
			wiki.minsert( '.' )
		end
		wiki.minsert( Comon.ploma )
	end
	
	-- Citation et commentaire de cet ouvrage
	local citacion = validArg( 'èxtrèt', 'citacion' )
	if citacion then
		if codeLengoua then
			citacion = Lengoua.lang{ codeLengoua, citacion }
		end
		wiki.minsert( '&nbsp;:<blockquote>«&nbsp;', citacion, '&nbsp;»</blockquote>' )
	end
		
	wiki.minsert( Comon.comentero( args ) )
	
	local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true, [104] = true }
	if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] and formaNormala then
		wiki.minsert(
			args.categ.lengoua and '[[Catègorie:Pâge du modèlo Ôvra que contint na fôta|lengoua]]',
			args.categ.titro and '[[Catègorie:Pâge du modèlo Ôvra que contint na fôta|titro]]',
			args.categ.titroChapitro and '[[Catègorie:Pâge du modèlo Chapitro que contint na fôta|Chapitro]]',
			args.categ.titroOvra and '[[Catègorie:Pâge du modèlo Chapitro que contint na fôta|Ovra]]',
			args.categ.limDeDefor and '[[Catègorie:Pâge du modèlo Ôvra que contint na fôta|DeDefor]]',
			args.categ.isbnInvalid and '[[Catègorie:Pâge avouéc ISBN envalido]]',
			args.categ.issnInvalid and '[[Catègorie:Pâge avouéc ISSN envalido]]',
			args.categ.eanInvalid and '[[Catègorie:Pâge avouéc EAN envalido]]'
		)
		if dir then
			wiki.minsert( '[[Catègorie:Recension temporèra por lo modèlo Ôvra|rtl]]' )
		end
	end

	
	return wiki.concat()
end


return Ovra