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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Annulation : language ne semble pas standard.
0x010D (discussion | contributions)
Aucun résumé des modifications
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,
-- ou la table transmise à la fonction par une autre fonction d'un module
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.
end


-- fonction abréviation, abréviation discrète
local Outils = require( 'Module:Outils' )
-- 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' }
    if args.abrd then
        table.insert(wikiText, ' class="abbr"')
    end
    table.insert(wikiText, ' title="' .. args[2])
    if args[3] then
        table.insert(wikiText, '" lang="' .. args[3])
    end
    table.insert(wikiText, '">' .. args[1] .. '</abbr>')


     return table.concat (wikiText)
Biblio.ouvrage = function ( frame )
    local args = Outils.extractArgs( frame, 'titre' )
    local Ouvrage = require( 'Module:Biblio/Ouvrage' )
     return Ouvrage.ouvrage( 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.chapitre = function ( frame )
            isbn = mw.text.trim ( args [i] or '' )
    local args = Outils.extractArgs( frame, 'titre', 'titre chapitre', 'titre ouvrage' )
            texteIsbn = isbn
    local Ouvrage = require( 'Module:Biblio/Ouvrage' )
        until isbn == ''
     return Ouvrage.chapitre( args )  
    end
     return '<small>(' .. mw.text.listToText ( liste ) .. ')</small>'
end
end


-- voir Modèle:ISSN
function Biblio.ISSN ( frame )
    local args = extractArgs ( frame )
    local liste = { }
    local i = 1
   
    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
Biblio.article = function ( frame )
            issn = mw.text.trim ( args [i] or '' )
    local args = Outils.extractArgs( frame, 'titre', 'périodique', 'année' )
            texteIsbn = issn
    local Ouvrage = require( 'Module:Biblio/Article' )
        until issn == ''
     return Ouvrage.article( args )  
    end
     return '<small>([[International Standard Serial Number|ISSN]]&nbsp;' .. mw.text.listToText ( liste ) .. ')</small>'
end
end


-- voir Modèle:Module biblio/span initial
Biblio.lienWeb = function( frame )
function Biblio.spanInitial ( frame )
     local args = Outils.extractArgs( frame, 'url', 'titre', 'title' )
     local args = extractArgs ( frame )         -- préparation pour appel par modèle ou direct.
     local Ouvrage = require( 'Module:Biblio/Lien web' )
     local id = args.id or ''
     return Ouvrage.lienWeb( args )  
     if string.len( id ) == 0 then
        id = mw.uri.anchorEncode ( args.id1 .. args.id2 .. args.id3 .. args.id4 .. args.id5 )
    end
    return '<span class="ouvrage" id="' .. id
end
end


-- voir Modèle:Module biblio/libellé
Biblio.ISBN = function ( frame )
function Biblio.libelle ( frame )
     local args = Outils.extractArgs( frame, 'isbn', 'ISBN', 'iSbn1', 'ISBN1' )
     local args = extractArgs ( frame )
     local References = require( 'Module:Biblio/Références' )
     local lib = args ['libellé'] or args [1] or ''
     return '<small>(' .. References.ISBN( args ) .. ')</small>'
     if string.len( lib ) > 0 then
        lib = '<small>[' .. lib .. ']</small> '
    end
    return lib
end
end


-- voir Modèle:Module biblio/indication de langue
 
function Biblio.indicationDeLangue ( frame )
Biblio.ISSN = function ( frame )
     local args = extractArgs ( frame )
     local args = Outils.extractArgs( frame, 'issn', 'ISSN', 'issn1', 'ISSN1' )
    local codeLangue = Langue.codeLangue2 (  args.langue )
     local References = require( 'Module:Biblio/Références' )
    if codeLangue ~= '' and codeLangue ~= 'fr' then
     return References.ISSN( args )
        return Langue.indicationDeLangue { '', codeLangue }
     else
        return ''
     end
end
end


-- voir Modèle:Module biblio/responsabilité principale
function Biblio.responsabilitePrincipale ( frame )
    local args = extractArgs ( frame )
    local nom = args ['nom1'] or ''
   
    if nom == '' then
        return ''
    end
   
    local listeRresponsables = { }  -- contiendra un élément pour chaque nom
    local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true }   
    local responsable, prenom, lien , precision, resp
    local i = 1
   
    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


