Module:Biblio : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
m (retouche de la modification précédente)
(Ajout fonction lienBrise pour le modèle:Lien brisé)
 
(23 révisions intermédiaires par 6 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
local Biblio = {}
+
-- Le module biblio centralise les différentes fonctions utiles pour les bibliographie et références.
  
local Langue = require ( 'Module:Langue' )
+
local Biblio = {  }
local Date = require ( 'Module:Date' )
 
  
-- cette simple fonction permet de récupérer les arguement du modèle,
+
require( 'Module:No globals' )
-- ou la table transmise à la fonction par une autre fonction d'un module
+
local Outils = require( 'Module:Outils' )
local function extractArgs ( frame )
+
 
    -- return ( frame.getParent and frame:getParent().args ) or frame or { }
+
 
    return frame.args or frame or { } -- renvoie les arguments transmis par invoke et non par le modèle, pour tester avant de créer les modèle.
+
Biblio.ouvrage = function ( frame )
 +
local args = Outils.extractArgs( frame )
 +
local Ouvrage = require( 'Module:Biblio/Ouvrage' )
 +
return Ouvrage.ouvrage( args )
 
end
 
end
  
-- fonction abréviation, abréviation discrète
 
-- paramètres : 1 = abréviation, 2 = texte, 3 = langue, abrd = abréviation discrète
 
function Biblio.abr ( frame )
 
    local args = extractArgs ( frame )
 
    if args[2] == nil then
 
        return args[1] or ''                -- retoune l'abréviation ou au minimum une chaine vide s'il n'y a pas de texte
 
    end
 
  
    local wikiText = { '<abbr' }
+
Biblio.chapitre = function ( frame )
    if args.abrd then
+
local args = Outils.extractArgs( frame )
        table.insert(wikiText, ' class="abbr"')
+
local Ouvrage = require( 'Module:Biblio/Ouvrage' )
    end
+
return Ouvrage.chapitre( args )  
    table.insert(wikiText, ' title="' .. args[2])
+
end
    if args[3] then
+
 
        table.insert(wikiText, '" lang="' .. args[3])
 
    end
 
    table.insert(wikiText, '">' .. args[1] .. '</abbr>')
 
  
    return table.concat (wikiText)
+
Biblio.article = function ( frame )
 +
local args = Outils.extractArgs( frame )
 +
local Ouvrage = require( 'Module:Biblio/Article' )
 +
return Ouvrage.article( args )  
 
end
 
end
  
-- voir Modèle:ISBN
 
function Biblio.ISBN ( frame )
 
    local args = extractArgs ( frame )
 
    local liste = { }
 
    local i = 1
 
   
 
    local isbn = mw.text.trim ( args [1] or '' )
 
    if isbn == '' then
 
        liste = { 'ISBN&nbsp;inconnu[[Catégorie:ISBN nécessaire]]' }
 
    else
 
        local texteIsbn = 'ISBN ' .. isbn
 
        repeat
 
            local lien = '[[Spécial:Ouvrages de référence/' .. isbn
 
                .. '|<span class="nowrap">' .. texteIsbn .. '</span>]]'
 
            table.insert ( liste, lien )
 
  
            i = i + 1
+
Biblio.lienWeb = function( frame )
            isbn = mw.text.trim ( args [i] or '' )
+
local args = Outils.extractArgs( frame )
            texteIsbn = isbn
+
local Ouvrage = require( 'Module:Biblio/Lien web' )
        until isbn == ''
+
return Ouvrage.lienWeb( args )  
    end
 
    return '<small>(' .. mw.text.listToText ( liste ) .. ')</small>'
 
 
end
 
end
  
-- voir Modèle:ISSN
+
Biblio.lienBrise = function( frame )
function Biblio.ISSN ( frame )
+
local args = Outils.extractArgs( frame )
    local args = extractArgs ( frame )
+
local Ouvrage = require( 'Module:Biblio/Lien web' )
    local liste = { }
+
return Ouvrage.lienBrise( args )
    local i = 1
+
end
   
 
    local issn = mw.text.trim ( args [1] or '' )
 
    if issn == '' then
 
        liste = { 'inconnu[[Catégorie:ISSN nécessaire]]' }
 
    else
 
        repeat
 
            local lien = '<span class="plainlinks noarchive">[http://worldcat.org/issn/'  
 
                .. mw.uri.encode( issn ) .. '&lang=fr ' .. issn.. ']</span>'
 
            table.insert ( liste, lien )
 
  
            i = i + 1
+
 
            issn = mw.text.trim ( args [i] or '' )
+
Biblio.dictionnaire = function( frame )
            texteIsbn = issn
+
local args = Outils.extractArgs( frame )
        until issn == ''
+
local article = Outils.validTextArg( args, 'notice', 'article', 'titre chapitre' )
    end
+
local Ouvrage = require( 'Module:Biblio/Ouvrage' )
    return '<small>([[International Standard Serial Number|ISSN]]&nbsp;' .. mw.text.listToText ( liste ) .. ')</small>'
+
if article then
 +
args['titre chapitre'] = article
 +
return Ouvrage.chapitre( args )
 +
else
 +
args.titre = args['titre ouvrage']
 +
args['sous-titre'] = args['sous-titre ouvrage']
 +
args.auteur1 = args['auteur ouvrage']
 +
args.auteurs = args['auteurs ouvrage']
 +
return Ouvrage.ouvrage( args )
 +
end
 
end
 
end
  
-- voir Modèle:Module biblio/span initial
+
-- catégorise une page en fonction du namespace
function Biblio.spanInitial ( frame )
+
local function categorise(args)
    local args = extractArgs ( frame )        -- préparation pour appel par modèle ou direct.
+
local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true, [104] = true }
    local id = args.id or ''
