Différences entre les pages « Module:Langue » et « Module:Biblio/Commun »

De Les Mots de l'agronomie
(Différence entre les pages)
imported>Jacques Ducloy
m (1 révision importée)
 
imported>Jacques Ducloy
m (1 révision importée)
 
Ligne 1 : Ligne 1 :
local Langue = { }
+
-- Les fonctions du module Biblio/Commun sont des éléments nécessaire au modules Biblio/Ouvrage, Biblio/Article, Biblio/Lien web.
  
-- Chargement de la base de données des langues avec gestion d'erreur.
+
local Commun = {}
local dataLangue
+
 
local moduleData = 'Module:Langue/Data'
+
 
local langErrorMess = '<span class=error>langue non reconnue : %s</span>'
+
local Date = require( 'Module:Date' )
local success, resultat = pcall (mw.loadData, moduleData )
+
local Outils = require( 'Module:Outils' )
success = success and type( resultat.en ) == 'table'
+
local TableBuilder = require( 'Module:TableBuilder' )
if success then
+
local Langue -- = require( 'Module:Langue' ) ne sera chargé que si nécessaire
dataLangue = resultat
+
local Languedata -- = mw.loadData( 'Module:Langue/Data' ) ne sera chargé que si nécessaire
else
+
 
-- Base de données a minima en cas de bug sur le Module:Langue/Data
+
local abr = Outils.abr      -- fonction abréviation discréte
dataLangue = { en = { code = 'en', nom = 'anglais' },
+
 
fr = { code = 'fr', nom = 'français' },
+
-- extractArgs permet de récupérer les arguement du modèle,
de = { code = 'de', nom = 'allemand' },
+
-- ou la table transmise à la fonction par une autre fonction d'un module
es = { code = 'es', nom = 'espagnol' },
+
local extractArgs = Outils.extractArgs
it = { code = 'it', nom = 'italien' },
+
 
la = { code = 'la', nom = 'latin'   },
+
function Commun.validTextArg( args, name, ... )
['rtl script'] = { Arab = true }
+
local texte = args[name]
}
+
if type( texte ) == 'string' and texte ~= '' and texte:match( '%S' ) then
dataLangue.anglais = dataLangue.en
+
return texte
dataLangue['français'] = dataLangue.fr
+
elseif #{ ... } > 0 then
dataLangue.allemand = dataLangue.de
+
return Commun.validTextArg( args, ... )
dataLangue.espagnol = dataLangue.es
+
end
dataLangue.italien = dataLangue.it
 
 
end
 
end
  
-- premierParametre renvoie le premier paramètre de Frame, que celui-ci ait été passé au module par invoke, directement au modèle,
+
 
-- ou à l'intérieur d'un module sous forme de string dans un tableau ou directement de string.
+
-- Abréviation utiles
-- Si aucun de ces arguments ne contient de chaine, la fonction renvoie nil.
+
Commun.chap =  abr{ 'chap.', 'chapitre(s)', nbsp='+' }
-- Si le deuxième paramètre est true, la chaine est renvoyée trimée et en minuscules.
+
Commun.coll =  abr{ 'coll.', 'collection', nbsp='+' }
local function premierParametre( frame, lowerCase )
+
Commun.ed =    abr{ 'éd.', 'édition', nbsp='-' }
local arg
+
Commun.nbp =    abr{ 'p.', 'pages', nbsp='-' }
if type( frame ) == 'table' then
+
Commun.numero = abr{ 'n<sup>o</sup>', 'numéro', nbsp='+' }
arg = ( frame.getParent and ( frame.args[1] or frame:getParent().args[1] ) ) or frame[1]
+
Commun.page =  abr{ 'p.', 'page(s)', nbsp='+' }
elseif type( frame ) == 'string' then
+
Commun.plume = '<span class=nowrap title="Ouvrage utilisé pour la rédaction de l\'article">\194\160[[Image:Nuvola apps ksig horizonta.png|30px|link=|alt=]]</span>'
arg = frame
+
Commun.premiere = abr{ '1<sup>re</sup>', 'première' }
end
+
Commun.reimpr = abr{ 'réimpr.', 'réimpression', nbsp='+' }
if type( arg ) ~= 'string' then
+
Commun.tome = abr{ 't.', 'tome', nbsp='+' }
arg = nil
+
Commun.vol = abr{ 'vol.', 'volume', nbsp='+' }
 +
 
 +
 
 +
function Commun.detailEdition( ref )
 +
return '<small>&#91;[[' .. ref .. '|détail de l’édition]]&#93;</small>'
 +
end
 +
 
 +
function Commun.detailEditions( ref )
 +
return '<small>&#91;[[' .. ref .. '|détail des éditions]]&#93;</small>'
 +
end
 +
 
 +
 
 +
-- affiche le texte en nombre romain majuscule.
 +
function Commun.romain( texte )
 +
    local a = '<span class="romain" style="text-transform:uppercase">'
 +
    local b = '</span>'
 +
    return a, texte, b
 +
end
 +
 
 +
function Commun.fusionTexteLien( texte, lien, categ )
 +
local categorisation, result
 +
local message = '<sup style="color:red;">[le lien externe a été retiré]</sup>'
 +
if lien and lien ~= '' then
 +
if texte:match( '%[%[' ) then
 +
result = Commun.fusionTexteLien( texte, nil, categ )
 +
elseif lien:match( '^http' ) or lien:match( '//' ) then
 +
lien = false
 +
categorisation = true
 +
result = texte .. message
 +
else
 +
result = string.format( '[[%s|%s]]', lien, texte )
 +
end
 +
else
 +
