« Module:Biblio/Ouvrage » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
chapitre : préface avec les auteurs ouvrage
 
(85 versions intermédiaires par le même utilisateur non affichées)
Ligne 6 : Ligne 6 :
local Outils = require( 'Module:Outils' )
local Outils = require( 'Module:Outils' )
local TableBuilder = require( 'Module:TableBuilder' )
local TableBuilder = require( 'Module:TableBuilder' )
local Langue -- = require( 'Module:Langue' )   ne sera chargé que si nécessaire.
local Langue = require( 'Module:Langue' )




function Ouvrage.chapitre( args )
function Ouvrage.chapitre( args )
-- 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 Outils.validTextArg( args, ... ) end
local validArg = function ( ... ) return Commun.validTextArg( args, ... ) end
-- titreChap est un paramètre différents de ceux du modèle ouvrage pour utilisé le même programme
-- titreChap est un paramètre différent de ceux du modèle ouvrage pour utiliser le même programme
args.titreChap = validArg( 'titre chapitre', 'chap', 'titre' )
args.titreChap = validArg( 'titre chapitre', 'chap', 'titre', 'title' )
args.titre = validArg( 'titre ouvrage', 'titre' )
if args.titre == args.titreChap then
if args.titre == args.titreChap then
args.titre = nil
args.titre = false
end
end
args['titre chapitre'] = nil
args.titre = validArg( 'titre ouvrage', 'ouvrage', 'titre', 'title' ) or false
args.chap = nil
args['titre chapitre'] = false
args['sous-titre chapitre'] = validArg( 'sous-titre chapitre', 'sous-titre' )  
args.chap = false
args['sous-titre'] = validArg( 'sous-titre ouvrage', 'sous-titre' )  
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
if args['sous-titre chapitre'] == args['sous-titre'] then
args['sous-titre'] = nil
args['sous-titre'] = false
end
end
args['lien titre'] = validArg( 'lien titre ouvrage', 'lien titre' )
args['lien titre'] = validArg( 'lien titre ouvrage', 'lien titre' )
return require( 'Module:Biblio/Ouvrage' ).ouvrage( args, true )
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
end




