Différences entre les pages « Module:Biblio/Article » et « Module:Biblio/Ouvrage »

De Les Mots de l'agronomie
< Module:Biblio(Différence entre les pages)
imported>Jacques Ducloy
m (1 révision importée)
 
imported>Jacques Ducloy
m (1 révision importée)
 
Ligne 1 : Ligne 1 :
local Article = { }
+
local Ouvrage = { }
  
  
Ligne 9 : Ligne 9 :
  
  
function Article.article( args )
+
function Ouvrage.chapitre( args )
-- La table wiki va recevoir tout les petits bouts de texte, et sera concaténtée à la fin.
+
-- validArg renvoie le premier paramètre non vide, ou nil s'ils sont tous vides.
-- Elle utilise la metat-table de TableBuilder, permettant d'utiliser les fonctions de la  
+
-- Seul les noms des paramètres doivent être transmis à la fonction.
-- librairy table comme des mèthodes. minsert permet d'insérer plusieurs élément en une  
+
local validArg = function ( ... ) return Commun.validTextArg( args, ... ) end
-- seule fois en, ignorant les paramètre nil.
+
 +
-- titreChap est un paramètre différent de ceux du modèle ouvrage pour utiliser le même programme
 +
args.numChap = validArg( 'numéro chapitre' )
 +
args.titreChap = validArg( 'titre chapitre', 'chap', 'titre', 'title' )
 +
if args.titre == args.titreChap then
 +
args.titre = false
 +
end
 +
args.titre = validArg( 'titre ouvrage', 'ouvrage', 'titre', 'title' ) or false
 +
args['numéro chapitre'] = false
 +
args['titre chapitre'] = false
 +
args.chap = false
 +
args['sous-titre chapitre'] = validArg( 'sous-titre chapitre', 'sous-titre' ) or false
 +
args['sous-titre'] = validArg( 'sous-titre ouvrage', 'sous-titre' )
 +
if args['sous-titre chapitre'] == args['sous-titre'] then
 +
args['sous-titre'] = false
 +
end
 +
args['lien titre'] = validArg( 'lien titre ouvrage', 'lien titre' )
 +
local preface = validArg( 'préface' )
 +
local auteurOuvrage = validArg( 'auteurs ouvrage', 'auteur ouvrage' )
 +
if preface and auteurOuvrage then
 +
args['auteurs ouvrage'] = ( validArg( 'auteurs ouvrage', 'auteur ouvrage' ) or '' ) .. ' (préf. ' .. preface .. ')'
 +
args['préface'] = ''
 +
end
 +
return Ouvrage.ouvrage( args, true )
 +
end
 +
 
 +
 
 +
function Ouvrage.ouvrage( args, chapitre )
 +
-- 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()
 
local wiki = TableBuilder.new()
 
 
-- validArg renvoi le premier paramètre non vide, ou nil s'ils sont tous vides.
+
-- 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.
 
-- Seul les noms des paramètres doivent être transmis à la fonction.
 
local validArg = function ( ... ) return Commun.validTextArg( args, ... ) or false end
 
local validArg = function ( ... ) return Commun.validTextArg( args, ... ) or false end
 +
local genre = ( chapitre and 'chapitre' ) or 'ouvrage'
 
 
-- table servant à la catégorisation
+
--Table servant à la catégorisation
 
args.categ = {}
 
args.categ = {}
 +
 +
local modeNormal = not validArg( 'nocat' )
 
 
-- clarification paramètre nécessaire pour les COinS
+
-- Clarification des paramètres  nécessaires pour les COinS
args['périodique'] = validArg( 'périodique', 'revue', 'journal' )
 
 
args.titre = validArg( 'titre', 'title' )
 
args.titre = validArg( 'titre', 'title' )
args.passage = validArg( 'pages', 'page', 'passage', 'p.', 'pp.' )
+
args['pages totales'] = validArg( 'pages totales', 'pages' )
args['format électronique'] = args.format
+
args.pages = ''
args.format = false
+
local lienExternes = validArg( 'lire en ligne', 'url texte', 'url', 'texte' )
 +
if args.format and not args['format électronique'] and lienExternes and string.match( args.format,"pdf" ) then
 +
args['format électronique'] = args.format
 +
args.format = false
 +
end
 
 
 
 
Ligne 35 : Ligne 72 :
 
wiki.minsert( spanInitial,  Commun.libelle( args ) )
 
wiki.minsert( spanInitial,  Commun.libelle( args ) )
 
 
-- indication de langue
+
-- Indication de langue
 
local indicLangue, codeLangue = Commun.indicationDeLangue ( args, validArg )
 
local indicLangue, codeLangue = Commun.indicationDeLangue ( args, validArg )
 +
local dir, attributsLangue
 
if indicLangue and indicLangue ~= '' then
 