+
local category = args[1]
    if string.len( id ) == 0 then
+
local flag = args[2]
        id = mw.uri.anchorEncode ( args.id1 .. args.id2 .. args.id3 .. args.id4 .. args.id5 )
+
if type(category) == 'string'
    end
+
and flag
    return '<span class="ouvrage" id="' .. id
+
and namespaceCategorisation[ mw.title.getCurrentTitle().namespace ]
 +
then
 +
return '[[Category:' .. category .. ']]'
 +
end
 +
return ''
 
end
 
end
  
-- voir Modèle:Module biblio/libellé
+
Biblio.ISBN = function ( frame )
function Biblio.libelle ( frame )
+
local args = Outils.extractArgs( frame )
    local args = extractArgs ( frame )
+
if Outils.trim( args[1] ) then
    local lib = args ['libellé'] or args [1] or ''
+
local newArgs = { isbn = args[1] }
    if string.len( lib ) > 0 then
+
local i = 2
        lib = '<small>[' .. lib .. ']</small> '
+
while args[i] do
    end
+
newArgs[ 'isbn' .. i ] = args[i]
    return lib
+
i = i + 1
 +
end
 +
return Biblio.identifiantsBiblio( newArgs )
 +
else
 +
return '<small>([[International Standard Book Number|ISBN]]&nbsp;inconnu)</small>' .. categorise{ 'ISBN nécessaire', true }
 +
end
 
end
 
end
  
-- voir Modèle:Module biblio/indication de langue
+
Biblio.rechercheIsbn = function( frame )
function Biblio.indicationDeLangue ( frame )
+
local args = Outils.extractArgs( frame )
    local args = extractArgs ( frame )
+
local References = require( 'Module:Biblio/Références' )
    local codeLangue = Langue.codeLangue2 ( args.langue )
+
local newArgs = { isbn = args[1], sansLabel = true, categ = {} }
    if codeLangue ~= '' and codeLangue ~= 'fr' then
+
local isbn = References.isbn( newArgs ) or ''
        return Langue.indicationDeLangue { '', codeLangue }
+
local categ = categorise{ 'Page avec ISBN invalide', newArgs.categ.isbnInvalid }
    else
+
return isbn .. categ
        return ''
 
    end
 
 
end
 
end
  
-- voir Modèle:Module biblio/responsabilité principale
+
 
function Biblio.responsabilitePrincipale ( frame )
+
Biblio.EAN = function ( frame )
    local args = extractArgs ( frame )
+
local args = Outils.extractArgs( frame )
    local nom = args ['nom1'] or ''
+
if Outils.trim( args[1] ) then
   