function Ouvrage.ouvrage( args, chapitre )
function Ouvrage.ouvrage( args, chapitre )
-- La table wiki va recevoir tout les petits bouts de texte, et sera concaténtée à la fin.
-- La table wiki va recevoir tout les petits bouts de texte, et sera concaténée à la fin.
-- Elle utilise la metat-table de TableBuilder, permettant d'utiliser les fonctions de la  
-- Elle utilise la meta-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  
-- librairie table comme des méthodes. minsert permet d'insérer plusieurs éléments en une
-- seule fois en, ignorant les paramètre nil.
-- 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 Outils.validTextArg( args, ... ) end
local validArg = function ( ... ) return Commun.validTextArg( args, ... ) or false end
local genre = ( chapitre and 'chapitre' ) or 'ouvrage'
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
--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.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
-- COinS, id et libelé
-- span initial (id) et libellé
wiki.minsert( Commun.COinS( args, validArg, genre ) )
local spanInitial, spanFinal = Commun.spanInitial ( args, validArg )
wiki.minsert( Commun.spanInitial ( args, validArg ) )
wiki.minsert( spanInitial,  Commun.libelle( args ) )
if validArg( 'libellé' ) then
wiki.minsert( '<small>[', args['libellé'], ']</small> ' )
-- Indication de langue
local indicLangue, codeLangue = Commun.indicationDeLangue ( args, validArg )
local dir, attributsLangue
if Outils.notEmpty( 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
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)
-- Liste des auteurs et de leurs responsabilités (principales et secondaires)
if validArg( 'nom1', 'nom', 'auteur', 'auteurs', 'last1', 'last', 'author1', 'author' ) then
local auteur = validArg( 'nom1', 'nom', 'auteur1', 'auteur', 'auteurs', 'auteur institutionnel', 'last1', 'last', 'author1', 'author' )
if auteur then
if validArg( 'auteurs' ) then
if validArg( 'auteurs' ) then
wiki.insert( args.auteurs )
wiki.minsert( args.auteurs )
else  
else
wiki.insert( Commun.responsabilitePrincipale( args, validArg, true ) )
wiki.minsert( Commun.responsabilitePrincipale( args, validArg ) )
end
end
if validArg( 'co-auteur', 'coauteurs' ) then
local coauteur = validArg( 'co-auteur', 'coauteurs', 'coauteur', 'coauthors' )
wiki.minsert( ', ', validArg( 'co-auteur', 'coauteurs' ) )
if coauteur then
wiki.minsert( ', ', coauteur )
end
end
wiki.minsert( Commun.responsabiliteSecondaire( args, validArg ), ', ' )
wiki.minsert( Commun.responsabiliteSecondaire( args, validArg ), ', ' )
Ligne 78 : Ligne 104 :
if chapitre then
if chapitre then
if args.titreChap then
if args.titreChap then
wiki.insert( '« <cite ' )
wiki.minsert( '<cite style="font-style:normal"', attributsLangue, '>« ', args.titreChap )
if codeLangue then
wiki.minsert( 'lang="', codeLangue, '" ' )
end
wiki.minsert( 'style="font-style:normal">', args.titreChap )
if args['sous-titre chapitre'] then
if args['sous-titre chapitre'] then
wiki.minsert( ( codeLangue and ': ' ) or ' : ', args['sous-titre chapitre'] )
wiki.minsert( ' : ', args['sous-titre chapitre'] )
end
end
wiki.insert( '</cite> » ' )
wiki.minsert( ' »</cite>' )
else
elseif modeNormal then
wiki.insert( Outils.erreur( 'paramètre « <code>titre chapitre</code> » manquant' ) )
wiki.minsert( Outils.erreur( ' [[Modèle:Chapitre|{{Chapitre}}]] : paramètre <code>titre chapitre</code> manquant' ) )
categTitreChapitre = true
args.categ.titreChapitre = true
end
wiki.minsert( ', dans ' )
local auteurOuvrage = validArg( 'auteurs ouvrage', 'auteur ouvrage' )
if auteurOuvrage then
wiki.minsert( auteurOuvrage, ', ' )
end
end
end
end
-- titre
-- Titre
if args.titre then
if args.titre then
if codeLangue then
local titre, sousTitre = args.titre, validArg( 'sous-titre' )
Langue = Langue or require( 'Module:Langue' )
if sousTitre then
local dir = Langue.directionLangue( codeLangue )
titre = titre .. ' : ' .. sousTitre
if dir == 'rtl' then dir = '" dir="rtl'
else dir = nil
end
wiki.minsert( '<cite lang="', codeLangue, dir, '">')
else
wiki.minsert( '<cite>')
end
end
if validArg( 'lien titre' ) then
titre = Commun.fusionTexteLien( titre, args['lien titre'], args.categ )
wiki.minsert( '[[', args['lien titre'], '|' )
local graphie = ' class="italique"'
if Langue.nonLatin( titre ) then
graphie = ' style="font-style:normal"'
end
end
wiki.minsert( '<cite', graphie, attributsLangue, '>', titre, '</cite>' )
wiki.insert( args.titre )  
elseif modeNormal then
if chapitre then
if validArg( 'sous-titre' ) then
args.categ.titreOuvrage = true
wiki.minsert( ( codeLangue and ': ' ) or ' : ', args['sous-titre'] )
if args.categ.titreChapitre then
wiki.minsert( Outils.erreur( 'paramètre <code>titre ouvrage</code> manquant' ) )
else
wiki.minsert( Outils.erreur( '[[Modèle:Chapitre|{{Chapitre}}]] : paramètre <code>titre ouvrage</code> manquant' ) )
end
else
args.categ.titre = true
wiki.minsert( Outils.erreur( '[[Modèle:Ouvrage|{{Ouvrage}}]] : paramètre <code>titre</code> manquant' ) )
end
end
if validArg( 'lien titre' ) then
end
wiki.insert( ']]' )
end
-- Titre original et traducteur
wiki.insert( '</cite>' )
local original = validArg( 'titre original', 'titre vo', 'traduction titre' )
if original and original ~= args.titre then
local original = validArg( 'titre original', 'titre vo' )
if validArg( 'langue originale' ) then
if original and original ~= args.titre then
wiki.minsert( ' [« ', Langue.langue{ args['langue originale'], original }, ' »]' )
else
wiki.minsert( ' [« ', original, ' »]' )
wiki.minsert( ' [« ', original, ' »]' )
end
end
else
end
if chapitre then
if not auteur then
wiki.insert( Outils.erreur( 'paramètre « <code>titre ouvrage</code> » manquant' ) )
local responsabiliteSecondaire = Commun.responsabiliteSecondaire( args, validArg )
categTitreOuvrage = true
if responsabiliteSecondaire then
else
wiki.minsert( ' ', responsabiliteSecondaire )
wiki.insert( Outils.erreur( 'paramètre « <code>titre</code> » manquant' ) )
categTitre = true
end
end
end
end
-- volume, tome
if validArg( 'volume' ) then
-- Volume, tome
wiki.minsert( ', ', Commun.vol, args.volume )
local volume = validArg( 'volume', 'vol' )
if volume then
wiki.minsert( ', ', Commun.vol, volume )
end
end
if validArg( 'tome' ) then
local tome = validArg( 'tome' )
wiki.minsert( ', ', Commun.tome, args.tome )
if tome then
wiki.minsert( ', ', Commun.tome, tome )
end
end
if validArg( 'titre volume', 'titre tome' ) then
local titreVolTome = validArg( 'titre volume', 'titre tome' )
if validArg( 'volume', 'tome' ) then
if titreVolTome then
wiki.insert( ' : ' )
if volume or tome then
wiki.minsert( [[ : '']] )
else
else
wiki.insert( ', ' )
wiki.minsert( [[, '']] )
end
end
wiki.minsert( validArg( 'titre volume' ) or args['titre tome'] )
if codeLangue then
if codeLangue then
Langue = Langue or require( 'Module:Langue' )
wiki.minsert( Langue.langue{ codeLangue, titreVolTome },  [['']] )
wiki.minsert( ' « ', Langue.lang{ codeLangue, args['titre volume'] } )
else
else  
wiki.minsert( titreVolTome,  [['']] )
wiki.minsert( validArg( 'titre volume' ) )
end
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
end
-- références
-- Lieu et éditeur
if validArg( 'référence' ) then
local lieu = validArg( 'lieu', 'location' )
wiki.minsert( ' ', Commun.detailEditions( args['référence'] ) )
if lieu then
else
wiki.minsert( ', ', lieu )
if validArg( 'lieu' ) then
end
wiki.minsert( ', ', args.lieu )
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
end
local edit = validArg( 'éditeur', 'édition' )
wiki.minsert( ' »' )
if edit then
end
if validArg( 'lien éditeur' ) then
local numeroCollection = validArg( 'numéro dans collection', 'numéro dans la collection' )
wiki.minsert( ', [[', args['lien éditeur'], '|', edit, ']]' )
if numeroCollection then
else
wiki.minsert( ' (', Commun.numero, numeroCollection, ')' )
wiki.minsert( ', ', edit )
end
  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
