« MediaWiki:Gadget-ArchiveLinks.js » : différence entre les versions

Contenu supprimé Contenu ajouté
Gadget destiné à remplacer la fonction affichant des liens [archive] pour les références dans Common.js. Création à la demande d'Od1n, par copie de Utilisateur:Od1n/MediaWiki:Gadget-ArchiveLinks.js.
(Aucune différence)

Version du 28 juillet 2015 à 22:39

/**
 * 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}}
 */
function archiveLinks(element) {

    element = element || document;
    $(element).find('ol.references a.external').each(function () {

        var $this = $(this);
        var chemin = this.href;

        if (/(^|\.)wiki[pm]edia\.org$/.test(this.hostname)
        || 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 ($this.parents().hasClass('noarchive')) {
            return;
        }

        // sécurité : les attributs ne doivent pas contenir de quotes

        var href = 'http://archive.wikiwix.com/cache/?url=' + encodeURIComponent(chemin);
        var title = 'archive de ' + $this.text().replace(/"/g, '&quot;');

        var link = '<a href="' + href + '" title="' + title + '">archive</a>';

        $this.after('<small class="cachelinks">\u00a0[' + link + ']</small>');
    });
}

if (mw.config.get('wgNamespaceNumber') === 0 && !mw.user.options.get('gadget-ExtendedArchiveLinks')) {
    $(function ($) {
        archiveLinks();
    });
}