Modul:Biblio/Références
Die Dokumentation für dieses Modul kann unter Modul:Biblio/Références/Doku erstellt werden
-- Les fonctions de ce module sont destinées à être utilisées par un autre module.
-- Leur paramètre d'entrée est une table simple (args), voire une chaine (oclc, bnf...)
local References = { }
local Outils = require( 'Module:Outils' )
local validTextArg = Outils.validTextArg
--[[
ISBN-10 and ISSN validator code calculates checksum across all isbn/issn digits including the check digit. ISBN-13 is checked in checkisbn().
If the number is valid the result will be 0. Before calling this function, issbn/issn must be checked for length and stripped of dashes,
spaces and other non-isxn characters.
]]
function References.is_valid_isxn( isxn_str, len )
local temp = 0
isxn_str = { isxn_str:byte(1, len) } -- make a table of bytes
len = len+1 -- adjust to be a loop counter
for i, v in ipairs( isxn_str ) do -- loop through all of the bytes and calculate the checksum
if v == string.byte( 'X' ) then -- if checkdigit is X
temp = temp + 10 * ( len - i ) -- it represents 10 decimal
else
temp = temp + tonumber( string.char( v ) ) * ( len - i )
end
end
return temp % 11 == 0 -- returns true if calculation result is zero
end
-- Determines whether an ISBN string is valid
function References.checkisbn( isbn_str )
if isbn_str:find( '[^0-9Xx%s-]' ) then -- fail if isbn_str contains anything but digits, hyphens, or X
return false
end
isbn_str = isbn_str:gsub( '[-%s]', '' ):gsub( 'x', 'X' ) -- remove hyphens and spaces
local len = isbn_str:len()
if len == 10 then
if isbn_str:match( '^%d*X?$' ) == nil then
return false
end
return References.is_valid_isxn( isbn_str, 10 )
elseif len == 13 then
local temp = 0
if isbn_str:match( '^%d*$' ) == nil then -- isbn13 or EAN13 contains only numbers
return false
end
isbn_str = { isbn_str:byte( 1, len ) }
for i, v in ipairs( isbn_str ) do
temp = temp + ( 3 - 2 * ( i % 2 ) ) * tonumber( string.char( v ) )
end
return temp % 10 == 0
else
return false
end
end
-- voir Modèle:ISBN
-- renvoie une liste de chaines formant le résultat du modèle une fois concaténées
function References.isbn( args, validArg )
local validArg = validArg or function ( ... ) return validTextArg( args, ... ) end
local liste = { }
local i = 1
local avertissementInvalid = '<sup style="color:red">[à vérifier : isbn invalide]</sup>'
local isbnErr = validArg( 'isbn erroné' )
local isbn = validArg( 'isbn', 'ISBN', 'isbn1', 'ISBN1' )
if isbnErr or isbn then
if isbnErr and isbnErr:find( '[%dXx -]' ) then
local lien
if isbnErr:find( '[%[\127]' ) then
lien = isbnErr .. ' (édité erroné)'
else
lien = '[[Spécial:Ouvrages de référence/' .. isbnErr:match( '[%dXx -]*' )
.. '|<span class="nowrap">' .. isbnErr .. '</span>]] (édité erroné)'
end
table.insert( liste, lien )
end
-- boucle sur les isbn2, 3...
while isbn do
-- vérifivation de la validité de l'ISBN
local isbnValid = References.checkisbn(isbn)
-- préparation du texte à afficher
if isbnValid then
local lien = '[[Spécial:Ouvrages de référence/' .. isbn
.. '|<span class="nowrap">' .. isbn .. '</span>]]'
table.insert( liste, lien )
else
table.insert( liste, isbn .. avertissementInvalid )
args.categIsbnInvalid = true
end
i = i + 1
isbn = validArg( 'isbn' .. i, 'ISBN' .. i )
end
return '[[International Standard Book Number|ISBN]] ' .. mw.text.listToText( liste )
end
end
-- voir Modèle:ISSN
-- renvoie une liste de chaines formant le résultat du modèle une fois concaténées
function References.issn( args, validArg )
local validArg = validArg or function ( ... ) return validTextArg( args, ... ) end
local liste = { }
local i = 1
local issn = validArg( 'issn', 'ISSN', 'issn1', 'ISSN1' )
if issn then
-- on réduit la chaine aux caractères qui peuvent être dans un code issn (pas de test de longueur)
local issnValid = string.match( string.gsub( issn, ' ', '' ), '[%dXx -]*' )
while issnValid do
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 = validArg( 'issn' .. i, 'ISSN' .. i )
issnValid = issn and string.match( string.gsub( issn, ' ', '' ), '[%dXx -]*' )
end
return '[[International Standard Serial Number|ISSN]] ' .. mw.text.listToText( liste )
end
end
local function databaseExterne( num, interne, externe, complement )
if Outils.notEmpty( num ) then
local adresse =
interne
.. ' <span class="plainlinks noarchive">[http://'
.. externe
.. num
.. ( complement or ' ' )
.. num
.. ']</span>'
return adresse
end
end
function References.oclc( oclc )
return databaseExterne( oclc, '[[Online Computer Library Center|OCLC]]', 'worldcat.org/oclc/', '&lang=fr ' )
end
function References.bnf( bnf )
return databaseExterne( bnf, 'notice [[Bibliothèque nationale de France|BnF]] n<sup>o</sup>',
'catalogue.bnf.fr/ark:/12148/cb', '/PUBLIC FRBNF' )
end
function References.lccn( lccn )
return databaseExterne( lccn, '[[Numéro de contrôle de la Bibliothèque du Congrès|LCCN]]', 'lccn.loc.gov/' )
end
function References.dnb( dnb )
return databaseExterne( dnb, '[[Bibliothèque nationale allemande|DNB]]', 'd-nb.info/' )
end
function References.jstor( jstor )
return databaseExterne( jstor, '[[JSTOR]]', 'jstor.org/stable/' )
end
function References.pmid( pmid )
return databaseExterne( pmid, '[[PubMed|PMID]]', 'www.ncbi.nlm.nih.gov/pubmed/' )
end
function References.pmcid( pmcid )
return databaseExterne( pmcid, '[[PubMed Central|PMCID]]', 'www.ncbi.nlm.nih.gov/pmc/articles/' )
end
function References.doi( doi )
return databaseExterne( doi, '[[Digital Object Identifier|DOI]]', 'dx.doi.org/' )
end
function References.bibcode( bibcode )
return databaseExterne( bibcode, '[[Bibcode]]', 'adsabs.harvard.edu/abs/' )
end
function References.mathreviews( mathreviews )
return databaseExterne( mathreviews, '[[Mathematical Reviews|Math Reviews]]', 'www.ams.org/mathscinet-getitem?mr=' )
end
function References.arxiv( arxiv )
return databaseExterne( arxiv, '[[arXiv]]', 'fr.arxiv.org/abs/' )
end
-- enLigne est destiné à remplacer "lire en ligne", "écouter en ligne", "présentation en ligne"
function References.enLigne( args )
local validArg = validArg or function ( ... ) return validTextArg( args, ... ) end
local lang, esp = '', ''
if args.langue then
local Langue = require( 'Module:Langue' )
lang = Langue.indicationMultilingue{ args.langue, args.langue2, args.langue3 }
esp = ' '
end
local url = validArg( 'lien', 'url' )
if url == nil then
if validArg( 'doi' ) then
url = 'http://dx.doi.org/' .. mw.uri.encode( args.doi )
else
return
end
end
url = string.gsub ( string.gsub ( url, '%[', '%%5B' ), '%]', '%%5D' )
local texte = validArg( 'texte' ) or 'en ligne'
local date = validArg( 'date', 'consulté le' )
if date then
return lang .. esp .. '[' .. url .. ' ' .. texte .. '] (consultée le' .. date .. ')'
else
return lang .. esp .. '[' .. url .. ' ' .. texte .. ']'
end
end
function References.indicationDeFormat( format )
if not Outils.trim( format ) then
return
end
local listeFormat = {
audio = { "audio", "Fichiers audio au format mp3, ogg..." },
bat = { "bat", "Script de traitement par lot (batch)" },
djvu = { "DjVu", "Document au format DjVu" },
doc = { "doc", "Document Microsoft Word" },
epub = { "EPUB", "Document au format Epub" },
flash = { "flash", "Animation vectorielle au format Macromedia Flash" },
hlp = { "hlp", "Fichier HeLP (aide) datant de Microsoft Windows 3.1" },
html = { "html", "Fichier au format Hypertext Markup Language (HTML)" },
image = { "image", "Image au format JPEG, PNG, GIF..." },
java = { "java", "Applet Java" },
mov = { "mov", "Vidéo au format Apple QuickTime" },
mp3 = { "MP3", "Son au format MP3 (MPEG-1/2 Audio Layer 3)" },
odt = { "odt", "Document au format OpenDocument" },
ogg = { "ogg", "Fichier au format conteneur Ogg" },
pdf = { "PDF", "Document au format Portable Document Format (PDF) d'Adobe" },
php = { "php", "Script PHP" },
pl = { "pl", "Script Practical Extraction and Report Language (Perl)" },
ppt = { "ppt", "Présentation Microsoft Powerpoint" },
ps = { "ps", "Fichier de description vectorielle au format PostScript" },
radio = { "radio", "Radio au format mpg, avi..." },
rar = { "rar", "Document compressé au format rar" },
rm = { "rm", "Vidéo au format RealMedia, RealAudio..." },
rtf = { "RTF", "Document texte au format Rich Text Format (RTF)" },
svg = { "SVG", "Image vectorielle au format Scalable Vector Graphics (SVG)" },
sxi = { "sxi", "Présentation OpenOffice.org Impress" },
sxw = { "sxw", "Document OpenOffice.org Writer" },
tex = { "TeX", "Document TeX" },
txt = { "txt", "Fichier au format texte brut" },
video = { "vidéo", "Vidéo au format mpg, avi..." },
xls = { "xls", "Classeur Microsoft Excel" },
xml = { "XML", "Document au format Extensible Markup Language (XML)" },
zip = { "zip", "Archive au format Zip" },
}
listeFormat['vidéo'] = listeFormat.video
listeFormat.htm = listeFormat.html
listeFormat.excel = listeFormat.xls
listeFormat.powerpoint = listeFormat.ppt
listeFormat.word = listeFormat.doc
local tabFormat = listeFormat[ string.lower( format ) ]
if tabFormat then
return ( ' <abbr class="abbr indicateur-format" title="' .. tabFormat[2]
.. '">' .. mw.text.nowiki( '[' .. tabFormat[1] .. ']' ) .. '</abbr>' )
else
return mw.text.nowiki( ' [' ) .. format .. mw.text.nowiki( ']' )
end
end
return References