« MediaWiki:Gadget-ArchiveLinks.js » : différence entre les versions
Contenu supprimé Contenu ajouté
ciblage plus précis/restreint, pour éviter un faux positif avec un lien vers mediawiki.org dans la zone de diff ; refs discussion utilisateur, discussion bistro, et surtout exemple (regarder les balises dans la zone de diff) |
Wikiwix est maintenant en https, économie de la redirection http vers https ; cf. WP:DIMS |
||
Ligne 39 : | Ligne 39 : | ||
// sécurité : attention à échapper les quotes dans les attributs |
// sécurité : attention à échapper les quotes dans les attributs |
||
var href = ' |
var href = 'https://archive.wikiwix.com/cache/?url=' + encodeURIComponent( chemin ); |
||
var title = 'archive sur Wikiwix'; |
var title = 'archive sur Wikiwix'; |
||
Version du 8 novembre 2021 à 03:01
/**
* Application de [[Wikipédia:Prise de décision/Système de cache]].
* Un <span class="noarchive"> autour d'un lien l'empêche d'être pris en compte.
*
* {{Catégorisation JS|ArchiveLinks}}
*/
if ( !window.no_external_cache && ( mw.config.get( 'wgNamespaceNumber' ) === 0 || mw.user.options.get( 'gadget-ExtendedCache' ) ) ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
var hasNativeClosest = !!Element.prototype.closest;
$content.find( '.mw-parser-output' ).find( '.external' ).each( function ( _, link ) {
if ( link.tagName !== 'A' ) {
return;
}
var chemin = link.href;
if ( /(^|\.)wiki([pm]edia|data)\.org$/.test( link.hostname )
|| chemin.indexOf( 'http://tools.wmflabs.org/' ) === 0
|| chemin.indexOf( 'http://archive.wikiwix.com/cache/' ) === 0
|| chemin.indexOf( 'http://wikiwix.com/cache/' ) === 0
|| chemin.indexOf( 'http://web.archive.org/web/' ) === 0
) {
return;
}
if ( hasNativeClosest ) {
if ( link.closest( '.noarchive, .infobox_v3' ) ) {
return;
}
} else {
if ( $( link ).closest( '.noarchive, .infobox_v3' ).length ) {
return;
}
}
// sécurité : attention à échapper les quotes dans les attributs
var href = 'https://archive.wikiwix.com/cache/?url=' + encodeURIComponent( chemin );
var title = 'archive sur Wikiwix';
var archiveLink = '<a href="' + href + '" title="' + title + '">archive</a>';
link.insertAdjacentHTML( 'afterend', '<small class="cachelinks">\u00a0[' + archiveLink + ']</small>' );
});
});
}