if indicLangue and indicLangue ~= '' then
 
wiki.minsert( indicLangue, ' ' )
 
wiki.minsert( indicLangue, ' ' )
 +
if codeLangue then
 +
dir = Langue.directionLangue( codeLangue )
 +
if dir == 'rtl' then
 +
attributsLangue = ' lang="' .. codeLangue .. '" dir="rtl"'
 +
else
 +
dir = nil
 +
attributsLangue = ' lang="' .. codeLangue .. '"'
 +
end
 +
end
 
end
 
end
+
 
-- Liste des auteurs et de leur responsabilités (principale et secondaire)
+
-- Liste des auteurs et de leurs responsabilités (principales et secondaires)
 
local auteur = validArg( 'nom1', 'nom', 'auteur1', 'auteur', 'auteurs', 'auteur institutionnel', 'last1', 'last', 'author1', 'author' )
 
local auteur = validArg( 'nom1', 'nom', 'auteur1', 'auteur', 'auteurs', 'auteur institutionnel', 'last1', 'last', 'author1', 'author' )
 
if auteur then
 
if auteur then
 
if validArg( 'auteurs' ) then
 
if validArg( 'auteurs' ) then
 
wiki.minsert( args.auteurs )
 
wiki.minsert( args.auteurs )
if validArg( 'et al.', 'et alii' ) then
 
wiki.minsert( " ''<abbr class=\"abbr\" title=\"et alii (et d’autres)\">et al.</abbr>''" )
 
end
 
 
else
 
else
wiki.minsert( Commun.responsabilitePrincipale( args, validArg ) )
+
wiki.minsert( Commun.responsabilitePrincipale( args, validArg ) )
 +
end
 +
local coauteur = validArg( 'co-auteur', 'coauteurs', 'coauteur', 'coauthors' )
 +
if coauteur then
 +
wiki.minsert( ', ', coauteur )
 
end
 
end
 
wiki.minsert( Commun.responsabiliteSecondaire( args, validArg ), ', ' )
 
wiki.minsert( Commun.responsabiliteSecondaire( args, validArg ), ', ' )
 
args.categ.auteur = validArg( 'auteur', 'auteurs', 'author1', 'author', 1, 2, 3, 4 )
 
args.categ.coauteur = validArg( 'coauteurs', 'coauteur', 'coauthors' )
 
 
end
 
end
 
 
-- titre, sous-titre
+
-- Pour le modèle chapitre : affichage du chapitre
if args.titre then
+
if chapitre then
if codeLangue then
+
if args.numChap then
local dir = Langue.directionLangue( codeLangue )
+
wiki.minsert( Commun.chap, args.numChap, ' ' )
if dir == 'rtl' then dir = '" dir="rtl'
+
end
else dir = nil
+
if args.titreChap then
 +
wiki.minsert( '<cite style="font-style:normal"', attributsLangue, '>« ', args.titreChap )
 +
if args['sous-titre chapitre'] then
 +
wiki.minsert( ' : ', args['sous-titre chapitre'] )
 
end
 
end
wiki.minsert( '<span lang="', codeLangue, dir, '">')
+
wiki.minsert( ' »</cite>' )
 +
elseif modeNormal then
 +
wiki.minsert( '<span class="error">[[Modèle:Chapitre|{{Chapitre}}]] : paramètre <code>titre chapitre</code> manquant</span>' )
 +
args.categ.titreChapitre = true
 
end
 
end
 
 
 +
wiki.minsert( ', dans ' )
 +
 +
local auteurOuvrage = validArg( 'auteurs ouvrage', 'auteur ouvrage' )
 +
if auteurOuvrage then
 +
wiki.minsert( auteurOuvrage, ', ' )
 +
end
 +
end
 +
 +
-- Titre
 +
if args.titre then
 
local titre, sousTitre = args.titre, validArg( 'sous-titre' )
 
local titre, sousTitre = args.titre, validArg( 'sous-titre' )
 
if sousTitre then
 
if sousTitre then
titre = titre .. ' : ' .. sousTitre
+
titre = titre .. ' : ' .. sousTitre
 
end
 
end
 
titre = Commun.fusionTexteLien( titre, args['lien titre'], args.categ )
 
titre = Commun.fusionTexteLien( titre, args['lien titre'], args.categ )
 +
local graphie = ' class="italique"'
 +
if Langue.nonLatin( titre ) then
 +
graphie = ' style="font-style:normal"'
 +
end
 +
wiki.minsert( '<cite', graphie, attributsLangue, '>', titre, '</cite>' )
 
 
wiki.minsert( '« <cite style="font-style:normal;">', titre, '</cite> »', codeLangue and '</span>' )
+
elseif modeNormal then
else
+
if chapitre then
args.categ.titre = true
+
args.categ.titreOuvrage = true
wiki.minsert( '<span class="error">[[Modèle:Article|{{Article}}]] : paramètre « <code>titre</code> » manquant</span>' )
+
if args.categ.titreChapitre then
 +
