« Module:Biblio/Lien web » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
test : afficher ''consulté en'' si le jour n'a pas été fourni
0x010D (discussion | contributions)
Aucun résumé des modifications
Ligne 121 : Ligne 121 :
end
end
if (string.match(consult, '^(%d%d? )')) then
if (string.match(consult, '^(%d%d? )')) then
consulteLe = 'consulté le'
consulteLe = 'consulté le '
else
else
consulteLe = 'consulté en'
consulteLe = 'consulté en '
end  
end  
precisions.minsert( consulteLe .. Outils.nobr( consult ) )
precisions.minsert( consulteLe .. Outils.nobr( consult ) )

Version du 2 février 2014 à 15:19

local Lien = { }

local Commun = require( 'Module:Biblio/Commun' ) local References = require( 'Module:Biblio/Références' ) local Outils = require( 'Module:Outils' ) local TableBuilder = require( 'Module:TableBuilder' )


function Lien.lienWeb( args ) -- La table wiki va recevoir tout les petits bouts de texte, et sera concaténtée à la fin. -- Elle utilise la metat-table de TableBuilder, permettant d'utiliser les fonctions de la -- librairy table comme des mèthodes. minsert permet d'insérer plusieurs élément en une -- seule fois en, ignorant les paramètre nil. local wiki = TableBuilder.new()

-- validArg renvoi le premier paramètre non vide, ou nil s'ils sont tous vides. -- Seul les noms des paramètres doivent être transmis à la fonction. local validArg = function ( ... ) return Outils.validTextArg( args, ... ) end

--Variables servant à la catégorisation local categUrl, categTitre, categLangue, categWork

-- Span initial, id wiki.minsert( Commun.spanInitial ( args, validArg ) )

-- indication de langue local indicLangue, codeLangue, categLangue = Commun.indicationDeLangue ( args, validArg ) if Outils.notEmpty( indicLangue ) then wiki.minsert( indicLangue, ' ' ) end

-- auteur et coauteurs local auteur = validArg( 'auteur', 'author', 'nom', 'nom1', 'last', 'auteurs', 'Auteur' ) if auteur then local lienAuteur = validArg( 'lien auteur' ) local prenom = validArg( 'prénom', 'prénom1', 'first' ) prenom = prenom and ( prenom .. ' ' ) if lienAuteur and string.sub( auteur, 1, 2 ) ~= '[[' then wiki.minsert( '', prenom, auteur, ', ' ) else wiki.minsert( prenom, auteur, ', ' ) end end local coauteur = validArg( 'coauteurs', 'coauteur', 'coauthors' ) if coauteur then wiki.minsert( coauteur, ', ' ) end

-- url local url = validArg( 'url', 'lire en ligne', 'url texte' ) if url then -- remplacement des crochets par leur équivalent html url = string.gsub ( string.gsub ( url, '%[', '%%5B' ), '%]', '%%5D' ) -- ajout http:// si nécessaire : if not ( string.match( url, '^http' ) or string.match( url, '^//' ) ) then url = 'http://' .. url end wiki.minsert( '[', url ) else categUrl = true wiki.minsert( Outils.erreur( 'modèle [[Modèle:Lien web|modèle {{Lien web}} : paramètre « url » manquantet paramètre « titre » manquant]] : paramètre « url » manquant' ) ) end

-- titre local titre = validArg( 'titre', 'title' ) if titre then -- suppression des retours ligne éventuel, sinon Mediawiki ne reconnais pas le lien externe titre = mw.ustring.gsub( titre, '\n', ' ' ) if auteur then wiki.minsert( ' « ', titre, ' »]' ) else wiki.minsert( ' ', titre, ']' ) end else categTitre = true if categUrl then wiki.minsert( Outils.erreur( ' et paramètre « titre » manquant' ) ) else wiki.minsert( ' ', args.url, '] ', Outils.erreur( 'modèle [[Modèle:Lien web|modèle {{Lien web}} : paramètre « url » manquantet paramètre « titre » manquant]] : paramètre « titre » manquant' ) ) end end

-- format wiki.minsert( References.indicationDeFormat( args.format ) )

-- série, site, éditeur local serie = validArg( 'série', 'work' ) if serie then wiki.minsert( , '', serie, '' ) categWork = validArg( 'work' ) -- il y a ambiguité sur l'utilisation de ce paramètre end local site = validArg( 'site', 'périodique', 'website' ) if site then wiki.minsert( , sur '', site, '' ) end local editeur = validArg( 'éditeur', 'publisher', 'editeur' ) if editeur then wiki.minsert( ', ', editeur ) end

-- date if validArg( 'année', 'date', 'year', 'en ligne le', 'en ligne' ) then args.date = validArg( 'date', 'en ligne le', 'en ligne' ) wiki.minsert( ',‎ ', Commun.inscriptionDate( args ) ) end


-- la partie suivante se trouve entre parenthèse, et plus petit (sauf en note) if validArg( 'consulté le', 'page', 'accessdate', 'Consulté le', 'consulté', 'isbn', 'ISBN', 'issn', 'consultée le' ) then local precisions = TableBuilder.new( )

-- isbn et issn precisions.minsert( References.isbn( args, validArg ), References.issn( args, validArg ) )

-- consulté le local consult = validArg( 'consulté le', 'accessdate', 'Consulté le', 'consulté', 'consultée le' ) local consuteLe = if consult then if string.sub( consult, -1,-1) == '.' then consult = string.sub( consult, 1, -2) end if (string.match(consult, '^(%d%d? )')) then consulteLe = 'consulté le ' else consulteLe = 'consulté en ' end precisions.minsert( consulteLe .. Outils.nobr( consult ) ) end

wiki.minsert( ' ', mw.text.nowiki( '(' ), precisions.concat( ', ' ), ')' ) end

-- fin du span wiki.minsert( '' )

-- citation local citation = validArg( 'citation', 'extrait', 'quote' ) if citation then wiki.minsert( ' : « ', citation, ' »' ) end local page = validArg( 'page', 'pages', 'passage' ) if page then wiki.minsert( ', ', Commun.page, page ) end

if mw.title.getCurrentTitle().namespace == 0 then wiki.minsert( categLangue and , categUrl and , categTitre and ) end

return wiki.concat() end


return Lien