--[=[ if texte:match( '//' ) then
 +
result = texte:gsub( '%[https?://[^%[%] ]* *([^%]]+)%]', '%1' )
 +
:gsub( '%[//[^%[%] ]* *([^%]]+)%]', '%1' )
 +
if result ~= texte then
 +
result = result .. message
 +
categorisation = true
 +
end
 +
end ]=] -- désactivé pour le moment (peut être activé si quelqu'un est prêt à corriger les erreurs)
 
end
 
end
if arg and lowerCase then
+
if categorisation and type( categ ) == 'table' then
arg = mw.ustring.lower( mw.text.trim ( arg ) )
+
categ.lienExterne = true
 
end
 
end
return arg
+
return result or texte
 
end
 
end
  
-- determinationCode retourne une table contenant le code de langue principal et la liste des subcode
+
-- voir Modèle:Module biblio/span initial
-- si le code de langue principal n'est pas reconnu, retourne nil.
+
function Commun.spanInitial( args, validArg )
function Langue.determinationCode( langue )
+
local validArg = function ( ... ) return Commun.validTextArg( args, ... ) or false end
if type( langue ) == 'string' and langue ~= '' then
+
local id, id2 = validArg( 'id' )
local tabCode = mw.text.split( langue, '-' )
+
 
local tabLangue = dataLangue[ mw.ustring.lower( tabCode[1] ) ]
+
if id then
if tabLangue and tabLangue.code then
+
id = ' id="' .. id .. '"'
tabCode[1] = tabLangue.code
+
else
if tabLangue.invalide then
+
local nom = validArg( 'nom1', 'nom', 'last1', 'last', 'author' )
tabCode.invalide=true
+
local prenom = validArg( 'prénom1', 'prénom', 'firt1', 'first' )
 +
local postnom = validArg('postnom1', 'postnom' )
 +
local auteur_i = validArg( 'auteur1', 'author1', 'auteur' )
 +
local i = 1
 +
local idTab, id2Tab = { }, { }
 +
 
 +
while nom or auteur_i do
 +
if auteur_i and not nom then
 +
-- tentative de séparation de l'auteur en prénom nom.
 +
-- Enregistre le résultat dans args pour les COinS.
 +
auteur_i = Outils.texteLien( auteur_i )
 +
if auteur_i == '' then
 +
break
 +
end
 +
local a1, a2, a3 = string.match( auteur_i, '^([^ ]+) ?([^ ]*) ?(.*)$' )
 +
if Outils.notEmpty( a3 ) then
 +
local a2len = mw.ustring.len( a2 )
 +
if a2len == 1 or ( a2len == 2 and mw.ustring.sub( a2, -1 ) == "." ) then
 +
-- a1 est le prénom, a2 une initiale et a3 le nom
 +
nom = a3
 +
if i == 1 then
 +
args.nom = a3
 +
args['prénom'] = a1 .. ' ' .. a2
 +
end
 +
else
 +
-- a2 peut être le deuxième prénon ou le début du nom
 +
nom = a2 .. ' ' .. a3
 +
end
 +
elseif Outils.notEmpty( a2 ) then
 +
-- a1 prénom, a2 nom
 +
nom = a2
 +
if i == 1 then
 +
args.nom = a2
 +
args['prénom'] = a1
 +
end
 +
else
 +
nom = a1
 +
end
 +
end
 +
if not auteur_i then
 +
if prenom and postnom then
 +
auteur_i = prenom .. ' ' .. nom .. ' ' .. postnom
 +
elseif prenom then
 +
auteur_i = prenom .. ' ' .. nom
 +
elseif postnom then
 +
auteur_i = nom .. ' ' .. postnom
 +
else
 +
auteur_i = nom
 +
end
 +
end
 +
table.insert( idTab, mw.uri.anchorEncode( nom ) )
 +
table.insert( id2Tab, mw.uri.anchorEncode( auteur_i ) )
 +
 
 +
if i == 4 then
 +
break
 +
end
 +
i = i + 1
 +
nom = validArg( 'nom' .. i, 'last' .. i )
 +
prenom = validArg( 'prénom' .. i, 'first' .. i )
 +
postnom = validArg( 'postnom' .. i)
 +
auteur_i = validArg( 'auteur' .. i, 'author' .. i )
 +
end
 +
 
 +
if #idTab < 4 and validArg( 'auteur institutionnel' ) then
 +
table.insert( idTab, mw.uri.anchorEncode( validArg( 'auteur institutionnel' ) ) )
 +
table.insert( id2Tab, idTab[#idTab] )
 +
end
 +
 
 +
local annee = validArg( 'année', 'year', 'date' )
 +
if annee then
 +
local t, d = Date.separationJourMoisAnnee( annee )
 +
if t and annee ~= d.annee then
 +
annee = tostring( d.annee )
 +
args['année'] = annee
 +
if d.mois then
 +
args.mois = args.mois or tostring( d.mois )
 +
end
 +
if d.jour then
 +
args.jour = args.jour or tostring( d.jour )
 +
end
 +
elseif mw.ustring.find( annee, "%a" ) and annee:find( "%f[%d]%d%d%d%d%f[%D]" ) then
 +
annee = annee:match( "%f[%d]%d%d%d%d%f[%D]" )
 
end
 
end
return tabCode
+
annee = mw.uri.anchorEncode( tostring( annee ) )
 +
table.insert( idTab, annee )
 +
table.insert( id2Tab, annee )
 
end
 
end
 +
 +
if #idTab > 0 then
 +
id = ' id="' .. table.concat( idTab ) .. '"'
 +
id2 = ' id="' .. table.concat( id2Tab ) .. '"'
 +
if id2 == id then
 +
id2 = false
 +
end
 +
else
 +
id = ''
 +
end
 +
end
 +
 +
local spaninitial, spanfinal
 +
if id2 then
 +
spaninitial = '<span class="ouvrage"' .. id .. '><span class="ouvrage"' .. id2 .. '>'
 +
spanfinal = '</span></span>'
 +
else
 +
spaninitial = '<span class="ouvrage"' .. id .. '>'
 +
spanfinal = '</span>'
 
end
 
end
 +
return spaninitial, spanfinal
 
end
 
end
  
-- Voir Modèle:Code langue
+
-- voir Modèle:Module biblio/libellé
-- Paramètre :
+
function Commun.libelle( args )
--    1  : nom de langue.
+
local lib = args['libellé'] or ''
function Langue.codeLangue( frame )
+
if lib ~= '' then
local arg = premierParametre( frame, true )
+
lib = '<small>[' .. lib .. ']</small> '
local tabCode = Langue.determinationCode( arg )
+
end
return ( tabCode and table.concat( tabCode, '-' ) ) or arg or ''
+
return lib
 
end
 
end
  
-- Voir Modèle:Code langue 2
+
-- voir Modèle:Commentaire biblio
-- Paramètre :
+
function Commun.commentaire( args )
--     1  : nom de langue.
+
if Outils.trim( args.commentaire ) then
function Langue.codeLangue2( frame )
+
local a = '<div style="Margin-top:0.1em ;margin-left:2em; line-height:1.5; margin-bottom:0.5em;">'
local arg = premierParametre( frame, true )
+
local b = '</div>'
local tabCode = Langue.determinationCode( arg )
+
return a, args.commentaire, b
return ( tabCode and table.concat( tabCode, '-' ) ) or ''
+
end
 +
return ''
 
end
 
end
  
 +
-- voir Modèle:Module biblio/indication de langue
 +
function Commun.indicationDeLangue( args, validArg )
 +
local lang = validArg( 'langue', 'lang', 'lien langue', 'language' )
 +
if lang then
 +
Langue = require( 'Module:Langue' )
 +
 +
-- on essaie le code de langue complet (nécessaire pour les langues avec plusieurs mot comme "grec ancien")
 +
local codeLangue = Langue.codeLangue2( lang )
 +
 +
if codeLangue == 'fr' or codeLangue:sub(1, 3) == 'fr-' then
 +
return ''
 +
elseif codeLangue ~= '' then
 +
return Langue.indicationMultilingue{ codeLangue }, codeLangue
 +
end
 +
 +
-- si la langue n'a pas été trouvée on considère qu'il y a plusieurs langues
 +
-- séparation des langues s'il y en a plusieurs
 +
local listeLangue = mw.text.split( lang, '[+,;:/ %.]+' )
 +
 +
-- code langue principal qui sera appliqué aux titres
 +
codeLangue = Langue.codeLangue2( listeLangue[1] )
  
-- Voir Modèle:Direction langue
+
if codeLangue == '' then
-- Paramètre :
+
if type( args.categ ) == 'table' then
--    1  : nom de langue ou code IETF.
+
args.categ.langue = true
function Langue.directionLangue( frame )
 
local arg = premierParametre( frame, true )
 
if type( arg ) ~= 'string' or arg == '' then
 
return 'ltr'
 
end
 
-- séparation du code de langue en code principal et les différents subcode.
 
local tabCode = Langue.determinationCode( arg )
 
if tabCode then
 
-- on essaye de savoir si la direction est de droite à gauche
 
local codeScript = tabCode[2]
 
if codeScript and string.len( codeScript ) == 4 and dataLangue[ 'rtl script' ] then
 
-- il y a un subcode d'écritrure, c'est lui qui est pris en compte
 
codeScript = string.upper( string.sub( codeScript, 1, 1 ) ) .. string.sub( codeScript, 2 )
 
if dataLangue[ 'rtl script' ][ codeScript ] then
 
return 'rtl'
 
 
end
 
end
 +
return Langue.indicationMultilingue( listeLangue )
 
else
 
else
-- il n'y a pas de sub-code d'écriture, on prend en compte le code de langue principal.
+
-- calcul code de langue et catégorie
local tabLangue = dataLangue[ tabCode[1] ]
+
local indicationLangue = Langue.indicationMultilingue( listeLangue )
if tabLangue and tabLangue.rtl then
+
if type( args.categ ) == 'table' then
return 'rtl'
+
args.categ.langue = indicationLangue:find( '???', 1, true )
 +
end
 +
 
 +
if codeLangue ~= 'fr' and codeLangue:sub(1, 3) ~= 'fr-' then
 +
return indicationLangue, codeLangue
 +
elseif #listeLangue > 1 then
 +
return indicationLangue, codeLangue
 
end
 
end
 
end
 
end
 
end
 
end
+
return ''
-- la langue n'est pas écrite de droite à gauche, donc ltr.
 
return 'ltr'
 
 
end
 
end
  
  
-- Voir Modèle:Nom langue
+
-- voir Modèle:Module biblio/responsabilité principale
-- Paramètre :
+
function Commun.responsabilitePrincipale( args, validArg )
--    1  : code IETF de langue.
+
 
function Langue.nomLangue( frame )
+
local nom = validArg( 'nom1', 'nom', 'last1', 'last' )
local arg = premierParametre( frame, true )
+
local auteur = validArg( 'auteur1', 'auteur', 'author1', 'author' )
if type( arg ) ~= 'string' or arg == '' then
+
local auteurInstitutionnel = validArg( 'auteur institutionnel' )
return '<span class=error>langue non précisée</span>'
+
if not ( nom or auteur or auteurInstitutionnel ) then
 +
return ''
 
end
 
end
local tabLangue = dataLangue[ arg ]
+
 
if tabLangue == nil then
+
if nom or auteur then
tabLangue = dataLangue[ mw.ustring.match( arg, '^(%a-)%-' ) ]
+
-- clarification des paramètres
 +
args['prénom1'] = validArg( 'prénom1', 'prénom', 'first1', 'first' )
 +
args['postnom1'] = validArg( 'postnom1', 'postnom' )
 +
 
 +
args.directeur1 = validArg( 'directeur1', 'directeur' )
 +
args['lien auteur1'] = validArg( 'lien auteur1', 'lien auteur', 'author-link' )
 
end
 
end
if not tabLangue then
+
 
if success then
+
-- préparation des variables
return string.format( langErrorMess, arg )
+
local listeRresponsables = { }  -- contiendra un élément pour chaque nom
else
+
local directeur = abr { 'dir.', 'directeur de publication' }
return '<span title="erreur dans ' .. moduleData .. '">' .. arg .. '</span>'
+
local prenom, postnom, dir, responsable, lien, precision, resp
 +
local i = 1
 +
 
 +
 
 +
-- boucle sur chaque nom, assemble toutes les caractéristique et ajoute l'ensemble à la liste.
 +
while nom or auteur do
 +
 
 +
-- nom de l'auteur
 +
if not auteur then
 +
prenom = validArg( 'prénom' .. i, 'first' .. i )
 +
nom = '<span class="nom_auteur">' .. nom .. '</span>'
 +
postnom = validArg( 'postnom' .. i)
 +
if prenom and postnom then
 +
auteur = prenom .. ' ' .. nom .. ' ' .. postnom
 +
elseif prenom then
 +
auteur = prenom .. ' ' .. nom
 +
elseif postnom then
 +
auteur = nom .. ' ' .. postnom
 +
else
 +
auteur = nom
 +
end
 
end
 
end
end
+
 
if type( tabLangue.page ) == 'string' then
+
-- lien sur l'auteur
if tabLangue.page ~= '' then
+
auteur = Commun.fusionTexteLien( auteur, args['lien auteur' .. i], args.categ)
return '[[' .. tabLangue.page .. '|' .. tabLangue.nom .. ']]'
+
 
 +
-- définition des responsabilités
 +
dir = validArg( 'directeur' .. i )
 +
resp = validArg( 'responsabilité' .. i )
 +
if dir then
 +
if resp then
 +
precision = ' (' .. directeur .. ' et ' .. resp .. ')'
 +
else
 +
precision = ' (' .. directeur .. ')'
 +
end
 +
elseif resp then
 +
precision = ' (' .. resp .. ')'
 
else
 
else
return tabLangue.nom
+
precision = ''
 
end
 
end
else
 
return '[[' .. tabLangue.nom .. ']]'
 
end
 
end
 
  
 +
table.insert( listeRresponsables, auteur .. precision )
  
-- Voir Modèle:Langue
+
i = i + 1
-- Paramètres :
+
nom = validArg( 'nom' .. i, 'last' .. i )
--    1 : code IETF de langue ;
+
auteur = validArg( 'auteur' .. i, 'author' .. i )
--    texte ou 2 : texte dans cette langue ;
 
--    trans : translittération du texte ;
 
--    dir : direction de la langue (obsolète : peut être en paramètre 1, avec code en 2 et texte en 3).
 
function Langue.langue( frame )
 
local args = ( frame.getParent and frame:getParent().args ) or frame        -- préparation pour appel par modèle ou direct.
 
local code = mw.ustring.lower( mw.text.trim( args[1] or '' ) )
 
local texte = args.texte or ''
 
if texte == '' then
 
texte = args[2] or ''
 
end
 
local dir = args.dir
 
local trans = args.trans
 
 
-- Décalage des paramètres si code contient la direction du texte (obsolète mais toujours possible).
 
if code == 'ltr' or code == 'rtl' then
 
dir = code
 
code = mw.ustring.lower( mw.text.trim( args[2] ) or '' )
 
texte = args[3] or ''
 
end
 
local codeArg = code
 
 
-- Si la langue est reconnue, la valeur de la table est prise en compte (permet de corriger les noms de langue en toutes lettres).
 
local tabCode = Langue.determinationCode( code )
 
local tabLangue
 
if tabCode then
 
code = table.concat( tabCode, '-' )
 
tabLangue = dataLangue[ tabCode[1] ]
 
 
local codeScript = tabCode[2]
 
-- Si codeScript est bien un style d'écriture (len = 4) on applique sa direction
 
if codeScript and  string.len( codeScript ) == 4 and dataLangue[ 'rtl script' ] then
 
-- formatage type Latn correspondant au fromat dans dataLangue[ 'rtl script' ]
 
codeScript = string.upper( string.sub(  codeScript, 1, 1 ) ) .. string.sub(  codeScript, 2 )
 
tabLangue = { code = tabLangue.code,
 
rtl = dataLangue[ 'rtl script' ][ codeScript ],
 
invalide = tabLangue.invalide
 
}
 
end
 
end
 
 
-- Prépatation du rendu de direction du texte.
 
dir = dir and dir:lower()
 
if dir ~= 'ltr' and dir ~= 'rtl' then
 
dir = ( tabLangue and tabLangue.rtl and 'rtl' )
 
end
 
 
 
-- Translittération.
 
local htmlTrans = mw.html.create()
 
if trans and trans ~= '' then
 
trans = trans:gsub( "^''([^'].*[^'])''$", "%1" )
 
htmlTrans:wikitext( " (''" )
 
:tag( 'span' )
 
:addClass( 'transcription lang-' .. code )
 
:attr( 'lang', code .. '-Latn' )
 
:attr( 'dir', 'ltr' )
 
:wikitext( trans )
 
:done()
 
:wikitext( "'')" )
 
 
end
 
end
  
-- Compilation du texte à retourner.
+
local listeAuteurs
local html = mw.html.create( '' )
+
local et_al = ''
if code == '' then
+
if validArg( 'et al.', 'et alii' ) then
html:wikitext( texte )
+
et_al = " ''" .. abr { "et al.", "et alii (et d’autres)" } .. "''"
 +
listeAuteurs = table.concat( listeRresponsables, ', ' ) .. et_al
 
else
 
else
html:tag( 'span' )
+
listeAuteurs = mw.text.listToText( listeRresponsables )
:addClass( 'lang-' .. code )
 
:attr{ lang = code, dir = dir }
 
:wikitext( texte )
 
:done()
 
:node( htmlTrans )
 
 
end
 
end
  
-- Ajout de la catégorie Page avec code de langue invalide si le code langue non reconnu ou invalide.
+
if auteurInstitutionnel then
if success and ( type( tabLangue ) ~= 'table' or tabCode.invalide ) then
+
if #listeRresponsables > 0 then
local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true }
+
return listeAuteurs .. ', ' .. auteurInstitutionnel
if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] then
+
else
if codeArg == '' then
+
return auteurInstitutionnel .. et_al
codeArg = ' ' -- sinon la catégorie n'est pas wikifiée
 
end
 
html:wikitext( '[[Catégorie:Page avec code de langue invalide]] ' )
 
:wikitext( string.format( langErrorMess, codeArg ) )
 
 
end
 
end
 +
else
 +
return listeAuteurs
 
end
 
end
  
return tostring( html )
 
 
end
 
end
  
-- Alias nom de fonction
 
Langue.lang = Langue.langue
 
  
 +
-- voir Module biblio/responsabilité secondaire
 +
function Commun.responsabiliteSecondaire( args, validArg )
 +
local liste = { }
  
-- Voir Modèle:Indication de langue
+
-- fonction qui teste l'existence d'un paramètre et insérere  dans liste une abréviation discrète suivi de ce paramètre
-- Paramètres :
+
local function insertAbr( arg, abrev, texte )
--    1 : nom de langue ;
+
if arg then
--    2 : code IETF ;
+
table.insert( liste, abr{ abrev, texte, nbsp='+' } .. arg )
--    texte : texte dans cette langue ;
 
--    dir : direction de la langue.
 
function Langue.indicationDeLangue( frame )
 
local args = ( frame.getParent and frame:getParent().args ) or frame
 
local nomLangue = args[1] or ''
 
local code = args.langue or mw.text.trim( args[2] or '' )
 
local texte = args.texte
 
local dir = args.dir
 
local wikiText = ''
 
-- Cas où le premier et/ou le deuxième paramètre est vide.
 
if code .. nomLangue == '' then
 
return texte
 
elseif nomLangue == '' then
 
nomLangue = dataLangue[ mw.ustring.lower( code ) ]
 
nomLangue = (nomLangue and nomLangue.nom or '???')
 
elseif code == '' then
 
code = dataLangue[ nomLangue ]
 
code = ( code and code.code or '' )
 
if code == '' then
 
return texte
 
 
end
 
end
 
end
 
end
-- Gestion du texte.
 
if texte and texte ~= '' then
 
texte = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte }
 