if validArg( 'référence simplifiée', 'ref' ) then
wiki.minsert( ',', lrm, ' ', Commun.inscriptionDate( args ) )
if validArg( 'année' ) then
-- le &lrm est une marque de texte gauche à droite, utile si le texte qui précède est en droite à gauche (arabe, hébreux...)
wiki.minsert( ', ', args['année'] )
end
end
local publi = validArg( 'réimpression', 'publi' )
wiki.minsert( ' ', Commun.detailEdition( validArg( 'référence simplifiée', 'ref' ) ) )
if publi then
else
wiki.minsert( ' (', Commun.reimpr, publi, ')' )
if validArg( 'collection' ) then
end
wiki.minsert( ', ', Commun.coll, '« ', args.collection )
local numeroEdition = validArg( "numéro d'édition", "numéro édition"  )
if validArg( 'série' ) then
if numeroEdition then
wiki.minsert( ' / ', args['série'] )
wiki.minsert( ', ', Outils.ordinal( numeroEdition, true ), Commun.ed )
end
end
wiki.insert( ' »' )
local premiereEdition = validArg( 'année première édition', 'origyear' )
end
if premiereEdition then
if validArg( 'numéro dans collection' ) then
wiki.minsert( ' (', Commun.premiere, Commun.ed, ' ', premiereEdition, ')' )
wiki.minsert( ' (', Commun.numero, args['numéro dans collection'], ')' )  
end
if validArg( 'année', 'date' ) then
wiki.minsert( ', ', Commun.inscriptionDate( args ) )
end
if validArg( 'réimpression', 'publi' ) then
wiki.minsert( ' ', Commun.reimpr, validArg( 'réimpression', 'publi' ) )
end
if validArg( "numéro d'édition" ) then
wiki.minsert( ', ', Outils.ordinal( args["numéro d'édition"], true ), Commun.ed )
end
if validArg( 'année première édition', 'origyear' ) then
wiki.minsert( ' (', Commun.premiere, Commun.ed, validArg( 'année première édition', 'origyear' ) )
end
if validArg( 'format' ) then
wiki.minsert( ', ', args.format )
end
if validArg( 'pages totales', 'pages' ) then
wiki.minsert( ', ', validArg( 'pages totales', 'pages' ), Commun.nbp )
end
end
end
end
-- références ISBN, oclc, lccn, bnf...
-- Pages et format
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 pages = validArg( 'pages totales', 'pages' )
local enligne = TableBuilder.new( )
if pages then
wiki.minsert( ', ', pages, Commun.nbp )
end
local format = validArg( 'format livre', 'format' )
if format then
wiki.minsert( ', ', format )
end
enligne.minsert( References.isbn( args, validArg ), References.issn( args, validArg ) )
-- 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
enligne.minsert(
 
References.oclc( validArg( 'oclc' ) ),
-- Lien vers l'ouvrage en ligne (isbn, issn, pmid, doi, lire en ligne, résumé...)
References.bnf ( validArg( 'bnf'  ) ),
wiki.minsert( References.affichageLiensExternes( args, validArg, true, false ) )
References.lccn( validArg( 'lccn' ) ),
-- consulté le n'est plus affiché, voir [[Discussion_modèle:Ouvrage#Évolution documentation]]
References.dnb ( validArg( 'dnb'  ) ),
References.doi( validArg( 'doi' ) ),
References.pmid( validArg( 'pmid' ) ),
References.jstor( validArg( 'jstor' ) )
)
if validArg( 'lire en ligne', 'url' ) then
-- Précision sur le passage concerné
enligne.insert( References.enLigne{
local partie = validArg( 'partie' )
lien = validArg( 'lire en ligne', 'url' ),  
if partie then
texte = 'lire en ligne',
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
end
if validArg( 'écouter en ligne' ) then
if codeLangue then
enligne.insert( References.enLigne{  
titreChapitre = Langue.langue{ codeLangue, titreChapitre }
lien = args['écouter en ligne'],
date = args['consulté le'],
texte = 'écouter en ligne',
} )
end
end
if validArg( 'présentation en ligne', 'résumé' ) then
wiki.minsert( titreChapitre )
enligne.insert( References.enLigne{
local tradTitreChap = validArg( 'traduction titre chapitre' )
lien = validArg( 'présentation en ligne', 'résumé' ),
if tradTitreChap then
texte = 'présentation en ligne',
wiki.minsert( ' ', tradTitreChap, ' »]' )
} )
end
end
end
if validArg( 'consulté le', 'accessdate', 'consulté' ) then
local passage = validArg( 'passage', 'page' )
enligne.insert( 'consulté le ' .. Outils.nobr( validArg( 'consulté le', 'accessdate', 'consulté' ) ) )
if passage then
if string.match ( passage, '^[%dIVXLCM]' ) then
wiki.minsert( ', ', Commun.page, passage )
else
wiki.minsert( ', ', passage )
end
end
wiki.minsert( ' <small>', mw.text.nowiki( '[' ), enligne.concat( ', ' ),  ']</small>' )
end
end
-- précision sue le passage concerné
local patternPonct = '[,.;:!?]$'
local sep_chapitre = ', '
local ponctuation = wiki.concat():gsub( '%b<>', '' ):match( patternPonct )
if validArg( 'partie' ) then
wiki.minsert( ', partie&nbsp;',  Commun.romain( args.partie ) )
-- Ajout des méthadonnées COinS (ContextObjects in Spans)
sep_chapitre = ' '
wiki.minsert( Commun.COinS( args, validArg, genre ) )
end
if validArg( 'numéro chapitre', 'numéro' ) then
-- Fin du span (id) et de la description de l'ouvrage
wiki.minsert( ', ', Commun.chap, validArg( 'numéro chapitre', 'numéro' ) )
wiki.minsert( spanFinal )
sep_chapitre = ' '
-- Citation et commentaire de cet ouvrage
local citation = validArg( 'extrait', 'citation' )
if citation then
wiki.minsert( ' :<blockquote>« ', citation, ' »</blockquote>' )
end
end
if validArg( 'titre chapitre', 'chap' ) then
wiki.minsert( sep_chapitre, '« ', validArg( 'titre chapitre', 'chap' ), ' »' )
end
if validArg( 'passage' ) then
wiki.minsert( ', ', Commun.page, args.passage )
end
-- fin des span (COinS et id) et de la description de l'ouvrage
wiki.insert( '</span></span>' )
-- citation et commentaire de cet ouvrage
if validArg( 'extrait' ) then
wiki.minsert( ' :<blockquote>', args.extrait, '</blockquote>' )
elseif validArg( 'plume', 'commentaire' ) then
wiki.insert( '.' )
end 
if validArg( 'plume' ) then
if validArg( 'plume' ) then
wiki.insert( Commun.plume )
local point
if not citation and not ponctuation then
point = '.'
end
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(
categLangue and '[[Catégorie:Article utilisant le modèle Ouvrage avec un paramètre langue non reconnu]]',
args.categ.langue and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|langue]]',
categTitre and '[[Catégorie:Page utilisant un modèle avec une syntaxe erronée|Ouvrage]]',
args.categ.titre and '[[Catégorie:Page du modèle Ouvrage comportant une erreur|titre]]',
categTitreChapitre and '[[Catégorie:Page utilisant un modèle avec une syntaxe erronée|Chapitre]]',
args.categ.titreChapitre and '[[Catégorie:Page du modèle Chapitre comportant une erreur|Chapitre]]',
categTitreOuvrage and '[[Catégorie:Page utilisant un modèle avec une syntaxe erronée|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
end



Dernière version du 22 avril 2017 à 07:24

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' )


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.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['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 Outils.notEmpty( 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.titreChap then wiki.minsert( '« ', args.titreChap ) if args['sous-titre chapitre'] then wiki.minsert( ' : ', args['sous-titre chapitre'] ) end wiki.minsert( ' »' ) elseif modeNormal then wiki.minsert( Outils.erreur( ' [[Modèle:Chapitre|Modèle:Chapitre]] : paramètre titre chapitre manquant' ) ) 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, '' )

elseif modeNormal then if chapitre then args.categ.titreOuvrage = true if args.categ.titreChapitre then wiki.minsert( Outils.erreur( 'paramètre titre ouvrage manquant' ) ) else wiki.minsert( Outils.erreur( '[[Modèle:Chapitre|Modèle:Chapitre]] : paramètre titre ouvrage manquant' ) ) end else args.categ.titre = true wiki.minsert( Outils.erreur( '[[Modèle:Ouvrage|{{Ouvrage}} : paramètre titre manquant]] : paramètre titre manquant' ) ) 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 }, '' ) else wiki.minsert( titreVolTome, '' ) 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 = '‎' 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( ', ', 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

-- 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 ', partie ) elseif string.match ( partie, '^[ivxlcmIVXLCM]+$' ) then wiki.minsert( ', partie ', 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

wiki.minsert( ' :

« ', citation, ' »

' )

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 , args.categ.titre and , args.categ.titreChapitre and , args.categ.titreOuvrage and , args.categ.lienExterne and , args.categ.isbnInvalid and , args.categ.issnInvalid and , args.categ.eanInvalid and ) if dir then wiki.minsert( ) end end


return wiki.concat() end


return Ouvrage