wiki.minsert( '<span class="error">paramètre <code>titre ouvrage</code> manquant</span>' )
 +
else
 +
wiki.minsert( '<span class="error">[[Modèle:Chapitre|{{Chapitre}}]] : paramètre <code>titre ouvrage</code> manquant</span>' )
 +
end
 +
else
 +
args.categ.titre = true
 +
wiki.minsert( '<span class="error">[[Modèle:Ouvrage|{{Ouvrage}}]] : paramètre <code>titre</code> manquant</span>' )
 +
end
 
end
 
end
 
 
 
-- Titre original et traducteur
 
-- Titre original et traducteur
local traductionTitre = validArg( 'traduction titre', 'titre original' )
+
local original = validArg( 'titre original', 'titre vo', 'traduction titre' )
if traductionTitre and traductionTitre ~= args.titre then
+
if original and original ~= args.titre then
wiki.minsert( ' [« ', traductionTitre, ' »]' )
+
if validArg( 'langue originale' ) then
 +
wiki.minsert( ' [« ', Langue.langue{ args['langue originale'], original }, ' »]' )
 +
else
 +
wiki.minsert( ' [« ', original, ' »]' )
 +
end
 
end
 
end
 
if not auteur then
 
if not auteur then
Ligne 91 : Ligne 169 :
 
end
 
end
 
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
 +
wiki.minsert( Langue.langue{ codeLangue, titreVolTome, class='italique' } )
 +
else
 +
wiki.minsert( '<span class="italique">', titreVolTome,  '</span>' )
 +
end
 +
local tradTitreVolTome = validArg( 'traduction titre volume', 'traduction titre tome' )
 +
if tradTitreVolTome then
 +
wiki.minsert( ' [« ', tradTitreVolTome, ' »]' )
 +
end
 +
end
 +
 
-- Nature du document et établissement (pour les thèses...)
 
-- Nature du document et établissement (pour les thèses...)
local nature = validArg( 'nature article', 'nature ouvrage' )
+
local nature = validArg( 'nature ouvrage' )
 
if nature then
 
if nature then
 
wiki.minsert( ' (', nature, ')')
 
wiki.minsert( ' (', nature, ')')
Ligne 102 : Ligne 207 :
 
end
 
end
 
 
-- périodique
+
-- Lieu et éditeur
local periodique = validArg( 'périodique' )
+
local lieu = validArg( 'lieu', 'location' )
if periodique then
 
-- on applique le code langue spécifique ou celui de l'article
 
local languePeriodique = validArg( 'langue périodique' )
 
if languePeriodique then
 
languePeriodique = Langue.codeLangue2( languePeriodique )
 
end
 
languePeriodique = languePeriodique or codeLangue
 
if languePeriodique and languePeriodique ~= 'fr' then
 
periodique = Langue.lang{ languePeriodique, periodique }
 
end
 
 
local periodiqueEtLien = Commun.fusionTexteLien( periodique, args['lien périodique'], args.categ )
 
if Langue.nonLatin( periodique ) then
 
-- caractères non latin donc police droite
 
wiki.minsert( ', ', periodiqueEtLien )
 
else
 
-- le titre et son lien éventuel son affichés en italique
 
wiki.minsert( ', <i>', periodiqueEtLien, '</i>' )
 
end
 
 
else
 
args.categ.periodique = true
 
if args.categ.titre then
 
wiki.minsert( ', <span class="error">paramètre « <code>périodique</code> » manquant</span>' )
 
else
 
wiki.minsert( ', <span class="error">[[Modèle:Article|{{Article}}]] : paramètre « <code>périodique</code> » manquant</span>' )
 
end
 
end
 
 
-- références : lieu, éditeur
 
local lieu = validArg( 'lieu', 'lieu édition', 'location' )
 
 
if lieu then
 
if lieu then
 
wiki.minsert( ', ', lieu )
 
wiki.minsert( ', ', lieu )
 
end
 
end
local editeur = validArg( 'éditeur', 'publisher' )
+
local editeur = validArg( 'éditeur', 'édition', 'editeur', 'edition', 'publisher' )
 
if editeur then
 
if editeur then
 
local lienEditeur = validArg( 'lien éditeur' )
 
local lienEditeur = validArg( 'lien éditeur' )
Ligne 144 : Ligne 218 :
 
end
 