else
 
texte = ''
 
end
 
-- Compilation de l'indicateur de langue et du texte.
 
local html = mw.html.create()
 
html:tag( 'span' )
 
:addClass( 'indicateur-langue' )
 
:wikitext( '(' )
 
:tag( 'abbr' )
 
:addClass( 'abbr' )
 
:attr( 'title', 'Langue : ' .. nomLangue )
 
:wikitext( code )
 
:done()
 
:wikitext( ')' )
 
:done()
 
:wikitext( texte )
 
 
return tostring( html )
 
end
 
  
-- Voir Modèle:Mul
+
-- langue originale et traducteur
-- Paramètres : codes IETF ou noms de langue, en nombre indéfini (string ou nil uniquement).
+
local trad = validArg( 'traducteur', 'trad', 'traduction' )
function Langue.indicationMultilingue( frame )
+
local langueOriginale = validArg( 'langue originale' )
local args = (frame.getParent and frame:getParent().args) or frame
+
if langueOriginale then
local listeNom = { }
+
local Languedata = mw.loadData( 'Module:Langue/Data' )
local listeCode = { }
+
langueOriginale = Languedata[langueOriginale] and Languedata[langueOriginale].nom
local tabLangue
 
-- Valeur par défaut du premier paramètre = 'mul'.
 
