Module:Biblio/Ouvrage
local Ouvrage = { }
local Commun = require( 'Module:Biblio/Commun' )
local References = require( 'Module:Biblio/Références' )
local Outils = require( 'Module:Outils' )
local TableBuilder = require( 'Module:TableBuilder' )
local Langue -- = require( 'Module:Langue' ) ne sera chargé que si nécessaire.
function Ouvrage.chapitre( args )
-- validArg renvoi 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 Outils.validTextArg( args, ... ) end
-- titreChap est un paramètre différents de ceux du modèle ouvrage pour utilisé le même programme args.titreChap = validArg( 'titre chapitre', 'chap', 'titre' ) args.titre = validArg( 'titre ouvrage', 'titre' ) if args.titre == args.titreChap then args.titre = nil end args['titre chapitre'] = nil args.chap = nil args['sous-titre chapitre'] = validArg( 'sous-titre chapitre', 'sous-titre' ) args['sous-titre'] = validArg( 'sous-titre ouvrage', 'sous-titre' ) if args['sous-titre chapitre'] == args['sous-titre'] then args['sous-titre'] = nil end args['lien titre'] = validArg( 'lien titre ouvrage', 'lien titre' ) return require( 'Module:Biblio/Ouvrage' ).ouvrage( args, true ) end
function Ouvrage.ouvrage( args, chapitre )
-- La table wiki va recevoir tout les petits bouts de texte, et sera concaténtée à la fin.
-- Elle utilise la metat-table de TableBuilder, permettant d'utiliser les fonctions de la
-- librairy table comme des mèthodes. minsert permet d'insérer plusieurs élément en une
-- seule fois en, ignorant les paramètre nil.
local wiki = TableBuilder.new()
-- validArg renvoi 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 Outils.validTextArg( args, ... ) end local genre = ( chapitre and 'chapitre' ) or 'ouvrage'
--Variables servant à la catégorisation local categTitre, categTitreChapitre, categTitreOuvrage, categLangue
-- clarification paramètre nécéssaire pour les coins args.titre = validArg( 'titre', 'title' )
-- COinS, id et libelé
wiki.minsert( Commun.COinS( args, validArg, genre ) )
wiki.minsert( Commun.spanInitial ( args, validArg ) )
local libelle = validArg( 'libellé' )
if libelle then
wiki.minsert( '[', libelle, '] ' )
end
-- indication de langue local incdicLangue, codeLangue, categLangue = Commun.indicationDeLangue ( args, validArg ) wiki.minsert( incdicLangue, ' ' )
-- Liste des auteurs et de leur responsabilités (principale et secondaire) if validArg( 'nom1', 'nom', 'auteur', 'auteurs', 'last1', 'last', 'author1', 'author' ) then if validArg( 'auteurs' ) then wiki.minsert( args.auteurs ) else wiki.minsert( Commun.responsabilitePrincipale( args, validArg, true ) ) end local coauteur = validArg( 'co-auteur', 'coauteurs' ) if coauteur then wiki.minsert( ', ', coauteur ) end wiki.minsert( Commun.responsabiliteSecondaire( args, validArg ), ', ' ) end
-- Pour le modèle chapitre : affichage du chapitre
if chapitre then
if args.titreChap then
wiki.minsert( '« ', args.titreChap )
if args['sous-titre chapitre'] then
wiki.minsert( ( codeLangue and ': ' ) or ' : ', args['sous-titre chapitre'] )
end
wiki.minsert( ' »' )
else
wiki.minsert( Outils.erreur( 'paramètre « titre chapitre » manquant' ) )
categTitreChapitre = true
end
local auteurOuvrage = validArg( 'auteurs ouvrage' ) if auteurOuvrage or agrs.titre then wiki.minsert( ', dans ' ) if auteurOuvrage then wiki.minsert( auteurOuvrage, ', ' ) end else wiki.minsert( ' ' ) end end
-- titre if args.titre then if codeLangue then Langue = Langue or require( 'Module:Langue' ) local dir = Langue.directionLangue( codeLangue ) if dir == 'rtl' then dir = '" dir="rtl' else dir = nil end
wiki.minsert( '') else wiki.minsert( '') end local lienTitre = validArg( 'lien titre' ) if lienTitre then wiki.minsert( '' ) end wiki.minsert( args.titre ) local sousTitre = validArg( 'sous-titre' ) if sousTitre then wiki.minsert( ( codeLangue and ': ' ) or ' : ', sousTitre ) end if lienTitre then wiki.minsert( '' ) end wiki.minsert( '' )
local original = validArg( 'titre original', 'titre vo' )
if original and original ~= args.titre then
wiki.minsert( ' [« ', original, ' »]' )
end
else
if chapitre then
wiki.minsert( Outils.erreur( 'paramètre « titre ouvrage » manquant' ) )
categTitreOuvrage = true
else
wiki.minsert( Outils.erreur( 'paramètre « titre » manquant' ) )
categTitre = true
end
end
-- volume, tome
local volume = validArg( 'volume', 'vol' )
if volume then
wiki.minsert( ', ', Commun.vol, volume )
end
local tome = validArg( 'tome' )
if tome then
wiki.minsert( ', ', Commun.tome, tome )
end
local titreVolTome = validArg( 'titre volume', 'titre tome' )
if titreVolTome then
if volume or tome then
wiki.minsert( '' )
else
wiki.minsert( , '' )
end
if codeLangue then
Langue = Langue or require( 'Module:Langue' )
wiki.minsert( Langue.lang{ codeLangue, titreVolTome }, '' )
else
wiki.minsert( titreVolTome, '' )
end
end
-- références local reference = validArg( 'référence' ) if reference then wiki.minsert( ' ', Commun.detailEditions( reference ) ) else local lieu = validArg( 'lieu' ) if lieu then wiki.minsert( ', ', lieu ) end local editeur = validArg( 'éditeur', 'édition' ) if editeur then local lienEditeur = validArg( 'lien éditeur' ) if lienEditeur then wiki.minsert( ', ', editeur, '' ) else wiki.minsert( ', ', editeur ) end end local refSimple = validArg( 'référence simplifiée', 'ref' ) local annee = validArg( 'année', 'date' ) if refSimple then if annee then wiki.minsert( ', ', annee ) end wiki.minsert( ' ', Commun.detailEdition( refSimple ) ) else local collection = validArg( 'collection' ) if collection then wiki.minsert( ', ', Commun.coll, '« ', collection ) local serie = validArg( 'série' ) if serie then wiki.minsert( ' / ', serie ) end wiki.minsert( ' »' ) end local numeroCollection = validArg( 'numéro dans collection' ) if numeroCollection then wiki.minsert( ' (', Commun.numero, numeroCollection, ')' ) end if annee then wiki.minsert( ', ', Commun.inscriptionDate( args ) ) end local publi = validArg( 'réimpression', 'publi' ) if publi then wiki.minsert( ' ', Commun.reimpr, publi ) end local numeroEdition = validArg( "numéro d'édition" ) if numeroEdition then wiki.minsert( ', ', Outils.ordinal( numeroEdition, true ), Commun.ed ) end local premiereEdition = validArg( 'année première édition', 'origyear' ) if premiereEdition then wiki.minsert( ' (', Commun.premiere, Commun.ed, premiereEdition ) end local format = validArg( 'format' ) if format then wiki.minsert( ', ', format ) end local pages = validArg( 'pages totales', 'pages' ) if pages then wiki.minsert( ', ', pages, Commun.nbp ) end
end
end
-- références ISBN, oclc, lccn, bnf... if validArg( 'isbn', 'lire en ligne', 'présentation en ligne', 'oclc', 'url', 'lccn', 'issn', 'bnf', 'ISBN', 'isbn1', 'ISSN', 'dnb', 'doi', 'jstor', 'url texte', 'pmid', 'résumé' ) then local enligne = TableBuilder.new( )
enligne.minsert( References.isbn( args, validArg ), References.issn( args, validArg ) )
enligne.minsert( References.oclc( validArg( 'oclc' ) ), References.bnf ( validArg( 'bnf' ) ), References.lccn( validArg( 'lccn' ) ), References.dnb ( validArg( 'dnb' ) ), References.doi( validArg( 'doi' ) ), References.pmid( validArg( 'pmid' ) ), References.jstor( validArg( 'jstor' ) ) )
local url = validArg( 'lire en ligne', 'url', 'url texte' ) if url then enligne.insert( References.enLigne{ lien = url, texte = 'lire en ligne', } ) end local ecouterEnLigne = validArg( 'écouter en ligne' ) if ecouterEnLigne then enligne.insert( References.enLigne{ lien = ecouterEnLigne, texte = 'écouter en ligne', } ) end local resume = validArg( 'présentation en ligne', 'résumé' ) if resume then enligne.insert( References.enLigne{ lien = resume, texte = 'présentation en ligne', } ) end
local cousulteLe = validArg( 'consulté le', 'accessdate', 'consulté' ) if cousulteLe then enligne.insert( 'consulté le ' .. Outils.nobr( cousulteLe ) ) end
wiki.minsert( ' ', mw.text.nowiki( '[' ), enligne.concat( ', ' ), ']' ) end
-- précision sue le passage concerné local numChapitrePartie local partie = validArg( 'partie' ) if partie then wiki.minsert( ', partie ', Commun.romain( partie ) ) numChapitrePartie = true end local numeroChapitre = validArg( 'numéro chapitre', 'numéro' ) if numeroChapitre then wiki.minsert( ', ', Commun.chap, numeroChapitre ) numChapitrePartie = true end local titreChapitre = validArg( 'titre chapitre', 'chap' ) if titreChapitre then if numChapitrePartie then wiki.minsert( ' (« ', titreChapitre, ' »)' ) else wiki.minsert( ', « ', titreChapitre, ' »' ) end end local passage = validArg( 'passage', 'page' ) if passage then wiki.minsert( ', ', Commun.page, passage ) end
-- fin des span (COinS et id) et de la description de l'ouvrage wiki.minsert( '' )
-- citation et commentaire de cet ouvrage local citation = validArg( 'extrait', 'citation' ) if citation then
wiki.minsert( ' :
', citation, '
' )
end if validArg( 'plume' ) then wiki.minsert( Commun.plume ) end wiki.minsert( Commun.commentaire( args ) )
if mw.title.getCurrentTitle().namespace == 0 then
wiki.minsert(
categLangue and ,
categTitre and ,
categTitreChapitre and ,
categTitreOuvrage and
)
end
return wiki.concat()
end
return Ouvrage