Example #1
0
/**
 * Hooks registered on ParserAfterTidy hook
 *
 * Injects links to feeds in HTML <head>
 *
 */
function wfWikiFeeds_Linker($a, $b)
{
    global $wgWikiFeedsSettings, $wgTitle;
    // only link against each article once
    if (!array_key_exists('__linkerTracker', $wgWikiFeedsSettings)) {
        $wgWikiFeedsSettings['__linkerTracker'] = array();
    }
    /** Wikia change start, author Federico "Lox" Lucignano **/
    if (!$wgTitle instanceof Title) {
        //$wgTitle is not set, skip processing
        return true;
    }
    /** Wikia change end **/
    // if we have already processed this title, don't do it again
    if (in_array($wgTitle->getFullText(), $wgWikiFeedsSettings['__linkerTracker'])) {
        return true;
    } else {
        // mark as processed
        $wgWikiFeedsSettings['__linkerTracker'][] = $wgTitle->getFullText();
    }
    switch ($wgTitle->getNamespace()) {
        case NS_USER:
        case NS_USER_TALK:
            $username = $wgTitle->getPartialURL();
            //strip out subpage if we are on one
            if ($pos = strpos($username, '/')) {
                $username = substr($username, 0, $pos);
            }
            $t0 = Title::newFromText("WikiFeeds/atom/recentuserchanges/user/{$username}", NS_SPECIAL);
            $t1 = Title::newFromText("WikiFeeds/rss/recentuserchanges/user/{$username}", NS_SPECIAL);
            $t2 = Title::newFromText("WikiFeeds/atom/newestuserarticles/user/{$username}", NS_SPECIAL);
            $t3 = Title::newFromText("WikiFeeds/rss/newestuserarticles/user/{$username}", NS_SPECIAL);
            $t4 = Title::newFromText("WikiFeeds/atom/watchlist/user/{$username}", NS_SPECIAL);
            $t5 = Title::newFromText("WikiFeeds/rss/watchlist/user/{$username}", NS_SPECIAL);
            /* Wikia change begin - @author: macbre */
            /* $username can contain illegal characters detected by Title::secureAndSplit() - BugId:8126 */
            if (!empty($t0)) {
                wfWikiFeeds_AddLink('atom', "Recently changed articles by {$username} (ATOM 1.0)", $t0->getFullUrl());
                wfWikiFeeds_AddLink('atom', "Latest articles created by {$username} (ATOM 1.0)", $t2->getFullUrl());
                wfWikiFeeds_AddLink('atom', "Watchlist for {$username} (ATOM 1.0)", $t4->getFullUrl());
                wfWikiFeeds_AddLink('rss', "Recently changes articles by {$username} (RSS 2.0)", $t1->getFullUrl());
                wfWikiFeeds_AddLink('rss', "Latest articles created by {$username} (RSS 2.0)", $t3->getFullUrl());
                wfWikiFeeds_AddLink('rss', "Watchlist for {$username} (RSS 2.0)", $t5->getFullUrl());
            }
            /* Wikia change end */
            break;
        case NS_CATEGORY:
        case NS_CATEGORY_TALK:
            $category = $wgTitle->getPartialURL();
            $catName = $wgTitle->getText();
            $atomCatNew = Title::newFromText("WikiFeeds/atom/newestcategoryarticles/category/{$catName}", NS_SPECIAL);
            $rssCatNew = Title::newFromText("WikiFeeds/rss/newestcategoryarticles/category/{$catName}", NS_SPECIAL);
            $atomCatRecent = Title::newFromText("WikiFeeds/atom/recentcategorychanges/category/{$catName}", NS_SPECIAL);
            $rssCatRecent = Title::newFromText("WikiFeeds/rss/recentcategorychanges/category/{$catName}", NS_SPECIAL);
            /* Wikia change begin - @author: macbre */
            /* $username can contain illegal characters detected by Title::secureAndSplit() - BugId:8126 */
            if (!empty($atomCatNew)) {
                wfWikiFeeds_AddLink('atom', "Newest pages to join the {$catName} category (ATOM 1.0)", $atomCatNew->getFullUrl());
                wfWikiFeeds_AddLink('atom', "Recently changed articles in the {$catName} category (ATOM 1.0)", $atomCatRecent->getFullUrl());
                wfWikiFeeds_AddLink('rss', "Newest pages to join the {$catName} category (RSS 2.0)", $rssCatNew->getFullUrl());
                wfWikiFeeds_AddLink('rss', "Recently changed articles in the {$catName} category (RSS 2.0)", $rssCatRecent->getFullUrl());
            }
            /* Wikia change end */
    }
    $atomRecentChanges = Title::newFromText("WikiFeeds/atom/recentarticlechanges", NS_SPECIAL);
    $atomNewestArticles = Title::newFromText("WikiFeeds/atom/newestarticles", NS_SPECIAL);
    $rssRecentChanges = Title::newFromText("WikiFeeds/rss/recentarticlechanges", NS_SPECIAL);
    $rssNewestArticles = Title::newFromText("WikiFeeds/rss/newestarticles", NS_SPECIAL);
    wfWikiFeeds_AddLink('atom', 'Recently changed articles (ATOM 1.0)', $atomRecentChanges->getFullUrl());
    wfWikiFeeds_AddLink('atom', 'Newest articles (ATOM 1.0)', $atomNewestArticles->getFullUrl());
    wfWikiFeeds_AddLink('rss', 'Recently changed articles (RSS 2.0)', $rssRecentChanges->getFullUrl());
    wfWikiFeeds_AddLink('rss', 'Newest articles (RSS 2.0)', $rssNewestArticles->getFullUrl());
    return true;
}
Example #2
0
/**
 * Hooks registered on ParserAfterTidy hook
 * 
 * Injects links to feeds in HTML <head>
 * 
 */
