Extension talk:LinkToArchive

About this board

Sphynkx (talkcontribs)

Exactly that I find..

Some modifications of LinkToArchive.php:

  • Link to archive replaced with favicons with links (for compactness)
  • Added possibility to add some another web-archive (openwayback based)
  • Added autocrawling of all external links on opened wikipage. Optional because wikipage may load slower
<?php

namespace LinkToArchive;

class LinkToArchive
{
    public static function onLinkerMakeExternalLink($url, $text, &$link, array &$attribs, $linktype)
    {
        $nocrawl=1;// 0 - crawl URLs (page will load slower); 1 - don't crawl URL
        if ($linktype) {
            $attribs['href'] = $url;
            $archiveAttribs = [
                'rel'  => $attribs['rel'],
                'href' => 'https://web.archive.org/web/'.$url,
            ];
            $emwaybackAttribs = [
                'rel'  => $attribs['rel'],
                'href' => 'https://someanotherwayback.tld/web/*/'.$url,
            ];

            if (isset($attribs['target'])) {
                $archiveAttribs['target'] = $attribs['target'];
            }
            $link = \Html::rawElement('a', $attribs, $text).
        ' <sup>'.
        \Html::rawElement('a', $emwaybackAttribs, '<img src="/extensions/LinkToArchive/someanotherwayback.ico" title="Link to EmWayBack" width="10px">').
        \Html::rawElement('a', $archiveAttribs, '<img src="/extensions/LinkToArchive/webarchive.ico" title="Link to WebArchive" width="10px">').
        (empty($nocrawl) ? \Html::rawElement('a', $archiveAttribs, '<img src="/extensions/LinkToArchive/webarchivesave.png" title="Save to WebArchive" width="10px"><iframe sandbox="" width=0 height=0 style="position: absolute; top: 0px; left: 0px;" src="https://web.archive.org/save/'.$url.'"></iframe>') :'' ).
        '</sup>';

            //We need to return false if we want to modify the HTML of external links
            return false;
        }
    }
}


Reply to "Thank You!!"
There are no older topics