Module:Biblio/Lien web
.mw-parser-output .documentation-modele{background-color:#ecfcf4}.mw-parser-output .documentation-module{background-color:#ecf0fc}.mw-parser-output .documentati…
Utilisation
Fonctions exportables :
lienWeb(args)– affiche un lien vers un site web ; voir {{Lien web}} ; il faut fournir une table de paramètres simplelienBrise(args)– affiche un lien brisé, auquel sont ajoutés des liens vers des sites d'archivage ; voir {{Lien brisé}} ; il faut fournir une table de paramètres simple
Modules externes et autres éléments dont ce module a besoin pour fonctionner :
Module:Biblio/CommunModule:Biblio/RéférencesModule:Langue– indirectement (chargé par Module:Biblio/Commun) si le paramètre langue est renseigné
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
-- luacheck: globals mw
local Lien = { }
local Commun = require( 'Module:Biblio/Commun' )
local References = require( 'Module:Biblio/Références' )
-- Si un concat est effectué pendant les traitements,
-- permet de réutiliser ensuite son résultat, au lieu de refaire un concat complet à la fin des traitements.
local function intermediateConcat( array )
local state = table.concat( array )
array[ 1 ] = state
for i = 2, #array do
array[ i ] = nil
end
return state
end
local function formatLien( args, dead )
-- La table wiki va recevoir tous les petits morceaux de texte, et sera concaténée à la fin.
local wiki = {}
-- permet d'écrire "insert( value )" au lieu de "wiki[#wiki+1] = value"
local function insert( value )
wiki[#wiki+1] = value
end
local modele = '[[Modèle:Lien web|{{Lien web}}]]'
if dead then
modele = '[[Modèle:Lien brisé|{{Lien brisé}}]]'
end
-- validArg renvoie le premier paramètre non vide, ou nil s'ils sont tous vides.
-- Seuls les noms des paramètres doivent être transmis à la fonction.
local function validArg( ... )
return Commun.validTextArg( args, ... )
end
-- Variables servant à la catégorisation
args.categ = {}
if validArg( 'dead-url', 'deadurl', 'brisé le', 'lien brisé' ) then
dead = true
end
-- Span initial, id
local spanInitial, spanFinal = Commun.spanInitial( args, validArg )
insert( spanInitial )
-- libellé
insert( Commun.libelle( args ) or nil )
-- indication de langue
local indicLangue, codeLangue = Commun.indicationDeLangue( args, validArg )
if indicLangue and indicLangue ~= '' then
insert( indicLangue .. ' ' )
end
-- Liste des auteurs et de leurs responsabilités (principales et secondaires)
local auteurs = Commun.responsabilitePrincipale( args, validArg )
if auteurs and auteurs ~= '' then
insert( auteurs )
local coauteur = validArg( 'co-auteur', 'coauteurs', 'coauteur', 'coauthors' )
if coauteur then
insert( ', ' .. coauteur )
end
insert( Commun.responsabiliteSecondaire( args, validArg ) or nil )
insert( ', ' )
end
local url = validArg( 'url', 'lire en ligne', 'url texte', 'lien' )
local archiveUrl = validArg( 'archive-url', 'archiveurl' )
local titre = validArg( 'titre', 'title' )
local description = validArg( 'description' )
-- url
if url then
-- remplacement des crochets et espaces par leur équivalent HTML
url = url:gsub( '%[', '%%5B' ):gsub( '%]', '%%5D' ):gsub( ' ', '%%20' )
-- ajout http:// si nécessaire :
if not ( url:match( '^https?://' ) or url:match( '^ftp://' ) or url:match( '^//' ) ) then
url = 'http://' .. url
end
if dead or archiveUrl then
insert( '<span class="noarchive">' )
end
end
-- titre
if titre then
-- suppression des retours ligne éventuels, sinon MediaWiki ne reconnaît pas le lien externe
-- et remplacement des crochets par leur équivalent HTML (uniquement le crochet de fermeture)
titre = titre:gsub( '\n', ' ' ):gsub( '%]', ']' )
-- on teste d'abord si titre contient déjà des guillemets
local lQuote = '« '
local rQuote = ' »'
if titre:match( '^«.+»$' ) then
lQuote = ''
rQuote = ''
end
-- par précaution, ne pas modifier la valeur de la variable locale "titre"
local sousTitre = validArg( 'sous-titre' )
if sousTitre then
sousTitre = ' : ' .. sousTitre
else
sousTitre = ''
end
local attributStyle = ' style="font-style:normal;"'
if dead and not archiveUrl then
attributStyle = ' style="font-style:normal; color:var(--color-link-red, #d73333);"'
end
local attributLang = ''
if codeLangue then
attributLang = ' lang="' .. codeLangue .. '"'
end
insert( lQuote )
if url then
insert( '[' .. url .. ' ' )
end
insert( '<cite' .. attributStyle .. attributLang .. '>' )
insert( titre .. sousTitre )
insert( '</cite>' )
if url then
insert( ']' )
end
insert( rQuote )
-- traduction titre
local traductionTitre = validArg( 'traduction titre' )
if traductionTitre and traductionTitre ~= args.titre then
insert( ' [« ' .. traductionTitre .. ' »]' )
end
if description then
insert( ', ' .. description )
end
elseif description then
if url then
insert( '[' .. url .. ' ' )
end
if dead and not archiveUrl then
insert( '<span style="color:var(--color-link-red, #d73333);">' )
insert( description )
insert( '</span>' )
else
insert( description )
end
if url then
insert( ']' )
end
else
args.categ.titre = true
if url then
insert( '[' .. url .. ']' )
end
end
-- liens archives pour les liens brisés
if url and dead and not archiveUrl then
insert( '<sup class="plainlinks">('
.. '[https://web.archive.org/web/*/' .. url .. ' Archive.org] • '
.. '[https://archive.wikiwix.com/cache/?url=' .. url .. ' Wikiwix] • '
.. '[https://webcache.googleusercontent.com/search?hl=fr&q=cache:' .. url .. ' Google] • '
.. '[[Projet:Correction des liens externes#J\'ai trouvé un lien mort, que faire ?|Que faire ?]]'
.. ')</sup>'
)
elseif archiveUrl then
if not ( archiveUrl:match( '^http' ) or archiveUrl:match( '^//' ) ) then
archiveUrl = 'http://' .. archiveUrl
end
local textArchive = 'archive'
local dateArchive = validArg( 'archive-date', 'archivedate' )
if dateArchive then
dateArchive = Commun.inscriptionDate{ date = dateArchive }
if dateArchive and dateArchive ~= '' then
textArchive = textArchive .. ' du ' .. dateArchive
end
end
insert( ' <small class="plainlinks cachelinks">[[' .. archiveUrl .. ' ' .. textArchive .. ']]</small>' )
end
if url and ( dead or archiveUrl ) then
insert( '</span>' )
end
-- affichage de l'icône du niveau d'accès à l'information
local paywall = validArg( 'accès url' )
if paywall then
local suffixeIcone = References.indicationIconeAcces( paywall )
if suffixeIcone and suffixeIcone ~= '' then
insert( suffixeIcone )
else
table.insert( wiki, 1, '<span class="error">Modèle '
.. modele .. ' : paramètre « <code>accès url</code> » utilisé avec la valeur <code>'
.. paywall .. '</code> inconnue. </span>'
)
end
end
-- format
local indicationDeFormat = References.indicationDeFormat( validArg( 'format électronique', 'format' ) )
if indicationDeFormat and indicationDeFormat ~= '' then
insert( indicationDeFormat )
end
-- Nature du document
local nature = validArg( 'nature document' )
if nature then
insert( ' (' .. nature .. ')' )
end
-- série, site, éditeur
local serie = validArg( 'série', 'work' )
if serie then
insert( ', <span class="italique">' .. serie .. '</span>' )
args.categ.work = validArg( 'work' ) -- il y a ambiguïté sur l'utilisation de ce paramètre
end
local site = validArg( 'site', 'website' )
if site then
insert( ', sur <span class="italique">' .. site .. '</span>' )
end
local periodique = validArg( 'périodique' )
if periodique then
insert( ', <i>' .. periodique .. '</i>' )
end
local lieu = validArg( 'lieu', 'lieu édition', 'location' )
if lieu then
insert( ', ' .. lieu )
end
local editeur = validArg( 'éditeur', 'publisher', 'editeur' )
if editeur then
local lienEditeur = validArg( 'lien éditeur' )
if lienEditeur then
insert( ', [[' .. lienEditeur .. '|' .. editeur .. ']]' )
else
insert( ', ' .. editeur )
end
end
-- date
if validArg( 'année', 'date', 'year', 'en ligne le', 'en ligne' ) then
args.categ.enLigneLe = validArg( 'date' ) and validArg( 'en ligne le' ) and args.date ~= args['en ligne le']
args.date = validArg( 'date', 'en ligne le', 'en ligne' )
local dateFormatee = Commun.inscriptionDate( args )
if dateFormatee and dateFormatee ~= '' then
local Langue = require( 'Module:Langue' )
local lrm = ''
if Langue.nonLatin( intermediateConcat( wiki ) ) then
lrm = '‎'
end
insert( ',' .. lrm .. ' ' .. dateFormatee )
end
end
-- liens externes (isbn, doi...) et "consulté le" entre parenthèses, et en plus petit, sauf en note
local liensExternes = References.affichageLiensExternes( args, validArg, false, true )
if liensExternes and liensExternes ~= '' then
insert( liensExternes )
elseif not url then
args.categ.url = true
end
-- fin du span
insert( spanFinal )
-- citation et passage
local citation = validArg( 'citation', 'extrait', 'quote' )
if citation then
if codeLangue then
local Langue = require( 'Module:Langue' )
citation = Langue.lang{ codeLangue, citation }
end
insert( '\194\160: <span class="citation">« ' .. citation .. ' »</span>' )
end
local passage = validArg( 'page', 'pages', 'passage' )
if passage then
insert( ', ' .. Commun.formatePassage( passage ) )
end
-- Plume "Ouvrage utilisé pour la rédaction de l'article"
if validArg( 'plume' ) then
local patternPonct = '[,.;:!?] ?»?$'
local ponctuation = intermediateConcat( wiki ):gsub( '%b<>', '' ):match( patternPonct )
if not ponctuation then
insert( '.' )
end
insert( Commun.plume )
end
-- message d'erreur
if args.categ.url or args.categ.titre then
local absent = { }
if args.categ.url then
table.insert( absent, '« <code>url</code> »' )
end
if args.categ.titre then
table.insert( absent, '« <code>titre</code> »' )
end
table.insert( wiki, 1, '<span class="error">Modèle '
.. modele .. ' : paramètre' .. ( #absent > 1 and 's ' or ' ' )
.. mw.text.listToText( absent ) .. ' manquant' .. ( #absent > 1 and 's' or '' )
.. '. </span>'
)
end
if mw.title.getCurrentTitle().namespace == 0 then
insert(
( args.categ.langue and '[[Catégorie:Page du modèle Lien web comportant une erreur|langue]]' or '' )
.. ( args.categ.url and '[[Catégorie:Page du modèle Lien web comportant une erreur|Url]]' or '' )
.. ( args.categ.titre and '[[Catégorie:Page du modèle Lien web comportant une erreur|titre]]' or '' )
.. ( args.categ.enLigneLe and '[[Catégorie:Page du modèle Lien web comportant une erreur|enLigneLe]]' or '' )
.. ( args.categ.isbnInvalid and '[[Catégorie:Page avec ISBN invalide]]' or '' )
.. ( args.categ.issnInvalid and '[[Catégorie:Page avec ISSN invalide]]' or '' )
)
end
if dead and not validArg( 'nocat' ) then
if mw.title.getCurrentTitle().namespace == 0 then
insert( '[[Catégorie:Article contenant un lien mort]]' )
else
insert( '[[Catégorie:Page contenant un lien mort]]' )
end
end
return table.concat( wiki )
end
function Lien.lienWeb( args )
return formatLien( args, false )
end
function Lien.lienBrise( args )
args.titre = Commun.validTextArg( args, 'titre', 'title', 'url', 'lire en ligne', 'url texte', 'lien' )
return formatLien( args, true )
end
return Lien
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.