Module:Biblio : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
(Préparation débugage (bis))
(Ajout fonction lienBrise pour le modèle:Lien brisé)
 
(29 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 moduleLangue = require ( 'Module:Langue' )
+
local Biblio = {  }
  
-- 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
 +
 
 +
 
 +
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
 
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.EAN = function ( frame )
    if args.abrd then
+
local args = Outils.extractArgs( frame )
        table.insert(wikiText, ' class="abbr"')
+
if Outils.trim( args[1] ) then
    end
+
local newArgs = { ean = args[1], categ = {} }
    table.insert(wikiText, ' title="' .. args[2])
+
local i = 2
    if args[3] then
+
while args[i] do
        table.insert(wikiText, '" lang="' .. args[3])
+
newArgs[ 'ean' .. i ] = args[i]
    end
+
i = i + 1
    table.insert(wikiText, '">' .. args[1] .. '</abbr>')
+
end
 +
return Biblio.identifiantsBiblio( newArgs )
 +
else
 +
return '<small>([[EAN 13|EAN]]&nbsp;inconnu)</small>[[Catégorie:EAN nécessaire]]'
 +
end
 +
end
 +
 
  
    return table.concat (wikiText)
+
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
 
end
  
function Biblio.spanInitial ( frame )
+
Biblio.rechercheIssn = function( frame )
    local args = extractArgs ( frame )         -- préparation pour appel par modèle ou direct.
+
local args = Outils.extractArgs( frame )
    local id = args.id or ''
+
local References = require( 'Module:Biblio/Références' )
    if string.len( id ) == 0 then
+
local newArgs = { issn = args[1], sansLabel = true, categ = {} }
        id = mw.uri.anchorEncode ( args.id1 .. args.id2 .. args.id3 .. args.id4 .. args.id5 )
+
local issn = References.issn( newArgs ) or ''
    end
+
local categ = categorise{ 'Page avec ISSN invalide', newArgs.categ.issnInvalid }
    return '<span class="ouvrage" id="' .. id
+
return issn .. categ
 
end
 
end
  
function Biblio.libelle ( frame )
+
Biblio.BNF = function ( frame )
    local args = extractArgs ( frame )
+
local References = require( 'Module:Biblio/Références' )
    local lib = args ['libellé'] or args [1] or ''
+
return References.bnf( Outils.extractArgs( frame )[1] )
    if string.len( lib ) > 0 then
 
        lib = '<small>[' .. lib .. ']</small> '
 
    end
 
    return lib
 
 
end
 
end
  
function Biblio.indicationDeLangue ( frame )
+
Biblio.enLigne = function ( frame )
    local args = extractArgs ( frame )
+
local args = Outils.extractArgs( frame )
    local langue = args.langue
+
local References = require( 'Module:Biblio/Références' )
    local codeLangue = moduleLangue.codeLangue2 ( langue )
+
return '<small>[' .. References.enLigne( args ) .. ']</small>'
    if codeLangue ~= '' and codeLangue ~= 'fr' then
 
        langue = moduleLangue.nomLangue ( codeLangue )
 
        return moduleLangue.indicationDeLangue { langue, codeLangue }
 
    else
 
        return ''
 
    end
 
 
end
 
end
  
function Biblio.responsabilitePrincipale ( frame )
+
Biblio.identifiantsBiblio = function( frame )
    local args = extractArgs ( frame )
+
local args = Outils.extractArgs( frame )
    local listeRresponsables = { }
+
args.categ = {}
    local nom = ( args ['nom1'] or '' ) or ''
+
local References = require( 'Module:Biblio/Références' )
   
+
return References.affichageLiensExternes( args, nil, true, true )
    if nom then
+
.. categorise{ 'Page avec ISBN invalide', args.categ.isbnInvalid }
        return ''
+
.. categorise{ 'Page avec ISSN invalide', args.categ.issnInvalid }
    end
+
.. categorise{ 'Page avec EAN invalide', args.categ.eanInvalid }
   
 
    local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true }
 
    local responsable, prenom, lien , precision, resp
 
    local i = 1
 
    repeat
 
        lien = args [ 'lien' .. i ] or ''
 
        if lien ~= '' then lien = lien .. '|' end
 
        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
 
       
 
        responsable = '[[' .. lien .. prenom .. nom .. ']]' .. precision
 
        table.insert ( listeRresponsables, responsable )
 
       
 
        nom = args [ 'nom' .. ( i + 1 ) ] 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
  
 
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