end
 
 
-- références : série, volume
+
-- Collecion et numéro
local serie = validArg( 'série' )
+
local collection = validArg( 'collection', 'series' )
if serie then
+
if collection then
if tonumber( serie ) then
+
wiki.minsert( ', ', Commun.coll, '« ', collection )
wiki.minsert( ', ', Nombre2texte.ordinal( serie, true ), ' série' )
+
local serie = validArg( 'série' )
else
+
if serie then
if string.match( serie, '<sup>e</sup>$') then
+
wiki.minsert( ' / ', serie )
wiki.minsert( ', ', serie, ' série' )
+
end
else
+
wiki.minsert( ' »' )
wiki.minsert( ', série ', serie )
+
end
end
+
local numeroCollection = validArg( 'numéro dans collection', 'numéro dans la collection' )
 +
if numeroCollection then
 +
wiki.minsert( ' (', Commun.numero, numeroCollection, ')' )
 +
end
 +
 +
-- Date, réimpression et éditions
 +
local annee = validArg( 'année', 'date', 'year' )
 +
if annee then
 +
local lrm
 +
if Langue.nonLatin( wiki.concat() ) then
 +
lrm = '&lrm;'
 
end
 
end
 +
wiki.minsert( ',', lrm, ' ', Commun.inscriptionDate( 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( 'réimpression', 'publi' )
 +
if publi then
 +
wiki.minsert( ' (', Commun.reimpr, publi, ')' )
 +
end
 +
local numeroEdition = validArg( "numéro d'édition", "numéro édition"  )
 +
if numeroEdition then
 +
wiki.minsert( ', ', Nombre2texte.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
 +
 +
-- Pages et format
 +
local pages = validArg( 'pages totales', 'pages' )
 +
if pages then
 +
wiki.minsert( ', ', pages, Commun.nbp )
 +
end
 +
local format = validArg( 'format livre', 'format' )
 +
if format then
 +
wiki.minsert( ', ', format )
 
end
 
end
local volume = validArg( 'volume', 'vol' )
+
if volume then
+
-- Références
wiki.minsert( ', ', Commun.vol, volume )
+
local reference = validArg( 'référence' )
 +
if reference then
 +
wiki.minsert( ' ', Commun.detailEditions( reference ) )
 
end
 
end
local tome = validArg( 'tome' )
+
local refSimple = validArg( 'référence simplifiée', 'ref' )
if tome then
+
if refSimple then
wiki.minsert( ', ', Commun.tome, tome )
+
wiki.minsert( ' ', Commun.detailEdition( refSimple ) )
 
end
 
end
local titreVolume = validArg( 'titre volume', 'titre vol' )
+
if titreVolume then
+
 
if codeLangue then
+
-- Lien vers l'ouvrage en ligne (isbn, issn, pmid, doi, lire en ligne, résumé...)
wiki.minsert( ' ', Langue.lang{ codeLangue, '« ' .. titreVolume .. ' »' } )
+
wiki.minsert( References.affichageLiensExternes( args, validArg, true, false ) )
 +
-- consulté le n'est plus affiché, voir [[Discussion_modèle:Ouvrage#Évolution documentation]]
 +
 +
-- Précision sur le passage concerné
 +
local partie = validArg( 'partie' )
 +
if partie then
 +
if string.match ( partie, '^[%dIVXLCM]+$' ) then
 +
wiki.minsert( ', partie&nbsp;', partie )
 +
elseif string.match ( partie, '^[ivxlcmIVXLCM]+$' ) then
 +
wiki.minsert( ', partie&nbsp;',  Commun.romain( partie ) )
 
else
 
else
wiki.minsert( ' « ', titreVolume, ' »' )
+
wiki.minsert( ', ', partie )
 
end
 
end
 
end
 
end
+
local numeroChapitre = validArg( 'numéro chapitre', 'numéro' )
-- références : n° du périodique et titre du n° et date de publication
+
if numeroChapitre then
local numero = validArg( 'numéro', 'no', 'issue' )
+
wiki.minsert( ', ', Commun.chap, numeroChapitre )
if numero then
+
end
if mw.ustring.match( numero, "^%d+ ?[-–—/,;àe]t? ?%d" ) then
+
local titreChapitre = validArg( 'titre chapitre', 'chap', 'chapitre', 'chapter' )
wiki.minsert( ', ', Commun.numeros, numero )
+
if titreChapitre then
 +
if numeroChapitre then
 +
titreChapitre = ' (« ' .. titreChapitre .. ' »)'
 
else
 
else
wiki.minsert( ', ', Commun.numero, numero )
+
titreChapitre = ', « ' .. titreChapitre .. ' »'
 
end
 
end
end
 
local titreNumero = validArg( 'titre numéro', 'titre no' )
 
if titreNumero then
 
 
if codeLangue then
 
if codeLangue then
wiki.minsert( ' ', Langue.lang{ codeLangue, '« ' .. titreNumero .. ' »'  } )
+
titreChapitre = Langue.langue{ codeLangue, titreChapitre }
else
 
wiki.minsert( ' « ', titreNumero, ' »' )
 
 
end
 
end
end
+
wiki.minsert( titreChapitre )
if validArg( 'année', 'date', 'year' ) then
+
local tradTitreChap = validArg( 'traduction titre chapitre' )
args.mois = validArg( 'mois', 'saison' )
+
if tradTitreChap then
wiki.minsert( ',&lrm; ', Commun.inscriptionDate( args ) )
+
wiki.minsert( ' [« ', tradTitreChap, ' »]' )
-- le &lrm est une marque de texte gauche à droite, utile si le texte qui précède est en droite à gauche (arabe, hébreux...)
 
else
 
args.categ.date = true
 
if args.categ.titre or args.categ.periodique then
 
wiki.minsert( ', <span class="error">paramètre « <code>date</code> » manquant</span>' )
 
else
 
wiki.minsert( ', <span class="error">[[Modèle:Article|{{Article}}]] : paramètre « <code>date</code> » manquant</span>' )
 
 
end
 
end
end
 
 
-- format livre
 
local format = validArg( 'format livre' )
 
if format then
 
wiki.minsert( ', ', format )
 
 
end
 
end
+
local passage = validArg( 'passage', 'page' )
-- pages
+
if passage then
local page = validArg( 'passage', 'pages', 'page', 'p.', 'pp.' )
+
if string.match ( passage, '^[%dIVXLCM]' ) then
if page then
+
wiki.minsert( ', ', Commun.page, passage )
if string.match ( page, '^[%dIVXL]' ) then
 
wiki.minsert( ', ', Commun.page, page )
 
 
else
 
else
wiki.minsert( ', ', page )
+
wiki.minsert( ', ', passage )
 
end
 
end
end
 
local noArticle = validArg( 'numéro article' )
 
if noArticle then
 
wiki.minsert( ', article ', Commun.numero, noArticle )
 
 
end
 
end
 
-- lien vers l'article en ligne (isbn, issn, pmid, doi, lire en ligne, résumé...)
 
wiki.minsert( References.affichageLiensExternes( args, validArg, true, false ) )
 
-- consulté le n'est plus affiché, voir [[Discussion_modèle:Ouvrage/Archive_5#.C3.89volution_documentation]]
 
 
 
 
local patternPonct = '[,.;:!?]$'
 
local patternPonct = '[,.;:!?]$'
 
local ponctuation = wiki.concat():gsub( '%b<>', '' ):match( patternPonct )
 
local ponctuation = wiki.concat():gsub( '%b<>', '' ):match( patternPonct )
 
 
-- ajout des méthadonnées COinS (ContextObjects in Spans)
+
-- Ajout des méthadonnées COinS (ContextObjects in Spans)
wiki.minsert( Commun.COinS( args, validArg, 'article' ) )
+
wiki.minsert( Commun.COinS( args, validArg, genre ) )
 
 
-- fin du span (id) et de la description de l'ouvrage
+
-- Fin du span (id) et de la description de l'ouvrage
 
wiki.minsert( spanFinal )
 
wiki.minsert( spanFinal )
 
 
-- citation et commentaire de cet ouvrage
+
-- Citation et commentaire de cet ouvrage
local citation = validArg( 'extrait', 'quote', 'citation' )
+
local citation = validArg( 'extrait', 'citation' )
 
if citation then
 
if citation then
 
if codeLangue then
 
if codeLangue then
Ligne 245 : Ligne 338 :
 
wiki.minsert( ' :<blockquote>« ', citation, ' »</blockquote>' )
 
wiki.minsert( ' :<blockquote>« ', citation, ' »</blockquote>' )
 
end
 
end
 
 
if validArg( 'plume' ) then
 
if validArg( 'plume' ) then
 
local point
 
local point
Ligne 253 : Ligne 345 :
 
wiki.minsert( point, Commun.plume )
 
wiki.minsert( point, Commun.plume )
 
end
 
end
+
 
wiki.minsert( Commun.commentaire( args ) )
 
wiki.minsert( Commun.commentaire( args ) )
 
 
+
local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true, [104] = true }
if mw.title.getCurrentTitle().namespace == 0 then
+
if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] and modeNormal then
 
wiki.minsert(
 
wiki.minsert(
args.categ.coauteur and '[[Catégorie:Recension temporaire pour le modèle Article|coauteur]]',
+
args.categ.langue and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|langue]]',
args.categ.langue and '[[Catégorie:Page du modèle Article comportant une erreur|langue]]',
+
args.categ.titre and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|titre]]',
args.categ.titre and '[[Catégorie:Page du modèle Article comportant une erreur|titre]]',
+
args.categ.titreChapitre and '[[Catégorie:Page du modèle Chapitre comportant une erreur|Chapitre]]',
args.categ.periodique and '[[Catégorie:Page du modèle Article comportant une erreur|périodique]]',
+
args.categ.titreOuvrage and '[[Catégorie:Page du modèle Chapitre comportant une erreur|Ouvrage]]',
args.categ.date and '[[Catégorie:Page du modèle Article comportant une erreur|date]]',
+
args.categ.lienExterne and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|Externe]]',
args.categ.lienExterne and '[[Catégorie:Page du modèle Article comportant une erreur|externe]]',
 
 
args.categ.isbnInvalid and '[[Catégorie:Page avec ISBN invalide]]',
 
