Ligne 6 : |
Ligne 6 : |
| local Date = require( 'Module:Date' ) | | local Date = require( 'Module:Date' ) |
| local Outils = require( 'Module:Outils' ) | | local Outils = require( 'Module:Outils' ) |
− | local TableBuilder = require( 'Module:TableBuilder' )
| |
| local Langue -- = require( 'Module:Langue' ) ne sera chargé que si nécessaire | | 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 Languedata -- = mw.loadData( 'Module:Langue/Data' ) ne sera chargé que si nécessaire |
Ligne 42 : |
Ligne 41 : |
| function Commun.validTextArg( args, name, ... ) | | function Commun.validTextArg( args, name, ... ) |
| local texte = args[name] | | local texte = args[name] |
− | if type( texte ) == 'string' and texte ~= '' and texte:match( '%S' ) then | + | if type( texte ) == 'string' and texte ~= '' then |
| return texte | | return texte |
| elseif #{ ... } > 0 then | | elseif #{ ... } > 0 then |
Ligne 74 : |
Ligne 73 : |
| Commun.numeros = abr{ 'n<sup>os</sup>', 'numéros', nbsp='+' } | | Commun.numeros = abr{ 'n<sup>os</sup>', 'numéros', nbsp='+' } |
| Commun.page = abr{ 'p.', 'page(s)', 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.plume = '<span class="nowrap" title="Ouvrage utilisé pour la rédaction de l\'article">\194\160[[Fichier:Icon_flatdesign_plume.svg|20px|link=|alt=]]</span>' |
| Commun.premiere = abr{ '1<sup>re</sup>', 'première' } | | Commun.premiere = abr{ '1<sup>re</sup>', 'première' } |
| Commun.reimpr = abr{ 'réimpr.', 'réimpression', nbsp='+' } | | Commun.reimpr = abr{ 'réimpr.', 'réimpression', nbsp='+' } |
Ligne 128 : |
Ligne 127 : |
| -- voir Modèle:Module biblio/span initial | | -- voir Modèle:Module biblio/span initial |
| function Commun.spanInitial( args, validArg ) | | function Commun.spanInitial( args, validArg ) |
− | local validArg = function ( ... ) return Commun.validTextArg( args, ... ) or false end
| + | local id = validArg( 'id' ) |
− | local id, id2 = validArg( 'id' ) | + | local id2 |
| | | |
| if id then | | if id then |
Ligne 136 : |
Ligne 135 : |
| local nom = validArg( 'nom1', 'nom', 'last1', 'last', 'author' ) | | local nom = validArg( 'nom1', 'nom', 'last1', 'last', 'author' ) |
| local prenom = validArg( 'prénom1', 'prénom', 'firt1', 'first' ) | | local prenom = validArg( 'prénom1', 'prénom', 'firt1', 'first' ) |
− | local postnom = validArg('postnom1', 'postnom' ) | + | local postnom = validArg( 'postnom1', 'postnom' ) |
| local auteur_i = validArg( 'auteur1', 'author1', 'auteur' ) | | local auteur_i = validArg( 'auteur1', 'author1', 'auteur' ) |
| local i = 1 | | local i = 1 |
Ligne 149 : |
Ligne 148 : |
| break | | break |
| end | | end |
− | local a1, a2, a3 = string.match( auteur_i, '^([^ ]+) ?([^ ]*) ?(.*)$' ) | + | local a1, a2, a3 = string.match( auteur_i, '^([^ ]+) *([^ ]*) *(.*)$' ) |
− | if Outils.notEmpty( a3 ) then | + | if a3 ~= '' then |
| local a2len = mw.ustring.len( a2 ) | | local a2len = mw.ustring.len( a2 ) |
| if a2len == 1 or ( a2len == 2 and mw.ustring.sub( a2, -1 ) == "." ) then | | if a2len == 1 or ( a2len == 2 and mw.ustring.sub( a2, -1 ) == "." ) then |
Ligne 163 : |
Ligne 162 : |
| nom = a2 .. ' ' .. a3 | | nom = a2 .. ' ' .. a3 |
| end | | end |
− | elseif Outils.notEmpty( a2 ) then | + | elseif a2 ~= '' then |
| -- a1 prénom, a2 nom | | -- a1 prénom, a2 nom |
| nom = a2 | | nom = a2 |
Ligne 210 : |
Ligne 209 : |
| args['année'] = annee | | args['année'] = annee |
| if d.mois then | | if d.mois then |
− | args.mois = validArg ('mois' ) or tostring( d.mois ) | + | args.mois = validArg( 'mois' ) or tostring( d.mois ) |
| end | | end |
| if d.jour then | | if d.jour then |
− | args.jour = validArg ('jour' ) or tostring( d.jour ) | + | args.jour = validArg( 'jour' ) or tostring( d.jour ) |
| end | | end |
| elseif mw.ustring.find( annee, "%a" ) and annee:find( "%f[%d]%d%d%d%d%f[%D][a-h]?" ) then | | elseif mw.ustring.find( annee, "%a" ) and annee:find( "%f[%d]%d%d%d%d%f[%D][a-h]?" ) then |
− | -- le [a-h]? final est destiné à accepter les lettres ajoutées lorsqu'il y a plusieurs ouvrage d'un même auteur la même année (cf. [[:en:Template:Harvard citation no brackets#More than one work in a year]]) | + | -- le [a-h]? final est destiné à accepter les lettres ajoutées lorsqu'il y a plusieurs ouvrages d'un même auteur la même année (cf. [[:en:Template:Harvard citation no brackets#More than one work in a year]]) |
| annee = annee:match( "%f[%d]%d%d%d%d%f[%D][a-h]?" ) | | annee = annee:match( "%f[%d]%d%d%d%d%f[%D][a-h]?" ) |
| end | | end |
Ligne 248 : |
Ligne 247 : |
| -- voir Modèle:Module biblio/libellé | | -- voir Modèle:Module biblio/libellé |
| function Commun.libelle( args ) | | function Commun.libelle( args ) |
− | local lib = args['libellé'] or '' | + | local lib = args['libellé'] |
− | if lib ~= '' then | + | if lib and lib ~= '' then |
− | lib = '<small>[' .. lib .. ']</small> ' | + | return '<small>[' .. lib .. ']</small> ' |
| + | else |
| + | return '' |
| end | | end |
− | return lib
| |
| end | | end |
| | | |
| -- voir Modèle:Commentaire biblio | | -- voir Modèle:Commentaire biblio |
| function Commun.commentaire( args ) | | function Commun.commentaire( args ) |
− | if Outils.trim( args.commentaire ) then | + | if args.commentaire and args.commentaire ~= '' then |
− | local a = '<div style="Margin-top:0.1em ;margin-left:2em; line-height:1.5; margin-bottom:0.5em;">' | + | local a = '<div style="margin-left:2em; line-height:1.5;">' |
| local b = '</div>' | | local b = '</div>' |
| return a, args.commentaire, b | | return a, args.commentaire, b |
Ligne 271 : |
Ligne 271 : |
| Langue = require( 'Module:Langue' ) | | Langue = require( 'Module:Langue' ) |
| | | |
− | -- on essaie le code de langue complet (nécessaire pour les langues avec plusieurs mot comme "grec ancien") | + | -- on essaie le code de langue complet (nécessaire pour les langues avec plusieurs mots comme "grec ancien") |
| local codeLangue = Langue.codeLangue2( lang ) | | local codeLangue = Langue.codeLangue2( lang ) |
| | | |
Ligne 336 : |
Ligne 336 : |
| | | |
| | | |
− | -- boucle sur chaque nom, assemble toutes les caractéristique et ajoute l'ensemble à la liste. | + | -- boucle sur chaque nom, assemble toutes les caractéristiques et ajoute l'ensemble à la liste. |
| while nom or auteur do | | while nom or auteur do |
| | | |
Ligne 406 : |
Ligne 406 : |
| local liste = { } | | 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 | + | -- fonction qui teste l'existence d'un paramètre et insère dans liste une abréviation discrète suivie de ce paramètre |
| local function insertAbr( arg, abrev, texte ) | | local function insertAbr( arg, abrev, texte ) |
| if arg then | | if arg then |
Ligne 422 : |
Ligne 422 : |
| if langueOriginale then | | if langueOriginale then |
| if trad then | | if trad then |
− | trad = ' par ' .. trad
| + | trad = ' par ' .. trad |
| else | | else |
| trad = '' | | trad = '' |
Ligne 440 : |
Ligne 440 : |
| table.insert( liste, 'postface ' .. args.postface ) | | table.insert( liste, 'postface ' .. args.postface ) |
| end | | end |
− | insertAbr( validArg( 'illustrateur' ), 'ill.', 'illustrations' ) | + | insertAbr( validArg( 'illustrateur', 'illustrations' ), 'ill.', 'illustrations' ) |
− | insertAbr( validArg( 'photographe' ), 'photogr.', 'photographies' ) | + | insertAbr( validArg( 'photographe', 'photographies' ), 'photogr.', 'photographies' ) |
| if validArg( 'champ libre' ) then | | if validArg( 'champ libre' ) then |
| table.insert( liste, args['champ libre'] ) | | table.insert( liste, args['champ libre'] ) |
Ligne 455 : |
Ligne 455 : |
| --- | | --- |
| -- voir émule le modèle:Inscription date | | -- 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. | + | -- la détection des arguments permet d'utiliser 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. | + | -- pour faciliter l'écriture de lua, annee (sans accent) est accepté lors de l'appel depuis lua. |
| function Commun.inscriptionDate( frame ) | | function Commun.inscriptionDate( frame ) |
| local args = Outils.extractArgs( frame ) | | local args = Outils.extractArgs( frame ) |
− | local annee = Outils.notEmpty( args['année'], args.annee, args.year ) | + | local annee = Commun.validTextArg( args, 'année', 'annee', 'year' ) |
| if annee then | | if annee then |
| if annee:match( '^%-?%d+$' ) then | | if annee:match( '^%-?%d+$' ) then |
− | -- si l'année est correctement renseigné, on essaye de trouver le mois | + | -- si l'année est correctement renseignée, on essaye de trouver le mois |
− | local mois = Outils.notEmpty( args.mois, args.month, args.saison ) | + | local mois = Commun.validTextArg( args, 'mois', 'month', 'saison' ) |
| mois = string.lower( mois or '' ) | | mois = string.lower( mois or '' ) |
− | local jour = Outils.notEmpty( args.jour, args.day, args['quantième'] ) | + | local jour = Commun.validTextArg( args, 'jour', 'day', 'quantième' ) |
− | local t, jma = Date.validationJourMoisAnnee( jour, mois, annee ) | + | local t, jma = Date.validationJourMoisAnnee{ jour, mois, annee } |
| if t then | | if t then |
| jma.nolinks = true | | jma.nolinks = true |
Ligne 474 : |
Ligne 474 : |
| table.insert( date, mois ) | | table.insert( date, mois ) |
| table.insert( date, annee ) | | table.insert( date, annee ) |
− | return '<time class="nowrap" datevalue="' .. annee .. '">' .. table.concat( date, ' ' ) .. '</time>' | + | return '<time class="nowrap" datetime="' .. annee .. '">' .. table.concat( date, ' ' ) .. '</time>' |
| end | | end |
| else | | else |
Ligne 480 : |
Ligne 480 : |
| end | | end |
| else | | else |
− | -- si annee n'est pas précisé, on utilise la paramètre date | + | -- si annee n'est pas précisé, on utilise le paramètre date |
− | local date = Outils.validTextArg( args, 'date' ) | + | local date = Commun.validTextArg( args, 'date' ) |
| if date then | | if date then |
| date = date:lower() | | date = date:lower() |
| -- Date iso avec l'heure : suppression de l'heure | | -- Date iso avec l'heure : suppression de l'heure |
− | date = date:gsub( '^(%d%d%d%d%-%d%d%-%d%d)t[%d:+-]+$', '%1') | + | date = date:gsub( '^(%d%d%d%d%-%d%d%-%d%d)t[%d:+-]+$', '%1' ) |
| local t, jma = Date.separationJourMoisAnnee( date ) | | local t, jma = Date.separationJourMoisAnnee( date ) |
− | if t and ( Date.determinationMois( jma.mois ) or Date.valideSaison( jma.mois ) ) then | + | if t then |
− | args['année'] = jma.annee
| |
| jma.nolinks = true | | jma.nolinks = true |
− | jma.nocat = true
| |
| return Date._modeleDate( jma ) | | return Date._modeleDate( jma ) |
| else | | else |
| -- date non reconnue, on essaye Month day, year | | -- date non reconnue, on essaye Month day, year |
| local mois, jour, annee = mw.ustring.match( date, '^([%a]+)%s*(%d%d?)[,%s]+(%d+)$' ) | | local mois, jour, annee = mw.ustring.match( date, '^([%a]+)%s*(%d%d?)[,%s]+(%d+)$' ) |
− | local t, jma = Date.validationJourMoisAnnee( jour, mois, annee ) | + | local t, jma = Date.validationJourMoisAnnee{ jour, mois, annee } |
| if annee and t then | | if annee and t then |
| jma.nolinks = true | | jma.nolinks = true |
Ligne 507 : |
Ligne 505 : |
| end | | end |
| | | |
− | -- retire toutes le lien interne, externe et balise html pour ne garder que le texte brut. | + | -- retire tous les liens internes, externes et balises html pour ne garder que le texte brut. |
| local function nettoyageTexte( texte ) | | local function nettoyageTexte( texte ) |
| if type( texte ) == 'string' then | | if type( texte ) == 'string' then |
Ligne 514 : |
Ligne 512 : |
| return ( t ~= '' and t ) or l | | return ( t ~= '' and t ) or l |
| end | | end |
− | -- nettoyage des liens interne | + | -- nettoyage des liens internes |
| texte = texte:gsub( '%[%[([^%[%]|]*)|?([^%[%]]*)%]%]', texteDuLien ) | | texte = texte:gsub( '%[%[([^%[%]|]*)|?([^%[%]]*)%]%]', texteDuLien ) |
| -- nettoyage des liens externes | | -- nettoyage des liens externes |
| :gsub( '%[https?://[^%[%] ]* *([^%]]+)%]', '%1' ) | | :gsub( '%[https?://[^%[%] ]* *([^%]]+)%]', '%1' ) |
| :gsub( '%[//[^%[%] ]* *([^%]]+)%]', '%1' ) | | :gsub( '%[//[^%[%] ]* *([^%]]+)%]', '%1' ) |
− | -- nettoyage des balise html | + | -- nettoyage des balises html |
| :gsub( '%b<>', '' ) | | :gsub( '%b<>', '' ) |
| end | | end |
Ligne 566 : |
Ligne 564 : |
| insertList( 'rft.place', texteLien( validArg( 'lieu', 'location' ) ), nil ) | | insertList( 'rft.place', texteLien( validArg( 'lieu', 'location' ) ), nil ) |
| insertList( 'rft.pub', texteLien( validArg( 'éditeur', 'édition' ) ), nil ) | | insertList( 'rft.pub', texteLien( validArg( 'éditeur', 'édition' ) ), nil ) |
− | insertList( 'rft.edition', args["numéro d'édition"] ) | + | insertList( 'rft.edition', texteLien( validArg( "numéro d'édition", "numéro édition" ) ), nil ) |
| end | | end |
| insertList( 'rft.stitle', args['sous-titre'] ) | | insertList( 'rft.stitle', args['sous-titre'] ) |
Ligne 640 : |
Ligne 638 : |
| local contextObject = table.concat( liste, '&' ) | | 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 )
| + | return '<span class="Z3988" title="' .. contextObject .. '"></span>' |
− | 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 | | end |
| | | |
| | | |
| return Commun | | return Commun |