+
local newArgs = { ean = args[1], categ = {} }
    if nom == '' then
+
local i = 2
        return ''
+
while args[i] do
    end
+
newArgs[ 'ean' .. i ] = args[i]
   
+
i = i + 1
    local listeRresponsables = { }  -- contiendra un élément pour chaque nom
+
end
    local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true }  
+
return Biblio.identifiantsBiblio( newArgs )
    local responsable, prenom, lien , precision, resp
+
else  
    local i = 1
+
return '<small>([[EAN 13|EAN]]&nbsp;inconnu)</small>[[Catégorie:EAN nécessaire]]'
   
+
end
    repeat      -- boucle sur chaque nom, assemble toutes les caractéristique et ajoute l'ensemble à la liste.
 
        prenom = args [ 'prénom' .. i ] or ''
 
        if prenom ~= '' then prenom = prenom .. ' '
 
        end
 
       
 
        precision = args [ 'directeur' .. i ] or ''
 
        resp = args [ 'responsabilité' .. i ] or ''
 
        if precision == '' then
 
            if resp ~= '' then
 
                precision = ' (' .. resp .. ')'
 
            end
 
        else
 
            if resp ~= '' then
 
                precision = ' (' .. directeur .. ' et ' .. resp .. ')'
 
            else
 
                precision = ' (' .. directeur .. ')'
 
            end
 
        end
 
       
 
        lien = args [ 'lien' .. i ] or ''
 
        if lien ~= '' then
 
            responsable = '[[' .. lien .. '|' .. prenom .. nom .. ']]' .. precision
 
        else
 
            responsable = prenom .. nom .. precision
 
        end
 
       
 
        table.insert ( listeRresponsables, responsable )
 
       
 
        i = i + 1
 
        nom = args [ 'nom' .. i ] or ''
 
       
 
    until nom == ''
 
   
 
    if args [ 'et al.' ] == 'oui' then
 
        local et_al = " ''" .. Biblio.abr { "et al.", "et alii (et d’autres)", abrd = true } .. "''"
 
        return table.concat ( listeRresponsables, ', ' ) .. et_al
 
    else
 
        return mw.text.listToText ( listeRresponsables )
 
    end
 
 
end
 
end
  
-- voir Module biblio/responsabilité secondaire
+
 
function Biblio.responsabiliteSecondaire ( frame )
+
Biblio.ISSN = function ( frame )
    local args = extractArgs ( frame )
+
local args = Outils.extractArgs( frame )
    local traducteur = args.traducteur or ''
+
if Outils.trim( args[1] ) then
    local preface = args [ 'préface' ] or ''
+
local newArgs = { issn = args[1], categ = {} }
    local postface = args [ 'postface' ] or ''
+
local i = 2
    local illustrateur = args.illustrateur or ''
+
while args[i] do
    local photographe = args.photographe or ''
+
newArgs[ 'issn' .. i ] = args[i]
    local libre = args [ 'champ libre' ] or ''
+
i = i + 1
    local liste = { }
+
end
   
+
return Biblio.identifiantsBiblio( newArgs )
    if traducteur ~= '' then
+
else
        table.insert ( liste, Biblio.abr { 'trad.', 'traduction', abrd = true } .. '&nbsp;' .. traducteur )
+
return '<small>([[International Standard Serial Number|ISSN]]&nbsp;inconnu)</small>' .. categorise{ 'ISSN nécessaire', true }
    end
+
end
    if preface ~= '' then
+
end
        table.insert ( liste, Biblio.abr { 'préf.', 'préface', abrd = true } .. '&nbsp;' .. preface )
+
 
    end
+
Biblio.rechercheIssn = function( frame )
    if postface ~= '' then
+
local args = Outils.extractArgs( frame )
        table.insert ( liste, Biblio.abr { 'post.', 'postface', abrd = true } .. '&nbsp;' .. postface )
+
local References = require( 'Module:Biblio/Références' )
    end
+
local newArgs = { issn = args[1], sansLabel = true, categ = {} }
    if illustrateur ~= '' then
+
local issn = References.issn( newArgs ) or ''
        table.insert ( liste, Biblio.abr { 'ill.', 'illustrations', abrd = true } .. '&nbsp;' .. illustrateur )