args.categ.isbnInvalid and '[[Catégorie:Page avec ISBN invalide]]',
args.categ.issnInvalid and '[[Catégorie:Page avec ISSN invalide]]'
+
args.categ.issnInvalid and '[[Catégorie:Page avec ISSN invalide]]',
 +
args.categ.eanInvalid and '[[Catégorie:Page avec EAN invalide]]'
 
)
 
)
if codeLangue then
+
if dir then
if Langue.directionLangue( codeLangue ) == 'rtl' then
+
wiki.minsert( '[[Catégorie:Recension temporaire pour le modèle Ouvrage|rtl]]' )
wiki.minsert( '[[Catégorie:Recension temporaire pour le modèle Article|rtl]]' )
 
end
 
 
end
 
end
 
end
 
end
+
 
 
 
 
return wiki.concat()
 
return wiki.concat()
Ligne 280 : Ligne 370 :
  
  
return Article
+
return Ouvrage

Version actuelle datée du 28 décembre 2020 à 10:52

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

local Ouvrage = { }


local Commun = require( 'Module:Biblio/Commun' )
local References = require( 'Module:Biblio/Références' )
local Nombre2texte = require( 'Module:Nombre2texte' )
local TableBuilder = require( 'Module:TableBuilder' )
local Langue = require( 'Module:Langue' )