local code = mw.text.trim( args[1] or '' )
 
if code == '' then
 
code = 'mul'
 
 
end
 
end
+
if langueOriginale then
if not args[2] and not dataLangue[ mw.ustring.lower( code ) ] then
+
if trad then
local split = mw.text.split( code, '[+,;:/ .]+' )
+
trad = ' par ' .. trad
if #split > 1 then  
+
else
return Langue.indicationMultilingue( split )
+
trad = ''
end
 
end
 
-- Ajout des noms et codes de langue de chaque paramètre dans listeNom et ListeCode.
 
local i = 1
 
repeat
 
code = mw.ustring.lower( code )
 
local tabLangue = dataLangue[ code ]
 
if not tabLangue then
 
code = mw.text.split( code, '-' )[1]
 
tabLangue = dataLangue[ code ]
 
 
end
 
end
if type( tabLangue ) == 'table' then
+
if mw.ustring.sub( langueOriginale, 1, 1 ):match( '[a, e, é, è, i, o, u, y]' ) or
table.insert( listeNom, tabLangue.nom )
+
langueOriginale == 'hébreu' then
table.insert( listeCode, tabLangue.code )
+
trad = "de l'" .. langueOriginale .. trad
elseif success then
 
table.insert( listeNom, '???' )
 
local erreur = ' ' .. string.format( langErrorMess, code )
 
table.insert( listeCode, erreur )
 
 
else
 
else
table.insert( listeNom, '??? (erreur dans ' .. moduleData .. ')' )
+
trad = 'du ' .. langueOriginale .. trad
table.insert( listeCode, code )
 
 
end
 
end
i = i + 1
 
code = mw.text.trim( args[i] or '' )
 
until code == ''
 
 
-- Préparation et renvoi du texte.
 
local n = #listeCode
 
local pluriel = ''
 
if #listeCode == 0 then
 
return ''
 
elseif n > 1 then
 
pluriel = 's'
 
 
end
 
end
+
insertAbr( trad, 'trad.', 'traduction' )
local html = mw.html.create( 'span' )
 
html:addClass( 'indicateur-langue' )
 
:wikitext( '(' )
 
:tag( 'abbr' )
 
:addClass( 'abbr' )
 
:attr( 'title', 'Langue' .. pluriel .. ' : ' .. mw.text.listToText( listeNom ) )
 
:wikitext( table.concat( listeCode, '+' ) )
 
:done()
 
:wikitext( ')' )
 
:done()
 
 
return tostring( html )
 
end
 
  
 
+
-- ajout des différents responsables
-- Voir Modèle:Langue avec nom
+
insertAbr( validArg( 'préface' ), 'préf.', 'préface' )
-- Paramètres :
+
if validArg( 'postface' ) then
--    1 : code IETF de langue ;
+
table.insert( liste, 'postface ' .. args.postface )
--    texte ou 2 : texte dans cette langue ;
+
end
--    trans : translittération du texte ;
+
insertAbr( validArg( 'illustrateur' ), 'ill.', 'illustrations' )
--    dir : direction de la langue.
+
insertAbr( validArg( 'photographe' ), 'photogr.', 'photographies' )
function Langue.langueAvecNom( frame )
+
if validArg( 'champ libre' ) then
local args = ( frame.getParent and frame:getParent().args ) or frame
+
table.insert( liste, args['champ libre'] )
local code = mw.ustring.lower( mw.text.trim( args [1] or '') )
 
local texte = args.texte or args[2] or ''
 
local trans = args.trans
 
local dir = args.dir
 
local wikiText = ''
 
 
 
-- Détection de la direction du texte.
 
if code == 'ltr' or code == 'rtl' then
 
dir = code
 
code = mw.ustring.lower( mw.text.trim( args[2] ) )
 
texte = args[3] or ''
 
 
end
 
end
  
-- Définition du nom de la langue en français.
+
-- concaténation de l'ensemble
local nom = Langue.nomLangue{ code }
+
local texte = table.concat( liste, ', ')
 
 
 
if texte ~= '' then
 
if texte ~= '' then
texte = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte, trans = trans }
+
return ' (' .. texte .. ')'
 
end
 
end
 
wikiText = nom .. ' :' .. texte
 
 
return wikiText
 
 
end
 
end
  
 
---
 
---
-- latinOnly détermine si la chaine fournie contien uniquement des caractère latin (étendu, unicode < 880)
+
-- voir émule le modèle:Inscription date
function Langue.nonLatin( frame )
+
-- la détection des arguments permet d'utilisé la fonction depuis un modèle, depuis invoke, ou depuis une autre fonction.
local texte = premierParametre( frame )
+
-- pour facilité l'écriture de lua, annee (sans accent) est accepté lors de l'appel depuis lua.
for codepoint in mw.ustring.gcodepoint( texte ) do
+
function Commun.inscriptionDate( frame )
if codepoint > 879 and not (                 -- > 036F
+
local args = Outils.extractArgs( frame )
codepoint > 7423 and codepoint < 7936 or  -- suppléments phonétique, diacritiques et latin  (1D00 à 1EFF)
+
local annee = Outils.notEmpty( args['année'], args.annee, args.year )
codepoint > 8191 and codepoint < 11392 or -- espace, indices, monaies et symboles divers (2000 à 2C7F)
+
if annee then
codepoint > 42783 and codepoint < 43008  -- latin étendu D  (A720 à A7FF)
+
if annee:match( '^%-?%d+$' ) then
) then
+
-- si l'année est correctement renseigné, on essaye de trouver le mois
return true
+
local mois = Outils.notEmpty( args.mois, args.month, args.saison )
 +
mois = string.lower(Date.determinationMois( mois ) or Date.valideSaison( mois ) or mois or '')
 +
local jour = Outils.notEmpty( args.jour, args.day, args['quantième'] )
 +
local t, jma = Date.validationJourMoisAnnee( jour, mois, annee )
 +
if t then
 +
return Date.modeleDate{ jour, mois, annee, nolinks=true }
 +
else
 +
local date = { jour }
 +
table.insert( date, mois )
 +
table.insert( date, annee )
 +
return '<time class="nowrap" datevalue="' .. annee .. '">' .. table.concat( date, ' ' ) .. '</time>'
 +
end
 +
else
 +
return Commun.inscriptionDate{ date = annee }
 +
end
 +
else
 +
-- si annee n'est pas précisé, on utilise la paramètre date
 +
local date = Outils.validTextArg( args, 'date' )
 +
if date then
 +
date = date:lower()
 +
date = date:gsub( '^(%d%d%d%d%-%d%d%-%d%d)t[%d:+-]+$', '%1') -- Date iso avec l'heure : suppression de l'heure
 +
local t, jma = Date.separationJourMoisAnnee( date )
 +
if t and ( Date.determinationMois( jma.mois ) or Date.valideSaison( jma.mois ) ) then
 +
args['année'] = jma.annee
 +
jma.nolinks = true
 +
jma.nocat = true
 +
return Date.modeleDate( jma )
 +