+
local categ = categorise{ 'Page avec ISSN invalide', newArgs.categ.issnInvalid }
    end
+
return issn .. categ
    if photographe ~= '' then
+
end
        table.insert ( liste, Biblio.abr { 'photogr.', 'photographies', abrd = true } .. '&nbsp;' .. photographe )
+
 
    end
+
Biblio.BNF = function ( frame )
    if libre ~= '' then
+
local References = require( 'Module:Biblio/Références' )
        table.insert ( liste, libre )
+
return References.bnf( Outils.extractArgs( frame )[1] )
    end
 
   
 
    local texte = table.concat ( liste , ', ')
 
    if texte ~= '' then
 
        return '(' .. texte .. ')'
 
    else
 
        return ''
 
    end
 
 
end
 
end
  
-- voir Modèle:Module biblio/description physique
+
Biblio.enLigne = function ( frame )
function Biblio.descriptionPhysique ( frame )
+
local args = Outils.extractArgs( frame )
    local args = extractArgs ( frame )
+
local References = require( 'Module:Biblio/Références' )
    local form = args.format or ''
+
return '<small>[' .. References.enLigne( args )  .. ']</small>'
    local numeros = args [ 'nombre numéros' ] or ''
 
    local volumes = args [ 'nombre volumes' ] or ''
 
    local tomes = args [ 'nombre tomes' ] or ''
 
    local pages = args [ 'nombre pages' ] or ''
 
    local liste = { }
 
   
 
    if form ~= '' then
 
        table.insert ( liste, ', ' .. form )
 
    end
 
    if numeros ~= '' then
 
        table.insert ( liste, ', ' .. numeros .. '&nbsp;numéros' )
 
    end
 
    if volumes ~= '' then
 
        table.insert ( liste,  ', ' .. volumes .. '&nbsp;' .. Biblio.abr { 'vol.', 'volumes', abrd = true } )
 
    end
 
    if tomes ~= '' then
 
        table.insert ( liste,  ', ' .. tomes .. '&nbsp;' .. Biblio.abr { 't.', 'tomes', abrd = true } )
 
    end
 
    if pages ~= '' then
 
        table.insert ( liste, ', ' .. pages .. '&nbsp;' .. Biblio.abr { 'p.', 'pages', abrd = true } )
 
    end
 
   
 
    return table.concat ( liste )
 
 
end
 
end
  
-- voir Modèle:COinS bibliographique
+
Biblio.identifiantsBiblio = function( frame )
function Biblio.COinS ( frame )  
+
local args = Outils.extractArgs( frame )
    local args = extractArgs ( frame )
+
args.categ = {}
    local liste = { }
+
local References = require( 'Module:Biblio/Références' )
   
+
return References.affichageLiensExternes( args, nil, true, true )  
    -- la fonction insert liste ajoute à la table 'liste' un couple 'nom Coins normalisé' - 'donnée'
+
.. categorise{ 'Page avec ISBN invalide', args.categ.isbnInvalid }
    -- Si istexte = true, le deuxième élément de tab est considéré comme du texte,
+
.. categorise{ 'Page avec ISSN invalide', args.categ.issnInvalid }
    -- sinon comme le nom d'un paramètre.
