Module:Biblio/Lien vidéo
Apparence
[voir] [modifier] [historique] [purger]
Utilisation
Fonctions exportables :
lienVideo(args)
– affiche un lien vers une vidéo ; voir {{Lien vidéo}}
Modules externes et autres éléments dont ce module a besoin pour fonctionner :
Module:Biblio/Commun
Module:Biblio/Références
Module:Unité
Module: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 (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local Lien = { }
local Commun = require( 'Module:Biblio/Commun' )
local References = require( 'Module:Biblio/Références' )
local Unite = require( 'Module:Unité' )
-- 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 = {}
local modele = '[[Modèle:Lien vidéo|{{Lien vidéo}}]]'
-- 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 )
table.insert(wiki, spanInitial )
-- libellé
table.insert(wiki, Commun.libelle( args ) or nil )
-- indication de langue
local indicLangue, codeLangue = Commun.indicationDeLangue( args, validArg )
if indicLangue and indicLangue ~= '' then
table.insert(wiki, indicLangue .. ' ' )
end
-- format, vidéo par défaut
local medium = validArg( 'medium' )
if validArg( 'format' ) then
table.insert(wiki, References.indicationDeFormat( args.format ) )
else
table.insert(wiki, References.indicationDeFormat( 'video' ) )
end
-- medium
if medium and not mw.ustring.find(medium, "[Vv]id[eé]o") then -- medium est fourni par Citoid et contient souvent "vidéo"
table.insert(wiki, '<span class="indicateur-format">'.. mw.text.nowiki( '[' .. args.medium .. ']' ) .. '</span>')
end
table.insert(wiki, ' ' )
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
table.insert(wiki, '<span class="noarchive">' )
end
end
-- titre
if titre then
-- suppression des retours ligne éventuels, sinon MediaWiki ne reconnaît pas le lien externe
titre = titre:gsub( '\n', ' ' )
-- 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
table.insert(wiki, lQuote )
if url then
table.insert(wiki, '[' .. url .. ' ' )
end
table.insert(wiki, '<cite' .. attributStyle .. attributLang .. '>' )
table.insert(wiki, titre .. sousTitre )
table.insert(wiki, '</cite>' )
if url then
table.insert(wiki, ']' )
end
table.insert(wiki, rQuote )
-- traduction titre
local traductionTitre = validArg( 'traduction titre' )
if traductionTitre and traductionTitre ~= args.titre then
table.insert(wiki, ' [« ' .. traductionTitre .. ' »]' )
end
if description then
table.insert(wiki, ', ' .. description )
end
elseif description then
if url then
table.insert(wiki, '[' .. url .. ' ' )
end
if dead and not archiveUrl then
table.insert(wiki, '<span style="color:var(--color-link-red, #d73333);">' )
table.insert(wiki, description )
table.insert(wiki, '</span>' )
else
table.insert(wiki, description )
end
if url then
table.insert(wiki, ']' )
end
else
args.categ.titre = true
if url then
table.insert(wiki, '[' .. url .. ']' )
end
end
-- liens archives pour les liens brisés
if url and dead and not archiveUrl then
table.insert(wiki, '<sup class="plainlinks">('
.. '[https://web.archive.org/web/*/' .. url .. ' Archive.org] • '
.. '[https://archive.wikiwix.com/cache/?url=' .. url .. ' Wikiwix] • '
.. '[https://archive.is/' .. url .. ' Archive.is] • '
.. '[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
table.insert(wiki, ' <small class="plainlinks cachelinks">[[' .. archiveUrl .. ' ' .. textArchive .. ']]</small>' )
end
if url and ( dead or archiveUrl ) then
table.insert(wiki, '</span>' )
end
-- message d'erreur
if args.categ.titre then
table.insert( wiki, 1, '<span class="error">Modèle ' .. modele .. ' : paramètre« <code>titre</code> » manquant. </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
table.insert(wiki, 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
-- indication de temps
local temps = validArg( 'temps', 'time' )
if temps then
table.insert(wiki, ', à ' .. temps )
end
-- citation
local citation = validArg( 'citation', 'extrait', 'quote' )
if citation then
if codeLangue then
local Langue = require( 'Module:Langue' )
citation = Langue.lang{ codeLangue, citation }
end
table.insert( wiki, '\194\160: <span class="citation">« ' .. citation .. ' »</span>' )
end
-- Liste des auteurs et de leurs responsabilités (principales et secondaires)
local auteur = validArg( 'people', 'nom1', 'nom', 'auteur1', 'auteur', 'auteurs', 'auteur institutionnel', 'last1', 'last', 'author1', 'author' )
if auteur then
if validArg( 'auteurs' ) then
table.insert(wiki, args.auteurs )
else
table.insert(wiki, Commun.responsabilitePrincipale( args, validArg ) or nil )
end
local coauteur = validArg( 'co-auteur', 'coauteurs', 'coauteur', 'coauthors' )
if coauteur then
table.insert(wiki, ', ' .. coauteur )
end
table.insert(wiki, Commun.responsabiliteSecondaire( args, validArg ) or nil )
end
-- émission et chaîne
local emission = validArg( 'périodique' )
if emission then
table.insert(wiki, ', dans <i>' .. emission .. '</i>' )
end
local chaine = validArg( 'chaine', 'chaîne')
if chaine then
table.insert(wiki, ' sur ' .. chaine)
end
-- date et durée
local date = validArg( 'année', 'date', 'year', 'en ligne le', 'en ligne' )
local duree = validArg( 'durée' )
local duree_table = Unite.parseUnit( duree )
duree = ""
for i = 1, #duree_table, 2 do -- Unite._unite ne gère pas directement 2 h 57 min, il faut faire Unite._unite{ '2h' } puis Unite._unite{ '57min' }.
if i > 1 then
duree = duree.. " "
end
if duree_table[i + 1] ~= nil then
duree = duree .. Unite._unite{duree_table[i], duree_table[i + 1]}
else
duree = duree .. Unite._unite{duree_table[i], 'min'} --durée en minutes par défaut
end
end
if date 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
table.insert(wiki, ',' .. lrm .. ' ' .. dateFormatee )
end
if duree ~= "" then
table.insert(wiki, ', ' .. duree )
end
elseif duree ~= "" then
table.insert(wiki, ' (' .. duree .. ') ' )
end
-- site, éditeur
local site = validArg( 'site', 'website' )
if site then
table.insert(wiki, ', sur <span class="italique">' .. site .. '</span>' )
end
local lieu = validArg( 'lieu', 'lieu édition', 'location' )
if lieu then
table.insert(wiki, ', ' .. lieu )
end
local editeur = validArg( 'éditeur', 'publisher', 'editeur' )
if editeur then
local lienEditeur = validArg( 'lien éditeur' )
if lienEditeur then
table.insert(wiki, ', [[' .. lienEditeur .. '|' .. editeur .. ']]' )
else
table.insert(wiki, ', ' .. editeur )
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
table.insert(wiki, liensExternes )
end
-- fin du span
table.insert(wiki, spanFinal )
-- 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
table.insert(wiki, '.' )
end
table.insert(wiki, Commun.plume )
end
if mw.title.getCurrentTitle().namespace == 0 then
table.insert(wiki,
( args.categ.langue and '[[Catégorie:Page avec modèle Lien vidéo comportant une erreur|langue]]' or '' )
.. ( args.categ.titre and '[[Catégorie:Page avec modèle Lien vidéo comportant une erreur|titre]]' or '' )
.. ( args.categ.enLigneLe and '[[Catégorie:Page avec modèle Lien vidéo 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
table.insert(wiki, '[[Catégorie:Article contenant un lien mort]]' )
else
table.insert(wiki, '[[Catégorie:Page contenant un lien mort]]' )
end
end
return table.concat( wiki )
end
function Lien.lienVideo( args )
return formatLien( args, false )
end
return Lien