-- voir Module biblio/responsabilité secondaire
Biblio.enLigne = function ( frame )
function Biblio.responsabiliteSecondaire ( frame )
     local args = Outils.extractArgs( frame, 'lien', 'url' )
     local args = extractArgs ( frame )
     local References = require( 'Module:Biblio/Références' )
    local traducteur = args.traducteur or ''
     return '<small>[' .. References.enLigne( args ) .. ']</small>'
    local preface = args [ 'préface' ] or ''
    local postface = args [ 'postface' ] or ''
    local illustrateur = args.illustrateur or ''
    local photographe = args.photographe or ''
    local libre = args [ 'champ libre' ] or ''
    local liste = { }
   
    if traducteur ~= '' then
        table.insert ( liste, Biblio.abr { 'trad.', 'traduction', abrd = true } .. '&nbsp;' .. traducteur )
     end
    if preface ~= '' then
        table.insert ( liste, Biblio.abr { 'préf.', 'préface', abrd = true } .. '&nbsp;' .. preface )
    end
    if postface ~= '' then
        table.insert ( liste, Biblio.abr { 'post.', 'postface', abrd = true } .. '&nbsp;' .. postface )
     end
    if illustrateur ~= '' then
        table.insert ( liste, Biblio.abr { 'ill.', 'illustrations', abrd = true } .. '&nbsp;' .. illustrateur )
    end
    if photographe ~= '' then
        table.insert ( liste, Biblio.abr { 'photogr.', 'photographies', abrd = true } .. '&nbsp;' .. photographe )
    end
    if libre ~= '' then
        table.insert ( liste, libre )
    end
   
    local texte = table.concat ( liste , ', ')
    if texte ~= '' then
        return '(' .. texte .. ')'
    else
        return ''
    end
end
end


-- voir Modèle:Module biblio/description physique
function Biblio.descriptionPhysique ( frame )
    local args = extractArgs ( frame )
    local form = args.format or ''
    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


-- voir Modèle:COinS bibliographique
function Biblio.COinS ( frame )
    local args = extractArgs ( frame )
    local liste = { }
   
    -- la fonction insert liste ajoute à la table 'liste' un couple 'nom Coins normalisé' - 'donnée'
    -- Si istexte = true, le deuxième élément de tab est considéré comme du texte,
    -- sinon comme le nom d'un paramètre.
    local function insertList ( key, value, prefix )
        prefix = prefix or ''
        if value and value ~= '' then
            table.insert ( liste, key .. '=' .. mw.uri.encode ( prefix .. value ) )
            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] or ''
            if prenom ~= '' then
                prenom = ', ' .. prenom
            end
            insertList ( 'rft.au', nom .. prenom )
        end
    end
   
    -- date
    local datePub = Date.dateISO ( frame )
    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
return Biblio
return Biblio

Version du 17 septembre 2013 à 07:51

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

local Biblio = { }


local Outils = require( 'Module:Outils' )


Biblio.ouvrage = function ( frame )

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

end


Biblio.chapitre = function ( frame )

   local args = Outils.extractArgs( frame, 'titre', 'titre chapitre', 'titre ouvrage' )
   local Ouvrage = require( 'Module:Biblio/Ouvrage' )
   return Ouvrage.chapitre( args ) 

end


Biblio.article = function ( frame )

   local args = Outils.extractArgs( frame, 'titre', 'périodique', 'année' )
   local Ouvrage = require( 'Module:Biblio/Article' )
   return Ouvrage.article( args ) 

end

Biblio.lienWeb = function( frame )

   local args = Outils.extractArgs( frame, 'url', 'titre', 'title' )
   local Ouvrage = require( 'Module:Biblio/Lien web' )
   return Ouvrage.lienWeb( args ) 

end

Biblio.ISBN = function ( frame )

   local args = Outils.extractArgs( frame, 'isbn', 'ISBN', 'iSbn1', 'ISBN1' )
   local References = require( 'Module:Biblio/Références' )
   return '(' .. References.ISBN( args ) .. ')'

end


Biblio.ISSN = function ( frame )

   local args = Outils.extractArgs( frame, 'issn', 'ISSN', 'issn1', 'ISSN1' )
   local References = require( 'Module:Biblio/Références' )
   return References.ISSN( args ) 

end


Biblio.enLigne = function ( frame )

   local args = Outils.extractArgs( frame, 'lien', 'url' )
   local References = require( 'Module:Biblio/Références' )
   return '[' .. References.enLigne( args )  .. ']'

end


return Biblio