Module:Biblio/Références : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
(Nouvelle page : -- Les fonctions de ce module sont destinées à être utilisée par un autre module. -- Leur paramètre d'entrée est une table simple (args), voir une chaine (oclc, bnf...) loc...)
 
Ligne 18 : Ligne 18 :
 
 
 
local isbn = validArg( 'isbn', 'ISBN', 'isbn1', 'ISBN1' )
 
local isbn = validArg( 'isbn', 'ISBN', 'isbn1', 'ISBN1' )
local texteIsbn = 'ISBN '
+
if isbn then
while isbn do
+
local texteIsbn = 'ISBN '
local lien = '[[Spécial:Ouvrages de référence/' .. isbn  
+
while isbn do
.. '|<span class="nowrap">' .. texteIsbn .. isbn .. '</span>]]'
+
local lien = '[[Spécial:Ouvrages de référence/' .. isbn  
table.insert( liste, lien )
+
.. '|<span class="nowrap">' .. texteIsbn .. isbn .. '</span>]]'
 
+
table.insert( liste, lien )
i = i + 1
+
isbn = validArg( 'isbn' .. i, 'ISBN' .. i )
+
i = i + 1
texteIsbn = isbn
+
isbn = validArg( 'isbn' .. i, 'ISBN' .. i )
 +
texteIsbn = isbn
 +
end
 +
 +
return mw.text.listToText( liste )
 
end
 
end
 
return mw.text.listToText( liste )
 
 
end
 
end
  

Version du 17 septembre 2013 à 08:01

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

-- Les fonctions de ce module sont destinées à être utilisée par un autre module.
-- Leur paramètre d'entrée est une table simple (args), voir une chaine (oclc, bnf...)

local References = { }


local Outils = require( 'Module:Outils' )
local validTextArg = Outils.validTextArg


-- voir Modèle:ISBN
-- renvoie une liste de chaine formant le résultat du modèle une fois concaténé
function References.isbn( args, validArg )
	local validArg = validArg or function ( ... ) return validTextArg( args, ... ) end
	
	local liste = { }
	local i = 1
	
	local isbn = validArg( 'isbn', 'ISBN', 'isbn1', 'ISBN1' )
	if isbn then
		local texteIsbn = 'ISBN '
		while isbn do
			local lien = '[[Spécial:Ouvrages de référence/' .. isbn 
				.. '|<span class="nowrap">' .. texteIsbn .. isbn .. '</span>]]'
			table.insert( liste, lien )
	
			i = i + 1
			isbn = validArg( 'isbn' .. i, 'ISBN' .. i )
			texteIsbn = isbn
		end
		
		return mw.text.listToText( liste )
	end
end


-- voir Modèle:ISSN
-- renvoie une liste de chaine formant le résultat du modèle une fois concaténé
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
		while issn 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 )
		end
		
		return '[[International Standard Serial Number|ISSN]]&nbsp;' .. mw.text.listToText( liste )
	end
end


local function databaseExterne( num, interne, externe, complement )
	if tonumber( num ) then
		local adresse = 
			interne	
			.. ' <span class="plainlinks noarchive">[http://'
			.. externe 
			.. mw.uri.encode( 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



-- 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 = '&nbsp'
	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
	
	local texte = validArg( 'texte' ) or 'en ligne'
	local date = validArg( 'date', 'consulté le' )
	
	if date then 
		return lang .. esp .. '[' .. url .. ' ' .. texte .. ']&nbsp;(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..." },
		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
	 
	 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