else
 +
-- date non reconnue, on essaye Month day, year
 +
local mois, jour, annee = mw.ustring.match( date, '^([%a]+)%s*(%d%d?)[,%s]+(%d+)$' )
 +
if Date.determinationMois( mois ) or Date.valideSaison( mois ) then
 +
return Date.modeleDate{ jour, mois, annee, nolinks=true }
 +
end
 +
end
 +
return date
 
end
 
end
 
end
 
end
return false
+
return ''
 
end
 
end
  
-- erreurModuleData affiche un message d'erreur si le Module:Langue/Data n'a pas été chargé correctement,
+
-- retire toutes le lien interne, externe et balise html pour ne garder que le texte brut.
-- pour la page de discussion de la base de données et ceux qui veulent surveiller cette page.
+
local function nettoyageTexte( texte )
function Langue.erreurModuleData()
+
if type( texte ) == 'string'  then
if success == false then
+
if texte:match( '[%[<]' ) then
local message = [[<strong class="error">Le chargement du module Langue/Data génère une erreur : </strong> <br>%s <br>
+
local function texteDuLien( l, t )
 
+
return ( t ~= '' and t ) or l
<span class="error">Cette erreur doit être corrigée au plus vite car des milliers de pages ne s'affichent pas correctement.</span>
+
end
]]
+
-- nettoyage des liens interne
return string.format( message, resultat )
+
texte = texte:gsub( '%[%[([^%[%]|]*)|?([^%[%]]*)%]%]', texteDuLien )
 +
-- nettoyage des liens externes
 +
:gsub( '%[https?://[^%[%] ]* *([^%]]+)%]', '%1' )
 +
:gsub( '%[//[^%[%] ]* *([^%]]+)%]', '%1' )
 +
-- nettoyage des balise html
 +
:gsub( '%b<>', '' )
 +
end
 +
return texte
 
end
 
end
 
end
 
end
  
-- tableauLangues génère un tableau triable de la liste des langues disponible dans Module:langue/Data.
+
-- voir Modèle:COinS bibliographique
function Langue.tableauLangues()
+
-- NISO Z39.88
if type( dataLangue ) ~= 'table' then
+
-- http://www.openurl.info/registry
return
+
function Commun.COinS( args, validArg, genre )
 +
local liste = { }
 +
 
 +
-- insertlist ajoute à la table 'liste' un couple 'nom Coins normalisé' - 'donnée'
 +
-- Si istexte = true, le deuxième élément de tab est considéré comme du texte,
 +
-- sinon comme le nom d'un paramètre.
 +
local function insertList( key, value, prefix )
 +
prefix = prefix or ''
 +
if type( value ) == 'string' and value ~= '' then
 +
table.insert( liste, key .. '=' .. mw.uri.encode( prefix .. value ) )
 +
end
 
end
 
end
  