function wfWikiFeeds_Linker($a, $b)
{
    global $wgWikiFeedsSettings, $wgTitle;
    // only link against each article once
    if (!array_key_exists('__linkerTracker', $wgWikiFeedsSettings)) {
        $wgWikiFeedsSettings['__linkerTracker'] = array();
    }
    // if we have already processed this title, don't do it again
    if (in_array($wgTitle->getFullText(), $wgWikiFeedsSettings['__linkerTracker'])) {
        return true;
    } else {
        // mark as processed
        $wgWikiFeedsSettings['__linkerTracker'][] = $wgTitle->getFullText();
    }
    switch ($wgTitle->getNamespace()) {
        case NS_USER:
        case NS_USER_TALK:
            $username = $wgTitle->getPartialURL();
            //strip out subpage if we are on one
            if ($pos = strpos($username, '/')) {
                $username = substr($username, 0, $pos);
            }
            $t0 = Title::newFromText("WikiFeeds/atom/recentuserchanges/user/{$username}", NS_SPECIAL);
            $t1 = Title::newFromText("WikiFeeds/rss/recentuserchanges/user/{$username}", NS_SPECIAL);
            $t2 = Title::newFromText("WikiFeeds/atom/newestuserarticles/user/{$username}", NS_SPECIAL);
            $t3 = Title::newFromText("WikiFeeds/rss/newestuserarticles/user/{$username}", NS_SPECIAL);
            $t4 = Title::newFromText("WikiFeeds/atom/watchlist/user/{$username}", NS_SPECIAL);
            $t5 = Title::newFromText("WikiFeeds/rss/watchlist/user/{$username}", NS_SPECIAL);
            wfWikiFeeds_AddLink('atom', "Recently changed articles by {$username} (ATOM 1.0)", $t0->getFullUrl());
            wfWikiFeeds_AddLink('atom', "Latest articles created by {$username} (ATOM 1.0)", $t2->getFullUrl());
            wfWikiFeeds_AddLink('atom', "Watchlist for {$username} (ATOM 1.0)", $t4->getFullUrl());
            wfWikiFeeds_AddLink('rss', "Recently changes articles by {$username} (RSS 2.0)", $t1->getFullUrl());
            wfWikiFeeds_AddLink('rss', "Latest articles created by {$username} (RSS 2.0)", $t3->getFullUrl());
            wfWikiFeeds_AddLink('rss', "Watchlist for {$username} (RSS 2.0)", $t5->getFullUrl());
            break;
        case NS_CATEGORY:
        case NS_CATEGORY_TALK:
            $category = $wgTitle->getPartialURL();
            $catName = $wgTitle->getText();
            $atomCatNew = Title::newFromText("WikiFeeds/atom/newestcategoryarticles/category/{$catName}", NS_SPECIAL);
            $rssCatNew = Title::newFromText("WikiFeeds/rss/newestcategoryarticles/category/{$catName}", NS_SPECIAL);
            $atomCatRecent = Title::newFromText("WikiFeeds/atom/recentcategorychanges/category/{$catName}", NS_SPECIAL);
            $rssCatRecent = Title::newFromText("WikiFeeds/rss/recentcategorychanges/category/{$catName}", NS_SPECIAL);
            wfWikiFeeds_AddLink('atom', "Newest pages to join the {$catName} category (ATOM 1.0)", $atomCatNew->getFullUrl());
            wfWikiFeeds_AddLink('atom', "Recently changed articles in the {$catName} category (ATOM 1.0)", $atomCatRecent->getFullUrl());
            wfWikiFeeds_AddLink('rss', "Newest pages to join the {$catName} category (RSS 2.0)", $rssCatNew->getFullUrl());
            wfWikiFeeds_AddLink('rss', "Recently changed articles in the {$catName} category (RSS 2.0)", $rssCatRecent->getFullUrl());
    }
    $atomRecentChanges = Title::newFromText("WikiFeeds/atom/recentarticlechanges", NS_SPECIAL);
    $atomNewestArticles = Title::newFromText("WikiFeeds/atom/newestarticles", NS_SPECIAL);
    $rssRecentChanges = Title::newFromText("WikiFeeds/rss/recentarticlechanges", NS_SPECIAL);
    $rssNewestArticles = Title::newFromText("WikiFeeds/rss/newestarticles", NS_SPECIAL);
    wfWikiFeeds_AddLink('atom', 'Recently changed articles (ATOM 1.0)', $atomRecentChanges->getFullUrl());
    wfWikiFeeds_AddLink('atom', 'Newest articles (ATOM 1.0)', $atomNewestArticles->getFullUrl());
    wfWikiFeeds_AddLink('rss', 'Recently changed articles (RSS 2.0)', $rssRecentChanges->getFullUrl());
    wfWikiFeeds_AddLink('rss', 'Newest articles (RSS 2.0)', $rssNewestArticles->getFullUrl());
    return true;
}