+
.. categorise{ 'Page avec EAN invalide', args.categ.eanInvalid }
    local function insertList ( key, value, prefix )
 
        prefix = prefix or ''
 
        if option and option ~= '' then
 
            table.insert ( liste, key .. '=' .. mw.uri.encode ( prefix .. option ) )
 
            return true
 
        end
 
    end
 
   
 
    -- norme du COinS
 
    insertList ( 'ctx_ver', 'Z39.88-2004' )
 
   
 
    -- genre, titre et sous-titre
 
    local tabGenre = {
 
        chapitre = { 'book', 'bookitem', 'rft.btitle', 'rft.atitle', 'titre section' },
 
        article = { 'journal', 'article', 'rft.atitle', 'rft.jtitle', 'périodique' },
 
        ouvrage = { 'book', 'book', 'rft.btitle', 'rft.atitle', 'titre section' },
 
    }
 
    local genre = tabGenre [ args.genre ]
 
    if not genre then
 
        return ''
 
    end
 
    insertList ( 'rft_val_fmt', genre [1], 'info:ofi/fmt:kev:mtx:' )
 
    insertList ( 'rft.genre',  genre [2] )
 
    insertList ( genre [3], args.titre )
 
    insertList ( genre [4], args [ genre [5] ] )
 
    insertList ( 'rft.stitle', args ['sous-titre'] )
 
   
 
    -- liste des auteur, noms - prénoms
 
    if insertList ( 'rft.aulast', args.nom1 ) then
 
        insertList ( 'rft.aufirst', args [ 'prénom1' ] )
 
    end
 
    insertList ( 'rft.au', args.auteur )
 
    for i = 1, 10 do
 
        local nom = args [ 'nom' .. i]
 
        if nom == nil or nom == '' then
 
            break
 
        else
 
            local prenom = args [ 'prénom' .. i]
 
            if prenom and prenom ~= '' then
 
                prenom = ', ' .. prenom
 
            end
 
            insertList ( 'rft.au', nom .. prenom )
 
        end
 
    end
 
   
 
    -- date
 
    local datePub = Date.dateISO { args [ 'année' ], args.mois, args.jour }
 
    if datePub then
 
        insertList ( 'rft.date', datePub )
 
    else
 
        insertList ( 'rft.date', args.date )
 
    end
 
   
 
    -- doonée phisique de la publication
 
    insertList ( 'rft.volume', args.volume )
 
    insertList ( 'rft.issue', args [ 'numéro' ] )
 
    insertList ( 'rft.pages', args.pages )
 
    insertList ( 'rft.spage', args [ 'page début' ] )
 
    insertList ( 'rft.tpages', args [ 'pages totales' ] )
 
   
 
    -- donnée sur l'éditeur
 
    insertList ( 'rft.place', args.lieu )
 
    insertList ( 'rft.pub', args [ 'éditeur' ] )
 
    insertList ( 'rft.edition', args [ 'édition' ] )
 
   
 
    -- références internationales
 
    insertList ( 'rft.isbn', args.isbn )
 
    insertList ( 'rft.issn', args.issn )
 
    insertList ( 'rft_id', args.doi, 'info:doi/' )
 
    insertList ( 'rft_id', args.pmid, 'info:pmid/' )
 
    insertList ( 'rft_id', args.oclc, 'info:oclcnum/' )
 
    insertList ( 'rft_id', args.url )
 
   
 
    -- referer : page Wikipedia ou se trouve cette référence
 
    insertList ( 'rfr_id', 'fr.wikipedia.org:' .. mw.title.getCurrentTitle().fullText, 'info:sid/' )
 
   
 
    return '<span class="Z3988" title="' .. table.concat ( liste, '&') .. '">&thinsp;</span>'
 
 
end
 
end
+
 
 
return Biblio
 
return Biblio

Version actuelle datée du 27 avril 2017 à 17:18

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

-- Le module biblio centralise les différentes fonctions utiles pour les bibliographie et références.

local Biblio = {  }

require( 'Module:No globals' )
local Outils = require( 'Module:Outils' )


Biblio.ouvrage = function ( frame )
	local args = Outils.extractArgs( frame )
	local Ouvrage = require( 'Module:Biblio/Ouvrage' )
	return Ouvrage.ouvrage( args ) 
end


Biblio.chapitre = function ( frame )
	local args = Outils.extractArgs( frame )
	local Ouvrage = require( 'Module:Biblio/Ouvrage' )
	return Ouvrage.chapitre( args ) 
end


Biblio.article = function ( frame )
	local args = Outils.extractArgs( frame )
	local Ouvrage = require( 'Module:Biblio/Article' )
	return Ouvrage.article( args ) 
end


Biblio.lienWeb = function( frame )
	local args = Outils.extractArgs( frame )
	local Ouvrage = require( 'Module:Biblio/Lien web' )
	return Ouvrage.lienWeb( args ) 
end

Biblio.lienBrise = function( frame )
	local args = Outils.extractArgs( frame )
	local Ouvrage = require( 'Module:Biblio/Lien web' )
	return Ouvrage.lienBrise( args )
end