local tableau = { }
+
-- norme du COinS
local entete = [[{| class="wikitable alternance sortable"
+
insertList( 'ctx_ver', 'Z39.88-2004' )
|-
 
!scope=col|Alias
 
!scope=col|Code IETF
 
!scope=col|Nom principal
 
!scope=col|Page (si différente du nom)
 
!scope=col|RTL
 
!scope=col|Invalide]]
 
  
local ligneTab, ligneSrt
+
-- genre, titre et sous-titre
for i, v in pairs( dataLangue ) do
+
if genre == 'article' then
if v.code then
+
insertList( 'rft_val_fmt', 'info:ofi/fmt:kev:mtx:journal' )
ligneTab = {
+
insertList( 'rft.genre', 'article' )
i,
+
insertList( 'rft.atitle', nettoyageTexte( args.titre ) )
v.code,
+
insertList( 'rft.jtitle', nettoyageTexte( validArg( 'périodique', 'revue', 'journal' ) ) )
v.nom,
+
insertList( 'rft.issue', validArg( 'numéro', 'no', 'issue' ) )
v.page or '',
+
else
v.rtl and '[[Image:Yes check.svg|15px|oui|lien=]]' or '',
+
-- genre = ouvrage ou chaitre
v.invalide and '[[Image:Yes check.svg|15px|oui|lien=]]' or '',
+
insertList( 'rft_val_fmt','info:ofi/fmt:kev:mtx:book' )
}
+
if genre == 'chapitre' then
ligneSrt = table.concat( ligneTab, '\n|' )
+
insertList( 'rft.genre', 'bookitem' )
table.insert( tableau, ligneSrt )
+
else
 +
insertList( 'rft.genre', 'book' )
 
end
 
end
 +
insertList( 'rft.btitle', nettoyageTexte( args.titre ) )
 +
insertList( 'rft.atitle', nettoyageTexte( validArg( 'titre chapitre', 'titreChap' ) ) )
 +
 +
-- donnée sur l'éditeur
 +
insertList( 'rft.place', Outils.texteLien( validArg( 'lieu', 'location' ) ), nil )
 +
insertList( 'rft.pub', Outils.texteLien( validArg( 'éditeur', 'édition' ) ), nil )
 +
insertList( 'rft.edition', args["numéro d'édition"] )
 
end
 
end
table.sort( tableau )
+
insertList( 'rft.stitle', args['sous-titre'] )
table.insert( tableau, 1, entete )
 
table.insert( tableau, '}' )
 
 
return table.concat( tableau, '\n|-\n|' )
 
end
 
  
-- listeCodeAlias génère une liste ; les langues sont de la forme : * code : alias1, alias2
+
-- Premier auteur, séparé en noms et prénoms
function Langue.listeCodeAlias ()
+
local nom = Outils.texteLien( validArg( 'nom1', 'nom', 'last1', 'last' ) )
if type( dataLangue ) ~= 'table' then
+
if nom then
return
+
insertList( 'rft.aulast', nom )
 +
insertList( 'rft.aufirst', validArg( 'prénom1', 'prénom', 'first1', 'first' ) )
 +
insertList( 'rtf.ausuffix ', validArg( 'postnom1', 'postnom' ) )
 +
else
 +
local auteur = Outils.texteLien( validArg( 'auteur', 'auteur1' ) )
 +
if auteur then
 +
insertList( 'rft.au', auteur )
 +
end
 
end
 
end
local languesTab, listeCodesAlias = { }, { }
+
 
local code, alias, codeAlias
+
-- les autres auteurs, la norme ne prévoit pas de séparation
for i, v in pairs( dataLangue ) do
+
for i = 2, 20 do
-- on construit un table avec pour indices les codes de langue, et pour valeurs une table avec la liste des alias
+
local nom_i = Outils.texteLien( validArg( 'nom' .. i ) )
code = v.code
+
if nom_i then
if code and not v.invalide then
+
local prenom_i = validArg( 'prénom' .. i )
languesTab[code] = languesTab[code] or { }
+
local postnom_i = validArg( 'postnom' .. i)
if i ~= mw.ustring.lower( code ) then
+
if prenom_i and postnom_i then
table.insert( languesTab[code], i )
+
insertList( 'rft.au', nom_i .. ' ' .. postnom_i .. ', ' .. prenom_i )
 +
elseif prenom_i then
 +
insertList( 'rft.au', nom_i .. ', ' .. prenom_i )
 +
elseif postnom_i then
 +
insertList( 'rft.au', nom_i .. ' ' .. postnom_i )
 +
else
 +
insertList( 'rft.au', nom_i )
 +
end
 +
else
 +
local auteur_i = Outils.texteLien( validArg( 'auteur' .. i ) )
 +
if auteur_i then
 +
insertList( 'rft.au', auteur_i )
 +
else
 +
break
 
end
 
end
 
end
 
end
 
end
 
end
for i, v in pairs( languesTab ) do
+
 
-- transformation en un table séquence, avec pour valeur une chaine correspondant à une ligne de la liste
+
if validArg( 'auteur institutionnel' ) then
alias = table.concat( v, ', ' )
+
insertList( 'rft.aucorp', args['auteur institutionnel'] )
if alias == '' then
 
codeAlias = '* <code>' .. i .. '</code>'
 
else
 
codeAlias = '* <code>' .. i .. '</code> : ' .. alias
 
end
 
table.insert( listeCodesAlias, codeAlias )
 
 
end
 
end
table.sort( listeCodesAlias )
 
 
return table.concat( listeCodesAlias, '\n' )
 
end
 
  
-- listeAliasCode génère une liste ; les langues sont de la forme :  * alias : code
+
-- date
function Langue.listeAliasCode ()
+
local datePub = Date.dateISO( args )
if type( dataLangue ) ~= 'table' then
+
if datePub then
return
+
insertList( 'rft.date', datePub )
 +
else
 +
insertList( 'rft.date', args.date )
 
end
 
end
local languesTab = { }
+
 
local code
+
-- doonées physique de la publication
for i, v in pairs( dataLangue ) do
+
insertList( 'rft.volume', validArg( 'volume', 'vol' ) )
-- on construit un table avec pour indices les codes de langue, et pour valeurs une table avec la liste des alias
+
insertList( 'rft.pages', validArg( 'passage', 'page' ) )
code = v.code
+
insertList( 'rft.spage', args['page début chapitre'] )
if code and i ~= code and not v.invalide then
+
insertList( 'rft.tpages', args['pages totales'] )
table.insert( languesTab, '* ' .. i .. ' = ' .. code )
+
 
end
+
 
 +
-- références internationales
 +
insertList( 'rft.isbn', args.isbn )
 +
insertList( 'rft.issn', args.issn )
 +
insertList( 'rft_id', args.doi, 'info:doi/' )
 +
insertList( 'rft_id', args.pmid, 'info:pmid/' )
 +
insertList( 'rft_id', args.oclc, 'info:oclcnum/' )
 +
insertList( 'rft_id', args.url )
 +
 
 +
-- referer : page Wikipedia ou se trouve cette référence
 +
insertList( 'rfr_id', 'fr.wikipedia.org:' .. mw.title.getCurrentTitle().fullText, 'info:sid/' )
 +
 
 +
local contextObject = table.concat( liste, '&' )
 +
 
 +
-- calcul d'un id pour que le span vide ne soit pas supprimé par tydy ( cf. https://bugzilla.wikimedia.org/show_bug.cgi?id=27786 )
 +
local id=0
 +
for i = 1, #contextObject do
 +
id = id + string.byte( contextObject, i )
 
end
 
end
table.sort( languesTab )
+
 
+
return '<span class="Z3988" title="' .. contextObject .. '" id="COinS_' .. id ..'"></span>'
return table.concat( languesTab, '\n' )
 
 
end
 
end
  
return Langue
+
 
 +
return Commun

Version actuelle datée du 28 décembre 2020 à 11:53

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

-- Les fonctions du module Biblio/Commun sont des éléments nécessaire au modules Biblio/Ouvrage, Biblio/Article, Biblio/Lien web.

local Commun = {}


local Date = require( 'Module:Date' )
local Outils = require( 'Module:Outils' )
local TableBuilder = require( 'Module:TableBuilder' )
local Langue -- = require( 'Module:Langue' ) ne sera chargé que si nécessaire
local Languedata -- = mw.loadData( 'Module:Langue/Data' ) ne sera chargé que si nécessaire

local abr = Outils.abr      -- fonction abréviation discréte

-- extractArgs permet de récupérer les arguement du modèle,
-- ou la table transmise à la fonction par une autre fonction d'un module
local extractArgs = Outils.extractArgs

function Commun.validTextArg( args, name, ... )
	local texte = args[name]
	if type( texte ) == 'string' and texte ~= '' and texte:match( '%S' ) then
		return texte
	elseif #{ ... } > 0 then
		return Commun.validTextArg( args, ... )
	end
end


-- Abréviation utiles
Commun.chap =   abr{ 'chap.', 'chapitre(s)', nbsp='+' }
Commun.coll =   abr{ 'coll.', 'collection', nbsp='+' }
Commun.ed =     abr{ 'éd.', 'édition', nbsp='-' }
Commun.nbp =    abr{ 'p.', 'pages', nbsp='-' }
Commun.numero = abr{ 'n<sup>o</sup>', 'numéro', nbsp='+' }
Commun.page =   abr{ 'p.', 'page(s)', nbsp='+' }
Commun.plume = '<span class=nowrap title="Ouvrage utilisé pour la rédaction de l\'article">\194\160[[Image:Nuvola apps ksig horizonta.png|30px|link=|alt=]]</span>'
Commun.premiere = abr{ '1<sup>re</sup>', 'première' }
Commun.reimpr = abr{ 'réimpr.', 'réimpression', nbsp='+' }
Commun.tome = abr{ 't.', 'tome', nbsp='+' }
Commun.vol = abr{ 'vol.', 'volume', nbsp='+' }


function Commun.detailEdition( ref )
	return '<small>&#91;[[' .. ref .. '|détail de l’édition]]&#93;</small>'
end

function Commun.detailEditions( ref )
	return '<small>&#91;[[' .. ref .. '|détail des éditions]]&#93;</small>'
end


-- affiche le texte en nombre romain majuscule.
function Commun.romain( texte )
    local a = '<span class="romain" style="text-transform:uppercase">'
    local b = '</span>'
    return a, texte, b
end

function Commun.fusionTexteLien( texte, lien, categ )
	local categorisation, result
	local message = '<sup style="color:red;">[le lien externe a été retiré]</sup>'
	if lien and lien ~= '' then
		if texte:match( '%[%[' ) then
			result = Commun.fusionTexteLien( texte, nil, categ )
		elseif lien:match( '^http' ) or lien:match( '//' ) then
			lien = false
			categorisation = true
			result = texte .. message
		else
			result = string.format( '[[%s|%s]]', lien, texte )
		end
	else
		--[=[ if texte:match( '//' ) then
			result = texte:gsub( '%[https?://[^%[%] ]* *([^%]]+)%]', '%1' )
								:gsub( '%[//[^%[%] ]* *([^%]]+)%]', '%1' )
			if result ~= texte then
				result = result .. message
				categorisation = true
			end
		end ]=] -- désactivé pour le moment (peut être activé si quelqu'un est prêt à corriger les erreurs)
	end
	if categorisation and type( categ ) == 'table' then
		categ.lienExterne = true
	end
	return result or texte
end

-- voir Modèle:Module biblio/span initial
function Commun.spanInitial( args, validArg )
	local validArg = function ( ... ) return Commun.validTextArg( args, ... ) or false end
	local id, id2 = validArg( 'id' )

	if id then
		id = ' id="' .. id .. '"'
	else
		local nom = validArg( 'nom1', 'nom', 'last1', 'last', 'author' )
		local prenom = validArg( 'prénom1', 'prénom', 'firt1', 'first' )
		local postnom = validArg('postnom1', 'postnom' )
		local auteur_i = validArg( 'auteur1', 'author1', 'auteur' )
		local i = 1
		local idTab, id2Tab = { }, { }

		while nom or auteur_i do
			if auteur_i and not nom then
				-- tentative de séparation de l'auteur en prénom nom.
				-- Enregistre le résultat dans args pour les COinS.
				auteur_i = Outils.texteLien( auteur_i )
				if auteur_i == '' then
					break
				end
				local a1, a2, a3 = string.match( auteur_i, '^([^ ]+) ?([^ ]*) ?(.*)$' )
				if Outils.notEmpty( a3 ) then
					local a2len = mw.ustring.len( a2 )
					if a2len == 1 or ( a2len == 2 and mw.ustring.sub( a2, -1 ) == "." ) then
						-- a1 est le prénom, a2 une initiale et a3 le nom
						nom = a3
						if i == 1 then
							args.nom = a3
							args['prénom'] = a1 .. ' ' .. a2
						end
					else
						-- a2 peut être le deuxième prénon ou le début du nom
						nom = a2 .. ' ' .. a3
					end
				elseif Outils.notEmpty( a2 ) then
					-- a1 prénom, a2 nom
					nom = a2
					if i == 1 then
						args.nom = a2
						args['prénom'] = a1
					end
				else
					nom = a1
				end
			end
			if not auteur_i then
				if prenom and postnom then
					auteur_i = prenom .. ' ' .. nom .. ' ' .. postnom
				elseif prenom then
					auteur_i = prenom .. ' ' .. nom
				elseif postnom then
					auteur_i = nom .. ' ' .. postnom
				else
					auteur_i = nom
				end
			end
			table.insert( idTab, mw.uri.anchorEncode( nom ) )
			table.insert( id2Tab, mw.uri.anchorEncode( auteur_i ) )

			if i == 4 then
				break
			end
			i = i + 1
			nom = validArg( 'nom' .. i, 'last' .. i )
			prenom = validArg( 'prénom' .. i, 'first' .. i )
			postnom = validArg( 'postnom' .. i)
			auteur_i = validArg( 'auteur' .. i, 'author' .. i )
		end

		if #idTab < 4 and validArg( 'auteur institutionnel' ) then
			table.insert( idTab, mw.uri.anchorEncode( validArg( 'auteur institutionnel' ) ) )
			table.insert( id2Tab, idTab[#idTab] )
		end

		local annee = validArg( 'année', 'year', 'date' )
		if annee then
			local t, d = Date.separationJourMoisAnnee( annee )
			if t and annee ~= d.annee then
				annee = tostring( d.annee )
				args['année'] = annee
				if d.mois then
					args.mois = args.mois or tostring( d.mois )
				end
				if d.jour then
					args.jour = args.jour or tostring( d.jour )
				end
			elseif mw.ustring.find( annee, "%a" ) and annee:find( "%f[%d]%d%d%d%d%f[%D]" ) then
				annee = annee:match( "%f[%d]%d%d%d%d%f[%D]" )
			end
			annee = mw.uri.anchorEncode( tostring( annee ) )
			table.insert( idTab, annee )
			table.insert( id2Tab, annee )
		end

		if #idTab > 0 then
			id = ' id="' .. table.concat( idTab ) .. '"'
			id2 = ' id="' .. table.concat( id2Tab ) .. '"'
			if id2 == id then
				id2 = false
			end
		else
			id = ''
		end
	end

	local spaninitial, spanfinal
	if id2 then
		spaninitial = '<span class="ouvrage"' .. id .. '><span class="ouvrage"' .. id2 .. '>'
		spanfinal = '</span></span>'
	else
		spaninitial = '<span class="ouvrage"' .. id .. '>'
		spanfinal = '</span>'
	end
	return spaninitial, spanfinal
end

-- voir Modèle:Module biblio/libellé
function Commun.libelle( args )
	local lib = args['libellé'] or ''
	if lib ~= '' then
		lib = '<small>[' .. lib .. ']</small> '
	end
	return lib
end

-- voir Modèle:Commentaire biblio
function Commun.commentaire( args )
	if Outils.trim( args.commentaire ) then
		local a = '<div style="Margin-top:0.1em ;margin-left:2em; line-height:1.5; margin-bottom:0.5em;">'
		local b = '</div>'
		return a, args.commentaire, b
	end
	return ''
end

-- voir Modèle:Module biblio/indication de langue
function Commun.indicationDeLangue( args, validArg )
	local lang = validArg( 'langue', 'lang', 'lien langue', 'language' )
	if lang then
		Langue = require( 'Module:Langue' )

		-- on essaie le code de langue complet (nécessaire pour les langues avec plusieurs mot comme "grec ancien")
		local codeLangue = Langue.codeLangue2( lang )

		if codeLangue == 'fr' or codeLangue:sub(1, 3) == 'fr-' then
			return ''
		elseif codeLangue ~= '' then
			return Langue.indicationMultilingue{ codeLangue }, codeLangue
		end

		-- si la langue n'a pas été trouvée on considère qu'il y a plusieurs langues
		-- séparation des langues s'il y en a plusieurs
		local listeLangue = mw.text.split( lang, '[+,;:/ %.]+' )

		-- code langue principal qui sera appliqué aux titres
		codeLangue = Langue.codeLangue2( listeLangue[1] )

		if codeLangue == '' then
			if type( args.categ ) == 'table' then
				args.categ.langue = true
			end
			return Langue.indicationMultilingue( listeLangue )
		else
			-- calcul code de langue et catégorie
			local indicationLangue = Langue.indicationMultilingue( listeLangue )
			if type( args.categ ) == 'table' then
				args.categ.langue = indicationLangue:find( '???', 1, true )
			end

			if codeLangue ~= 'fr' and codeLangue:sub(1, 3) ~= 'fr-' then
				return indicationLangue, codeLangue
			elseif #listeLangue > 1 then
				return indicationLangue, codeLangue
			end
		end
	end
	return ''
end


-- voir Modèle:Module biblio/responsabilité principale
function Commun.responsabilitePrincipale( args, validArg )

	local nom = validArg( 'nom1', 'nom', 'last1', 'last' )
	local auteur = validArg( 'auteur1', 'auteur', 'author1', 'author' )
	local auteurInstitutionnel = validArg( 'auteur institutionnel' )
	if not ( nom or auteur or auteurInstitutionnel ) then
		return ''
	end

	if nom or auteur then
		-- clarification des paramètres
		args['prénom1'] = validArg( 'prénom1', 'prénom', 'first1', 'first' )
		args['postnom1'] = validArg( 'postnom1', 'postnom' )

		args.directeur1 = validArg( 'directeur1', 'directeur' )
		args['lien auteur1'] = validArg( 'lien auteur1', 'lien auteur', 'author-link' )
	end

	-- préparation des variables
	local listeRresponsables = { }  -- contiendra un élément pour chaque nom
	local directeur = abr { 'dir.', 'directeur de publication' }
	local prenom, postnom, dir, responsable, lien, precision, resp
	local i = 1


	-- boucle sur chaque nom, assemble toutes les caractéristique et ajoute l'ensemble à la liste.
	while nom or auteur do

		-- nom de l'auteur
		if not auteur then
			prenom = validArg( 'prénom' .. i, 'first' .. i )
			nom = '<span class="nom_auteur">' .. nom .. '</span>'
			postnom = validArg( 'postnom' .. i)
			if prenom and postnom then
				auteur = prenom .. ' ' .. nom .. ' ' .. postnom
			elseif prenom then
				auteur = prenom .. ' ' .. nom
			elseif postnom then
				auteur = nom .. ' ' .. postnom
			else
				auteur = nom
			end
		end

		-- lien sur l'auteur
		auteur = Commun.fusionTexteLien( auteur, args['lien auteur' .. i], args.categ)

		-- définition des responsabilités
		dir = validArg( 'directeur' .. i )
		resp = validArg( 'responsabilité' .. i )
		if dir then
			if resp then
				precision = ' (' .. directeur .. ' et ' .. resp .. ')'
			else
				precision = ' (' .. directeur .. ')'
			end
		elseif resp then
			precision = ' (' .. resp .. ')'
		else
			precision = ''
		end

		table.insert( listeRresponsables, auteur .. precision )

		i = i + 1
		nom = validArg( 'nom' .. i, 'last' .. i )
		auteur = validArg( 'auteur' .. i, 'author' .. i )
	end

	local listeAuteurs
	local et_al = ''
	if validArg( 'et al.', 'et alii' ) then
		et_al = " ''" .. abr { "et al.", "et alii (et d’autres)" } .. "''"
		listeAuteurs = table.concat( listeRresponsables, ', ' ) .. et_al
	else
		listeAuteurs = mw.text.listToText( listeRresponsables )
	end

	if auteurInstitutionnel then
		if #listeRresponsables > 0 then
			return listeAuteurs .. ', ' .. auteurInstitutionnel
		else
			return auteurInstitutionnel .. et_al
		end
	else
		return listeAuteurs
	end

end


-- voir Module biblio/responsabilité secondaire
function Commun.responsabiliteSecondaire( args, validArg )
	local liste = { }

	-- fonction qui teste l'existence d'un paramètre et insérere  dans liste une abréviation discrète suivi de ce paramètre
	local function insertAbr( arg, abrev, texte )
		if arg then
			table.insert( liste, abr{ abrev, texte, nbsp='+' } .. arg )
		end
	end

	-- langue originale et traducteur
	local trad = validArg( 'traducteur', 'trad', 'traduction' )
	local langueOriginale = validArg( 'langue originale' )
	if langueOriginale then
		local Languedata = mw.loadData( 'Module:Langue/Data' )
		langueOriginale = Languedata[langueOriginale] and Languedata[langueOriginale].nom
	end
	if langueOriginale then
		if trad then
			 trad = ' par ' .. trad
		else
			trad = ''
		end
		if mw.ustring.sub( langueOriginale, 1, 1 ):match( '[a, e, é, è, i, o, u, y]' ) or
			langueOriginale == 'hébreu' then
			trad = "de l'" .. langueOriginale .. trad
		else
			trad = 'du ' .. langueOriginale .. trad
		end
	end
	insertAbr( trad, 'trad.', 'traduction' )

	-- ajout des différents responsables
	insertAbr( validArg( 'préface' ), 'préf.', 'préface' )
	if validArg( 'postface' ) then
		table.insert( liste, 'postface ' .. args.postface )
	end
	insertAbr( validArg( 'illustrateur' ), 'ill.', 'illustrations' )
	insertAbr( validArg( 'photographe' ), 'photogr.', 'photographies' )
	if validArg( 'champ libre' ) then
		table.insert( liste, args['champ libre'] )
	end

	-- concaténation de l'ensemble
	local texte = table.concat( liste, ', ')
	if texte ~= '' then
		return ' (' .. texte .. ')'
	end
end

---
-- voir émule le modèle:Inscription date
-- la détection des arguments permet d'utilisé la fonction depuis un modèle, depuis invoke, ou depuis une autre fonction.
-- pour facilité l'écriture de lua, annee (sans accent) est accepté lors de l'appel depuis lua.
function Commun.inscriptionDate( frame )
	local args = Outils.extractArgs( frame )
	local annee = Outils.notEmpty( args['année'], args.annee, args.year )
	if annee then
		if annee:match( '^%-?%d+$' ) then
			-- si l'année est correctement renseigné, on essaye de trouver le mois
			local mois = Outils.notEmpty( args.mois, args.month, args.saison )
			mois = string.lower(Date.determinationMois( mois ) or Date.valideSaison( mois ) or mois or '')
			local jour = Outils.notEmpty( args.jour, args.day, args['quantième'] )
			local t, jma = Date.validationJourMoisAnnee( jour, mois, annee )
			if t then
				return Date.modeleDate{ jour, mois, annee, nolinks=true }
			else
				local date = { jour }
				table.insert( date, mois )
				table.insert( date, annee )
				return '<time class="nowrap" datevalue="' .. annee .. '">' .. table.concat( date, ' ' ) .. '</time>'
			end
		else
			return Commun.inscriptionDate{ date = annee }
		end
	else
		-- si annee n'est pas précisé, on utilise la paramètre date
		local date = Outils.validTextArg( args, 'date' )
		if date then
			date = date:lower()
			date = date:gsub( '^(%d%d%d%d%-%d%d%-%d%d)t[%d:+-]+$', '%1') -- Date iso avec l'heure : suppression de l'heure
			local t, jma = Date.separationJourMoisAnnee( date )
			if t and ( Date.determinationMois( jma.mois ) or Date.valideSaison( jma.mois ) ) then
				args['année'] = jma.annee
				jma.nolinks = true
				jma.nocat = true
				return Date.modeleDate( jma )
			else
				-- date non reconnue, on essaye Month day, year
				local mois, jour, annee = mw.ustring.match( date, '^([%a]+)%s*(%d%d?)[,%s]+(%d+)$' )
				if Date.determinationMois( mois ) or Date.valideSaison( mois ) then
					return Date.modeleDate{ jour, mois, annee, nolinks=true }
				end
			end
			return date
		end
	end
	return ''
end

-- retire toutes le lien interne, externe et balise html pour ne garder que le texte brut.
local function nettoyageTexte( texte )
	if type( texte ) == 'string'  then
		if texte:match( '[%[<]' ) then
			local function texteDuLien( l, t )
				return ( t ~= '' and t ) or l
			end
			-- nettoyage des liens interne
			texte = texte:gsub( '%[%[([^%[%]|]*)|?([^%[%]]*)%]%]', texteDuLien )
			-- nettoyage des liens externes
				:gsub( '%[https?://[^%[%] ]* *([^%]]+)%]', '%1' )
				:gsub( '%[//[^%[%] ]* *([^%]]+)%]', '%1' )
			-- nettoyage des balise html
				:gsub( '%b<>', '' )
		end
		return texte
	end
end

-- voir Modèle:COinS bibliographique
-- NISO Z39.88
-- http://www.openurl.info/registry
function Commun.COinS( args, validArg, genre )
	local liste = { }

	-- insertlist ajoute à la table 'liste' un couple 'nom Coins normalisé' - 'donnée'
	-- Si istexte = true, le deuxième élément de tab est considéré comme du texte,
	-- sinon comme le nom d'un paramètre.
	local function insertList( key, value, prefix )
		prefix = prefix or ''
		if type( value ) == 'string' and value ~= '' then
			table.insert( liste, key .. '=' .. mw.uri.encode( prefix .. value ) )
		end
	end

	-- norme du COinS
	insertList( 'ctx_ver', 'Z39.88-2004' )

	-- genre, titre et sous-titre
	if genre == 'article' then
		insertList( 'rft_val_fmt', 'info:ofi/fmt:kev:mtx:journal' )
		insertList( 'rft.genre', 'article' )
		insertList( 'rft.atitle', nettoyageTexte( args.titre ) )
		insertList( 'rft.jtitle', nettoyageTexte( validArg( 'périodique', 'revue', 'journal' ) ) )
		insertList( 'rft.issue', validArg( 'numéro', 'no', 'issue' ) )
	else
		-- genre = ouvrage ou chaitre
		insertList( 'rft_val_fmt','info:ofi/fmt:kev:mtx:book' )
		if genre == 'chapitre' then
			insertList( 'rft.genre', 'bookitem' )
		else
			insertList( 'rft.genre', 'book' )
		end
		insertList( 'rft.btitle', nettoyageTexte( args.titre ) )
		insertList( 'rft.atitle', nettoyageTexte( validArg( 'titre chapitre', 'titreChap' ) ) )

		-- donnée sur l'éditeur
		insertList( 'rft.place', Outils.texteLien( validArg( 'lieu', 'location' ) ), nil )
		insertList( 'rft.pub', Outils.texteLien( validArg( 'éditeur', 'édition' ) ), nil )
		insertList( 'rft.edition', args["numéro d'édition"] )
	end
	insertList( 'rft.stitle', args['sous-titre'] )

	-- Premier auteur, séparé en noms et prénoms
	local nom = Outils.texteLien( validArg( 'nom1', 'nom', 'last1', 'last' ) )
	if nom then
		insertList( 'rft.aulast', nom )
		insertList( 'rft.aufirst', validArg( 'prénom1', 'prénom', 'first1', 'first' ) )
		insertList( 'rtf.ausuffix ', validArg( 'postnom1', 'postnom' ) )
	else
		local auteur = Outils.texteLien( validArg( 'auteur', 'auteur1' ) )
		if auteur then
			insertList( 'rft.au', auteur )
		end
	end

	-- les autres auteurs, la norme ne prévoit pas de séparation
	for i = 2, 20 do
		local nom_i = Outils.texteLien( validArg( 'nom' .. i ) )
		if nom_i then
			local prenom_i = validArg( 'prénom' .. i )
			local postnom_i = validArg( 'postnom' .. i)
			if prenom_i and postnom_i then
				insertList( 'rft.au', nom_i .. ' ' .. postnom_i .. ', ' .. prenom_i )
			elseif prenom_i then
				insertList( 'rft.au', nom_i .. ', ' .. prenom_i )
			elseif postnom_i then
				insertList( 'rft.au', nom_i .. ' ' .. postnom_i )
			else
				insertList( 'rft.au', nom_i )
			end
		else
			local auteur_i = Outils.texteLien( validArg( 'auteur' .. i ) )
			if auteur_i then
				insertList( 'rft.au', auteur_i )
			else
				break
			end
		end
	end

	if validArg( 'auteur institutionnel' ) then
		insertList( 'rft.aucorp', args['auteur institutionnel'] )
	end

	-- date
	local datePub = Date.dateISO( args )
	if datePub then
		insertList( 'rft.date', datePub )
	else
		insertList( 'rft.date', args.date )
	end

	-- doonées physique de la publication
	insertList( 'rft.volume', validArg( 'volume', 'vol' ) )
	insertList( 'rft.pages', validArg( 'passage', 'page' ) )
	insertList( 'rft.spage', args['page début chapitre'] )
	insertList( 'rft.tpages', args['pages totales'] )


	-- références internationales
	insertList( 'rft.isbn', args.isbn )
	insertList( 'rft.issn', args.issn )
	insertList( 'rft_id', args.doi, 'info:doi/' )
	insertList( 'rft_id', args.pmid, 'info:pmid/' )
	insertList( 'rft_id', args.oclc, 'info:oclcnum/' )
	insertList( 'rft_id', args.url )

	-- referer : page Wikipedia ou se trouve cette référence
	insertList( 'rfr_id', 'fr.wikipedia.org:' .. mw.title.getCurrentTitle().fullText, 'info:sid/' )

	local contextObject = table.concat( liste, '&' )

	-- calcul d'un id pour que le span vide ne soit pas supprimé par tydy ( cf. https://bugzilla.wikimedia.org/show_bug.cgi?id=27786 )
	local id=0
	for i = 1, #contextObject do
		id = id + string.byte( contextObject, i )
	end

	return '<span class="Z3988" title="' .. contextObject .. '" id="COinS_' .. id ..'"></span>'
end


return Commun