function Ouvrage.chapitre( 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 Commun.validTextArg( args, ... ) end
	
	-- titreChap est un paramètre différent de ceux du modèle ouvrage pour utiliser le même programme
	args.numChap = validArg( 'numéro chapitre' )
	args.titreChap = validArg( 'titre chapitre', 'chap', 'titre', 'title' )
	if args.titre == args.titreChap then
		args.titre = false
	end
	args.titre = validArg( 'titre ouvrage', 'ouvrage', 'titre', 'title' ) or false
	args['numéro chapitre'] = false
	args['titre chapitre'] = false
	args.chap = false
	args['sous-titre chapitre'] = validArg( 'sous-titre chapitre', 'sous-titre' ) or false
	args['sous-titre'] = validArg( 'sous-titre ouvrage', 'sous-titre' )
	if args['sous-titre chapitre'] == args['sous-titre'] then
		args['sous-titre'] = false
	end
	args['lien titre'] = validArg( 'lien titre ouvrage', 'lien titre' )
	local preface = validArg( 'préface' )
	local auteurOuvrage = validArg( 'auteurs ouvrage', 'auteur ouvrage' )
	if preface and auteurOuvrage then
		args['auteurs ouvrage'] = ( validArg( 'auteurs ouvrage', 'auteur ouvrage' ) or '' ) .. ' (préf. ' .. preface .. ')'
		args['préface'] = ''
	end
	return Ouvrage.ouvrage( args, true )
end


function Ouvrage.ouvrage( args, chapitre )
	-- 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 Commun.validTextArg( args, ... ) or false end
	local genre = ( chapitre and 'chapitre' ) or 'ouvrage'
	
	--Table servant à la catégorisation
	args.categ = {}

	local modeNormal = not validArg( 'nocat' )
	
	-- Clarification des paramètres  nécessaires pour les COinS
	args.titre = validArg( 'titre', 'title' )
	args['pages totales'] = validArg( 'pages totales', 'pages' )
	args.pages = ''
	local lienExternes = validArg( 'lire en ligne', 'url texte', 'url', 'texte' )
	if args.format and not args['format électronique'] and lienExternes and string.match( args.format,"pdf" ) then
		args['format électronique'] = args.format
		args.format = false
	end
	
	
	-- span initial (id) et libellé
	local spanInitial, spanFinal = Commun.spanInitial ( args, validArg )
	wiki.minsert( spanInitial,  Commun.libelle( args ) )
	
	-- Indication de langue
	local indicLangue, codeLangue = Commun.indicationDeLangue ( args, validArg )
	local dir, attributsLangue
	if indicLangue and indicLangue ~= '' then
		wiki.minsert( indicLangue, ' ' )
		if codeLangue then
			dir = Langue.directionLangue( codeLangue )
			if dir == 'rtl' then 
				attributsLangue = ' lang="' .. codeLangue .. '" dir="rtl"'
			else 
				dir = nil
				attributsLangue = ' lang="' .. codeLangue .. '"'
			end
		end
	end

	-- Liste des auteurs et de leurs responsabilités (principales et secondaires)
	local auteur = validArg( 'nom1', 'nom', 'auteur1', 'auteur', 'auteurs', 'auteur institutionnel', 'last1', 'last', 'author1', 'author' )
	if auteur then
		if validArg( 'auteurs' ) then
			wiki.minsert( args.auteurs )
		else
			wiki.minsert( Commun.responsabilitePrincipale( args, validArg ) )
		end
		local coauteur = validArg( 'co-auteur', 'coauteurs', 'coauteur', 'coauthors' )
		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.numChap then
			wiki.minsert( Commun.chap, args.numChap, ' ' )
		end
		if args.titreChap then
			wiki.minsert( '<cite style="font-style:normal"', attributsLangue, '>« ', args.titreChap )
			if args['sous-titre chapitre'] then
				wiki.minsert( ' : ', args['sous-titre chapitre'] )
			end
			wiki.minsert( ' »</cite>' )
		elseif modeNormal then
			wiki.minsert( '<span class="error">[[Modèle:Chapitre|{{Chapitre}}]] : paramètre <code>titre chapitre</code> manquant</span>' )
			args.categ.titreChapitre = true
		end
		
		wiki.minsert( ', dans ' )
		
		local auteurOuvrage = validArg( 'auteurs ouvrage', 'auteur ouvrage' )
		if auteurOuvrage then
			wiki.minsert( auteurOuvrage, ', ' )
		end
	end
	
	-- Titre
	if args.titre then
		local titre, sousTitre = args.titre, validArg( 'sous-titre' )
		if sousTitre then
			titre =  titre .. ' : ' .. sousTitre
		end
		titre = Commun.fusionTexteLien( titre, args['lien titre'], args.categ )
		local graphie = ' class="italique"'
		if Langue.nonLatin( titre ) then
			graphie = ' style="font-style:normal"'
		end
		wiki.minsert( '<cite', graphie, attributsLangue, '>', titre, '</cite>' )
		
	elseif modeNormal then
		if chapitre then
			args.categ.titreOuvrage = true
			if args.categ.titreChapitre then
				wiki.minsert( '<span class="error">paramètre <code>titre ouvrage</code> manquant</span>' )
			else
				wiki.minsert( '<span class="error">[[Modèle:Chapitre|{{Chapitre}}]] : paramètre <code>titre ouvrage</code> manquant</span>' )
			end
		else
			args.categ.titre = true
			wiki.minsert( '<span class="error">[[Modèle:Ouvrage|{{Ouvrage}}]] : paramètre <code>titre</code> manquant</span>' )
		end
	end
	
	-- Titre original et traducteur
	local original = validArg( 'titre original', 'titre vo', 'traduction titre' )
	if original and original ~= args.titre then
		if validArg( 'langue originale' ) then
			wiki.minsert( ' [« ', Langue.langue{ args['langue originale'], original }, ' »]' )
		else
			wiki.minsert( ' [« ', original, ' »]' )
		end
	end
	if not auteur then
		local responsabiliteSecondaire = Commun.responsabiliteSecondaire( args, validArg )
		if responsabiliteSecondaire then
			wiki.minsert( ' ', responsabiliteSecondaire )
		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
			wiki.minsert( Langue.langue{ codeLangue, titreVolTome, class='italique' } )
		else
			wiki.minsert( '<span class="italique">', titreVolTome,  '</span>' )
		end
		local tradTitreVolTome = validArg( 'traduction titre volume', 'traduction titre tome' )
		if tradTitreVolTome then
			wiki.minsert( ' [« ', tradTitreVolTome, ' »]' )
		end
	end
	
	-- Nature du document et établissement (pour les thèses...)
	local nature = validArg( 'nature ouvrage' )
	if nature then
		wiki.minsert( ' (', nature, ')')
	end
	local etablissement = validArg( 'établissement' )
	if etablissement then
		wiki.minsert( ', ', etablissement )
	end
	
	-- Lieu et éditeur
	local lieu = validArg( 'lieu', 'location' )
	if lieu then
		wiki.minsert( ', ', lieu )
	end
	local editeur = validArg( 'éditeur', 'édition', 'editeur', 'edition', 'publisher' )
	if editeur then
		local lienEditeur = validArg( 'lien éditeur' )
		wiki.minsert( ', ', Commun.fusionTexteLien( editeur, lienEditeur, args.categ ) )
	end
	
	-- Collecion et numéro
	local collection = validArg( 'collection', 'series' )
	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', 'numéro dans la collection' )
	if numeroCollection then
		wiki.minsert( ' (', Commun.numero, numeroCollection, ')' )
	end
	
	-- Date, réimpression et éditions
	local annee = validArg( 'année', 'date', 'year' )
	if annee then
		local lrm
		if Langue.nonLatin( wiki.concat() ) then
			lrm = '&lrm;'
		end
		wiki.minsert( ',', lrm, ' ', Commun.inscriptionDate( 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( 'réimpression', 'publi' )
	if publi then
		wiki.minsert( ' (', Commun.reimpr, publi, ')' )
	end
	local numeroEdition = validArg( "numéro d'édition", "numéro édition"  )
	if numeroEdition then
		wiki.minsert( ', ', Nombre2texte.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
	
	-- Pages et format
	local pages = validArg( 'pages totales', 'pages' )
	if pages then
		wiki.minsert( ', ', pages, Commun.nbp )
	end
	local format = validArg( 'format livre', 'format' )
	if format then
		wiki.minsert( ', ', format )
	end
		
	-- Références
	local reference = validArg( 'référence' )
	if reference then
		wiki.minsert( ' ', Commun.detailEditions( reference ) )
	end
	local refSimple = validArg( 'référence simplifiée', 'ref' )
	if refSimple then
		wiki.minsert( ' ', Commun.detailEdition( refSimple ) )
	end
	

	-- Lien vers l'ouvrage en ligne (isbn, issn, pmid, doi, lire en ligne, résumé...)
	wiki.minsert( References.affichageLiensExternes( args, validArg, true, false ) )
	-- consulté le n'est plus affiché, voir [[Discussion_modèle:Ouvrage#Évolution documentation]]
	
	-- Précision sur le passage concerné
	local partie = validArg( 'partie' )
	if partie then
		if string.match ( partie, '^[%dIVXLCM]+$' ) then
			wiki.minsert( ', partie&nbsp;', partie )
		elseif string.match ( partie, '^[ivxlcmIVXLCM]+$' ) then
			wiki.minsert( ', partie&nbsp;',  Commun.romain( partie ) )
		else
			wiki.minsert( ', ', partie )
		end
	end
	local numeroChapitre = validArg( 'numéro chapitre', 'numéro' )
	if numeroChapitre then
		wiki.minsert( ', ', Commun.chap, numeroChapitre )
	end
	local titreChapitre = validArg( 'titre chapitre', 'chap', 'chapitre', 'chapter' )
	if titreChapitre then
		if numeroChapitre then
			titreChapitre = ' (« ' .. titreChapitre .. ' »)'
		else
			titreChapitre = ', « ' .. titreChapitre .. ' »'
		end
		if codeLangue then
			titreChapitre = Langue.langue{ codeLangue, titreChapitre }
		end
		wiki.minsert( titreChapitre )
		local tradTitreChap = validArg( 'traduction titre chapitre' )
		if tradTitreChap then
			wiki.minsert( ' [« ', tradTitreChap, ' »]' )
		end
	end
	local passage = validArg( 'passage', 'page' )
	if passage then
		if string.match ( passage, '^[%dIVXLCM]' ) then
			wiki.minsert( ', ', Commun.page, passage )
		else
			wiki.minsert( ', ', passage )
		end
	end
	
	local patternPonct = '[,.;:!?]$'
	local ponctuation = wiki.concat():gsub( '%b<>', '' ):match( patternPonct )
	
	-- Ajout des méthadonnées COinS (ContextObjects in Spans)
	wiki.minsert( Commun.COinS( args, validArg, genre ) )
	
	-- Fin du span (id) et de la description de l'ouvrage
	wiki.minsert( spanFinal )
	
	-- Citation et commentaire de cet ouvrage
	local citation = validArg( 'extrait', 'citation' )
	if citation then
		if codeLangue then
			citation = Langue.lang{ codeLangue, citation }
		end
		wiki.minsert( ' :<blockquote>« ', citation, ' »</blockquote>' )
	end
	if validArg( 'plume' ) then
		local point
		if not citation and not ponctuation then
			point = '.'
		end
		wiki.minsert( point, Commun.plume )
	end
		
	wiki.minsert( Commun.commentaire( args ) )
	
	local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true, [104] = true }
	if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] and modeNormal then
		wiki.minsert(
			args.categ.langue and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|langue]]',
			args.categ.titre and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|titre]]',
			args.categ.titreChapitre and '[[Catégorie:Page du modèle Chapitre comportant une erreur|Chapitre]]',
			args.categ.titreOuvrage and '[[Catégorie:Page du modèle Chapitre comportant une erreur|Ouvrage]]',
			args.categ.lienExterne and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|Externe]]',
			args.categ.isbnInvalid and '[[Catégorie:Page avec ISBN invalide]]',
			args.categ.issnInvalid and '[[Catégorie:Page avec ISSN invalide]]',
			args.categ.eanInvalid and '[[Catégorie:Page avec EAN invalide]]'
		)
		if dir then
			wiki.minsert( '[[Catégorie:Recension temporaire pour le modèle Ouvrage|rtl]]' )
		end
	end

	
	return wiki.concat()
end


return Ouvrage