Biblio.dictionnaire = function( frame )
	local args = Outils.extractArgs( frame )
	local article = Outils.validTextArg( args, 'notice', 'article', 'titre chapitre' )
	local Ouvrage = require( 'Module:Biblio/Ouvrage' )
	if article then
		args['titre chapitre'] = article
		return Ouvrage.chapitre( args ) 
	else
		args.titre = args['titre ouvrage']
		args['sous-titre'] = args['sous-titre ouvrage']
		args.auteur1 = args['auteur ouvrage']
		args.auteurs = args['auteurs ouvrage']
		return Ouvrage.ouvrage( args )
	end
end

-- catégorise une page en fonction du namespace
local function categorise(args)
	local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true, [104] = true }
	local category = args[1]
	local flag = args[2]
	if type(category) == 'string'
		and flag 
		and namespaceCategorisation[ mw.title.getCurrentTitle().namespace ]
	then
		return '[[Category:' .. category .. ']]'
	end
	return ''
end

Biblio.ISBN = function ( frame )
	local args = Outils.extractArgs( frame )
	if Outils.trim( args[1] ) then
		local newArgs = { isbn = args[1] }
		local i = 2
		while args[i] do
			newArgs[ 'isbn' .. i ] = args[i]
			i = i + 1
		end
		return Biblio.identifiantsBiblio( newArgs )
	else 
		return '<small>([[International Standard Book Number|ISBN]]&nbsp;inconnu)</small>' .. categorise{ 'ISBN nécessaire', true }
	end
end

Biblio.rechercheIsbn = function( frame )
	local args = Outils.extractArgs( frame )
	local References = require( 'Module:Biblio/Références' )
	local newArgs = { isbn = args[1], sansLabel = true, categ = {} }
	local isbn = References.isbn( newArgs ) or ''
	local categ = categorise{ 'Page avec ISBN invalide', newArgs.categ.isbnInvalid }
	return isbn .. categ
end


Biblio.EAN = function ( frame )
	local args = Outils.extractArgs( frame )
	if Outils.trim( args[1] ) then
		local newArgs = { ean = args[1], categ = {} }
		local i = 2
		while args[i] do
			newArgs[ 'ean' .. i ] = args[i]
			i = i + 1
		end
		return Biblio.identifiantsBiblio( newArgs )
	else 
		return '<small>([[EAN 13|EAN]]&nbsp;inconnu)</small>[[Catégorie:EAN nécessaire]]'
	end
end


Biblio.ISSN = function ( frame )
	local args = Outils.extractArgs( frame )
	if Outils.trim( args[1] ) then
		local newArgs = { issn = args[1], categ = {} }
		local i = 2
		while args[i] do
			newArgs[ 'issn' .. i ] = args[i]
			i = i + 1
		end
		return Biblio.identifiantsBiblio( newArgs )
	else 
		return '<small>([[International Standard Serial Number|ISSN]]&nbsp;inconnu)</small>' .. categorise{ 'ISSN nécessaire', true }
	end
end

Biblio.rechercheIssn = function( frame )
	local args = Outils.extractArgs( frame )
	local References = require( 'Module:Biblio/Références' )
	local newArgs = { issn = args[1], sansLabel = true, categ = {} }
	local issn = References.issn( newArgs ) or ''
	local categ = categorise{ 'Page avec ISSN invalide', newArgs.categ.issnInvalid }
	return issn .. categ
end

Biblio.BNF = function ( frame )
	local References = require( 'Module:Biblio/Références' )
	return References.bnf( Outils.extractArgs( frame )[1] )
end

Biblio.enLigne = function ( frame )
	local args = Outils.extractArgs( frame )
	local References = require( 'Module:Biblio/Références' )
	return '<small>[' .. References.enLigne( args )  .. ']</small>'
end

Biblio.identifiantsBiblio = function( frame )
	local args = Outils.extractArgs( frame )
	args.categ = {}
	local References = require( 'Module:Biblio/Références' )
	return References.affichageLiensExternes( args, nil, true, true ) 
		.. categorise{ 'Page avec ISBN invalide', args.categ.isbnInvalid }
		.. categorise{ 'Page avec ISSN invalide', args.categ.issnInvalid }
		.. categorise{ 'Page avec EAN invalide', args.categ.eanInvalid }
end

return Biblio