« Module:Biblio » : différence entre les versions
indicationDeLangue : simplification, responsabilitePrincipale : correction boucle infinie |
Ajout des function ISBN, ISSN, responsabiliteSecondaire, descriptionPhysique et COinS |
||
Ligne 2 : | Ligne 2 : | ||
local Langue = require ( 'Module:Langue' ) | local Langue = require ( 'Module:Langue' ) | ||
local Date = require ( 'Module:Date' ) | |||
-- cette simple fonction permet de récupérer les arguement du modèle, | -- cette simple fonction permet de récupérer les arguement du modèle, | ||
Ligne 31 : | Ligne 32 : | ||
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 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 | |||
isbn = mw.text.trim ( args [i] or '' ) | |||
texteIsbn = isbn | |||
until ibsn == '' | |||
end | |||
return '<small>(' .. mw.text.listToText ( liste ) .. ')</small>' | |||
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 | |||
issn = mw.text.trim ( args [i] or '' ) | |||
texteIsbn = issn | |||
until ibsn == '' | |||
end | |||
return '<small>([[International Standard Serial Number|ISSN]] ' .. mw.text.listToText ( liste ) .. ')</small>' | |||
end | |||
-- voir Modèle:Module biblio/span initial | |||
function Biblio.spanInitial ( frame ) | function Biblio.spanInitial ( frame ) | ||
local args = extractArgs ( frame ) -- préparation pour appel par modèle ou direct. | local args = extractArgs ( frame ) -- préparation pour appel par modèle ou direct. | ||
Ligne 40 : | Ligne 89 : | ||
end | end | ||
-- voir Modèle:Module biblio/libellé | |||
function Biblio.libelle ( frame ) | function Biblio.libelle ( frame ) | ||
local args = extractArgs ( frame ) | local args = extractArgs ( frame ) | ||
Ligne 49 : | Ligne 99 : | ||
end | end | ||
-- voir Modèle:Module biblio/indication de langue | |||
function Biblio.indicationDeLangue ( frame ) | function Biblio.indicationDeLangue ( frame ) | ||
local args = extractArgs ( frame ) | local args = extractArgs ( frame ) | ||
Ligne 59 : | Ligne 110 : | ||
end | end | ||
-- voir Modèle:Module biblio/responsabilité principale | |||
function Biblio.responsabilitePrincipale ( frame ) | function Biblio.responsabilitePrincipale ( frame ) | ||
local args = extractArgs ( frame ) | local args = extractArgs ( frame ) | ||
Ligne 67 : | Ligne 119 : | ||
end | end | ||
local listeRresponsables = { } | local listeRresponsables = { } -- contiendra un élément pour chaque nom | ||
local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true } | local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true } | ||
local responsable, prenom, lien , precision, resp | local responsable, prenom, lien , precision, resp | ||
local i = 1 | local i = 1 | ||
repeat | |||
repeat -- boucle sur chaque nom, assemble toutes les caractéristique et ajoute l'ensemble à la liste. | |||
prenom = args [ 'prénom' .. i ] or '' | prenom = args [ 'prénom' .. i ] or '' | ||
if prenom ~= '' then prenom = prenom .. ' ' | if prenom ~= '' then prenom = prenom .. ' ' | ||
Ligne 106 : | Ligne 159 : | ||
if args [ 'et al.' ] == 'oui' then | if args [ 'et al.' ] == 'oui' then | ||
local et_al = " ''" .. Biblio.abr { "et al.", "et alii (et d’autres)", abrd = true } .. "''" | local et_al = " ''" .. Biblio.abr { "et al.", "et alii (et d’autres)", abrd = true } .. "''" | ||
return table.concat ( listeRresponsables, ',' ) .. et_al | return table.concat ( listeRresponsables, ', ' ) .. et_al | ||
else | else | ||
return mw.text.listToText ( listeRresponsables ) | return mw.text.listToText ( listeRresponsables ) | ||
Ligne 112 : | Ligne 165 : | ||
end | end | ||
-- voir Modèle:Module biblio/responsabilité secondaire | |||
function Biblio.responsabiliteSecondaire ( frame ) | |||
local args = extractArgs ( frame ) | |||
local traducteur = args.traducteur or '' | |||
local preface = args [ 'péface' ] 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 } .. ' ' .. traducteur ) | |||
end | |||
if preface ~= '' then | |||
table.insert ( liste, Biblio.abr { 'préf.', 'préface', abrd = true } .. ' ' .. preface ) | |||
end | |||
if illustrateur ~= '' then | |||
table.insert ( liste, Biblio.abr { 'ill.', 'illustrations', abrd = true } .. ' ' .. illustrateur ) | |||
end | |||
if photographe ~= '' then | |||
table.insert ( liste, Biblio.abr { 'photogr.', 'photographies', abrd = true } .. ' ' .. photographe ) | |||
end | |||
if libre ~= '' then | |||
table.insert ( liste, libre ) | |||
end | |||
local texte = table.concat ( liste , ', ') | |||
if texte ~= '' then | |||
return '(' .. texte .. ')' | |||
else | |||
return '' | |||
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 .. ' numéros' ) | |||
end | |||
if volumes ~= '' then | |||
table.insert ( liste, ', ' .. volumes .. ' ' .. Biblio.abr { 'vol.', 'volumes', abrd = true } ) | |||
end | |||
if tomes ~= '' then | |||
table.insert ( liste, ', ' .. tomes .. ' ' .. Biblio.abr { 't.', 'tomes', abrd = true } ) | |||
end | |||
if pages ~= '' then | |||
table.insert ( liste, ', ' .. pages .. ' ' .. Biblio.abr { 'p.', 'pages', abrd = true } ) | |||
end | |||
return table.concat ( liste ) | |||
end | |||
function Biblio.COinS ( frame ) | |||
local args = extractArgs ( frame ) | |||
local fields = { | |||
chapitre = { 'book', { '.genre=', 'bookitem' }, { 'btitle', 'titre'}, { 'atitle', 'titre section' } }, | |||
article = { 'journal', { 'genre', 'article' }, { 'atitle', 'titre'}, { 'jtitle', 'périodique' } }, | |||
ouvrage = { 'book', { 'genre', 'bookitem' }, { 'btitle', 'titre'}, { 'atitle', 'titre section' } }, | |||
soustitre = { '.stitle=', 'sous-titre' }, | |||
{ '.volume=', 'volume' }, | |||
{ '.issue=', 'numéro' }, | |||
{ '.pages=' , 'pages' }, | |||
{ '.spage=', 'page début' }, | |||
{ '.tpages=', 'pages totales' }, | |||
{ '.place=', 'lieu' }, | |||
{ '.pub=', 'éditeur' }, | |||
{ '.edition=' , 'édition' }, | |||
{ '.isbn=', 'isbn' }, | |||
{ '.issn=', 'issn' }, | |||
{ '_id=info:doi/', 'doi' }, | |||
{ '_id=info:pmid/', 'pmid' }, | |||
{ '_id=info:oclcnum/' , 'oclc' }, | |||
{ '_id=', 'url' }, | |||
wikipedia = { '_id=info:sid/fr.wikipedia.org:', mw.title.getCurrentTitle().fullText } | |||
} | |||
local liste = { } | |||
local wikiText = '<span class="Z3988" title="ctx_ver=Z39.88-2004&rft_val_fmt=' .. mw.uri.encode ( 'info:ofi/fmt:kev:mtx:' ) | |||
local function insertList ( tab, istexte ) | |||
local param | |||
if istexte then | |||
param = tab[2] | |||
else | |||
param = args [ tab[2] ] or '' | |||
end | |||
if param ~= '' then | |||
table.insert ( liste, tab[1] .. mw.uri.encode ( param ) ) | |||
return true | |||
end | |||
end | |||
-- genre, titre et sous-titre | |||
local genre = fields [ args.genre ] | |||
table.insert ( liste, genre [1] ) | |||
insertList ( genre [2], true) | |||
insertList ( genre [3] ) | |||
insertList ( genre [4] ) | |||
isertList ( fields.soustitre ) | |||
-- liste des noms - prénoms | |||
for i = 1, 10 do | |||
if insertList ( { 'aulast', 'nom' .. i } ) then | |||
insertList ( { 'aufirst', 'prénom' .. i } ) | |||
end | |||
end | |||
-- date | |||
local datePub = { 'date', 'date' } | |||
if args [ 'année' ] and args [ 'année' ] ~= '' then | |||
local mois, jour = '', '' | |||
if args.mois and args.mois ~= '' then | |||
mois = '-' .. Date.prepend ( args.mois, '0', 2) | |||
end | |||
if args.jour and args.jour ~= '' then | |||
jour = '-' .. Date.prepend ( args.jour, '0', 2) | |||
end | |||
datePub = { 'date', args [ 'année' ] .. mois .. jour } | |||
end | |||
insertList ( datePub ) | |||
-- autres renseignements | |||
for i = 1, #fields do | |||
insertList ( fields [i] ) | |||
end | |||
-- page Wikipedia | |||
insertList ( fields.wikipedia, true) | |||
wikiText = wikiText .. table.concat ( liste, '&rft') .. '"><span style="display: none;"> </span></span>' | |||
return wikiText | |||
end | |||
return Biblio | return Biblio |
Version du 3 août 2013 à 17:53
local Biblio = {}
local Langue = require ( 'Module:Langue' ) 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 -- 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] .. '')
return table.concat (wikiText)
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 inconnu' }
else
local texteIsbn = 'ISBN ' .. isbn
repeat
local lien = '[[Spécial:Ouvrages de référence/' .. isbn
.. '|' .. texteIsbn .. ']]'
table.insert ( liste, lien )
i = i + 1 isbn = mw.text.trim ( args [i] or ) texteIsbn = isbn until ibsn == end return '(' .. mw.text.listToText ( liste ) .. ')'
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' }
else
repeat
local lien = '[http://worldcat.org/issn/'
.. mw.uri.encode( issn ) .. '&lang=fr ' .. issn.. ']]]'
table.insert ( liste, lien )
i = i + 1 issn = mw.text.trim ( args [i] or ) texteIsbn = issn until ibsn == end return '(ISSN ' .. mw.text.listToText ( liste ) .. ')'
end
-- voir Modèle:Module biblio/span initial function Biblio.spanInitial ( frame )
local args = extractArgs ( frame ) -- préparation pour appel par modèle ou direct.
local id = args.id or
if string.len( id ) == 0 then
id = mw.uri.anchorEncode ( args.id1 .. args.id2 .. args.id3 .. args.id4 .. args.id5 )
end
return ' 0 then
lib = '[' .. lib .. '] '
end
return lib
end
-- voir Modèle:Module biblio/indication de langue function Biblio.indicationDeLangue ( frame )
local args = extractArgs ( frame ) local codeLangue = Langue.codeLangue2 ( args.langue ) if codeLangue ~= and codeLangue ~= 'fr' then return Langue.indicationDeLangue { , codeLangue } else return 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 = '' .. 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 Modèle:Module biblio/responsabilité secondaire function Biblio.responsabiliteSecondaire ( frame )
local args = extractArgs ( frame ) local traducteur = args.traducteur or local preface = args [ 'péface' ] 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 } .. ' ' .. traducteur ) end if preface ~= then table.insert ( liste, Biblio.abr { 'préf.', 'préface', abrd = true } .. ' ' .. preface ) end if illustrateur ~= then table.insert ( liste, Biblio.abr { 'ill.', 'illustrations', abrd = true } .. ' ' .. illustrateur ) end if photographe ~= then table.insert ( liste, Biblio.abr { 'photogr.', 'photographies', abrd = true } .. ' ' .. photographe ) end if libre ~= then table.insert ( liste, libre ) end local texte = table.concat ( liste , ', ') if texte ~= then return '(' .. texte .. ')' else return 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 .. ' numéros' ) end if volumes ~= then table.insert ( liste, ', ' .. volumes .. ' ' .. Biblio.abr { 'vol.', 'volumes', abrd = true } ) end if tomes ~= then table.insert ( liste, ', ' .. tomes .. ' ' .. Biblio.abr { 't.', 'tomes', abrd = true } ) end if pages ~= then table.insert ( liste, ', ' .. pages .. ' ' .. Biblio.abr { 'p.', 'pages', abrd = true } ) end return table.concat ( liste )
end
function Biblio.COinS ( frame )
local args = extractArgs ( frame )
local fields = {
chapitre = { 'book', { '.genre=', 'bookitem' }, { 'btitle', 'titre'}, { 'atitle', 'titre section' } },
article = { 'journal', { 'genre', 'article' }, { 'atitle', 'titre'}, { 'jtitle', 'périodique' } },
ouvrage = { 'book', { 'genre', 'bookitem' }, { 'btitle', 'titre'}, { 'atitle', 'titre section' } },
soustitre = { '.stitle=', 'sous-titre' },
{ '.volume=', 'volume' },
{ '.issue=', 'numéro' },
{ '.pages=' , 'pages' },
{ '.spage=', 'page début' },
{ '.tpages=', 'pages totales' },
{ '.place=', 'lieu' },
{ '.pub=', 'éditeur' },
{ '.edition=' , 'édition' },
{ '.isbn=', 'isbn' },
{ '.issn=', 'issn' },
{ '_id=info:doi/', 'doi' },
{ '_id=info:pmid/', 'pmid' },
{ '_id=info:oclcnum/' , 'oclc' },
{ '_id=', 'url' },
wikipedia = { '_id=info:sid/fr.wikipedia.org:', mw.title.getCurrentTitle().fullText }
}
local liste = { }
local wikiText = ''
return wikiText
end
return Biblio