« Module:Biblio » : différence entre les versions
Ajout fonction rechercheIsbn ; rechercheIssn : utilisation du nouveau paramètre 'sansLabel' |
si References.affichageLiensExternes() retourne nil, empêche une erreur Lua ici car on ne peut pas concaténer nil ; j'ai regardé pour faire retourner une chaîne vide par affichageLiensExternes() quand il n'y a aucun lien, mais mieux vaut qu'il continue de retourner nil (le point important est de supporter les deux éventualités dans les codes appelants) |
||
(8 versions intermédiaires par 3 utilisateurs non affichées) | |||
Ligne 3 : | Ligne 3 : | ||
local Biblio = { } |
local Biblio = { } |
||
require( 'strict' ) |
|||
local Outils = require( 'Module:Outils' ) |
local Outils = require( 'Module:Outils' ) |
||
Ligne 32 : | Ligne 32 : | ||
local Ouvrage = require( 'Module:Biblio/Lien web' ) |
local Ouvrage = require( 'Module:Biblio/Lien web' ) |
||
return Ouvrage.lienWeb( args ) |
return Ouvrage.lienWeb( args ) |
||
end |
|||
Biblio.lienBrise = function( frame ) |
|||
local args = Outils.extractArgs( frame ) |
|||
⚫ | |||
return Ouvrage.lienBrise( args ) |
|||
end |
end |
||
Ligne 51 : | Ligne 57 : | ||
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 ) |
Biblio.ISBN = function ( frame ) |
||
local args = Outils.extractArgs( frame ) |
local args = Outils.extractArgs( frame ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local i = 2 |
local i = 2 |
||
while args[i] do |
while args[i] do |
||
newArgs['isbn' .. i] = args[i] |
newArgs[ 'isbn' .. i ] = args[i] |
||
i = i + 1 |
i = i + 1 |
||
end |
end |
||
return Biblio.identifiantsBiblio( newArgs ) |
|||
⚫ | |||
return '<small>(' .. listeISBN .. ')</small>' .. categ |
|||
else |
else |
||
return '<small>([[International Standard Book Number|ISBN]] inconnu)</small>' .. |
return '<small>([[International Standard Book Number|ISBN]] inconnu)</small>' .. categorise{ 'ISBN nécessaire', true } |
||
end |
end |
||
end |
end |
||
Ligne 73 : | Ligne 89 : | ||
local args = Outils.extractArgs( frame ) |
local args = Outils.extractArgs( frame ) |
||
local References = require( 'Module:Biblio/Références' ) |
local References = require( 'Module:Biblio/Références' ) |
||
local newArgs = { isbn = args[1], sansLabel = true, categ = { |
local newArgs = { isbn = args[1], sansLabel = true, categ = {} } |
||
local isbn = References.isbn( newArgs ) or '' |
local isbn = References.isbn( newArgs ) or '' |
||
local categ = |
local categ = categorise{ 'Page avec ISBN invalide', newArgs.categ.isbnInvalid } |
||
return isbn .. categ |
return isbn .. categ |
||
end |
end |
||
Ligne 82 : | Ligne 98 : | ||
Biblio.EAN = function ( frame ) |
Biblio.EAN = function ( frame ) |
||
local args = Outils.extractArgs( frame ) |
local args = Outils.extractArgs( frame ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local i = 2 |
local i = 2 |
||
while args[i] do |
while args[i] do |
||
newArgs['ean' .. i] = args[i] |
newArgs[ 'ean' .. i ] = args[i] |
||
i = i + 1 |
i = i + 1 |
||
end |
end |
||
return Biblio.identifiantsBiblio( newArgs ) |
|||
⚫ | |||
return '<small>(' .. listeEAN .. ')</small>' .. categ |
|||
else |
else |
||
return '<small>([[EAN 13|EAN]] inconnu)</small> |
return '<small>([[EAN 13|EAN]] inconnu)</small>[[Catégorie:EAN nécessaire]]' |
||
end |
end |
||
end |
end |
||
Ligne 101 : | Ligne 114 : | ||
Biblio.ISSN = function ( frame ) |
Biblio.ISSN = function ( frame ) |
||
local args = Outils.extractArgs( frame ) |
local args = Outils.extractArgs( frame ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local i = 2 |
local i = 2 |
||
while args[i] do |
while args[i] do |
||
newArgs['issn' .. i] = args[i] |
newArgs[ 'issn' .. i ] = args[i] |
||
i = i + 1 |
i = i + 1 |
||
end |
end |
||
return Biblio.identifiantsBiblio( newArgs ) |
|||
⚫ | |||
return '<small>(' .. listeISSN .. ')</small>' .. categ |
|||
else |
else |
||
return '<small>(inconnu)</small>' .. |
return '<small>([[International Standard Serial Number|ISSN]] inconnu)</small>' .. categorise{ 'ISSN nécessaire', true } |
||
end |
end |
||
end |
end |
||
Ligne 120 : | Ligne 130 : | ||
local args = Outils.extractArgs( frame ) |
local args = Outils.extractArgs( frame ) |
||
local References = require( 'Module:Biblio/Références' ) |
local References = require( 'Module:Biblio/Références' ) |
||
local newArgs = { issn = args[1], sansLabel = true, categ = { |
local newArgs = { issn = args[1], sansLabel = true, categ = {} } |
||
local issn = References.issn( newArgs ) or '' |
local issn = References.issn( newArgs ) or '' |
||
local categ = |
local categ = categorise{ 'Page avec ISSN invalide', newArgs.categ.issnInvalid } |
||
return issn .. categ |
return issn .. categ |
||
end |
|||
Biblio.BNF = function ( frame ) |
|||
⚫ | |||
return References.bnf( Outils.extractArgs( frame )[1] ) |
|||
end |
end |
||
Ligne 132 : | Ligne 147 : | ||
end |
end |
||
Biblio.identifiantsBiblio = function( frame ) |
|||
local args = Outils.extractArgs( frame ) |
|||
args.categ = {} |
|||
⚫ | |||
return ( References.affichageLiensExternes( args, nil, true, true ) or '' ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
return Biblio |
return Biblio |
Dernière version du 1 juin 2023 à 17:45
Ce module sert de base aux fonctions bibliographiques. Lorsqu'elles sont appelées directement par un modèle (via #invoke), les paramètres passés à ce modèle sont automatiquement transmis au module, sauf si le modèle spécifie une autre valeur pour ce paramètre.
Utilisation
Fonctions exportables :
ouvrage(frame)
– modèle {{Ouvrage}} ;chapitre(frame)
– modèle {{Chapitre}} ;article(frame)
– modèle {{Article}} ;lienWeb(frame)
– modèle {{Lien web}} ;lienBrise(frame)
– modèle {{Lien brisé}} ;dictionnaire(frame)
– appelle le modèle chapitre si un paramètretitre chapitre
,article
ounotice
est non vide, sinon appelle le modèle ouvrage ;ISBN(frame)
– affiche en petit et entre parenthèses ISBN suivi d'autant de codes que de paramètres non nommés, avec lien à la page ad hoc ;ISSN(frame)
– affiche en petit et entre parenthèses ISSN suivi d'autant de codes que de paramètres non nommés, avec lien à la page ad hoc ;enLigne()
– similaire au modèle {{Lire en ligne}} (le texte par défaut est « en ligne »).
Modules externes et autres éléments dont ce module a besoin pour fonctionner :
Module:Outils
Module:Biblio/Références
Module:Biblio/Article
– pour la fonction articleModule:Biblio/Lien web
– pour les fonctions lienWeb et lienBriseModule:Biblio/Ouvrage
– pour la fonction ouvrage, chapitre et dictionnaire
Exemples
Utilisation de la fonction ouvrage
dans un modèle pour afficher une référence :
{{#invoke:Biblio |ouvrage |auteur=Martine Michu |titre=Mes vacances à la mer}}
- Martine Michu, Mes vacances à la mer
Une page utilisant ce modèle avec le paramètre « passage = 28
» affichera :
- Martine Michu, Mes vacances à la mer, p. 28
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
-- Le module biblio centralise les différentes fonctions utiles pour les bibliographie et références.
local Biblio = { }
require( 'strict' )
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]] 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]] 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]] 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 ) or '' )
.. 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