Example #1
0
function WidgetAncientPages($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgTitle, $wgLang, $wgOut;
    // load class if it's not loaded yet...
    if (!class_exists('AncientPagesPage')) {
        require_once $IP . 'includes/SpecialAncientpages.php';
    }
    if (!is_object($wgTitle)) {
        $wgTitle = Title::newMainPage();
    }
    $offset = 0;
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 10 : $limit;
    $pages = array();
    // query the special page object
    $showSpecial = false;
    $app = new WidgetAncientPagesPage($showSpecial);
    $app->setListoutput(TRUE);
    $app->doQuery($offset, $limit, $showSpecial);
    $items = array();
    $aRows = $app->getResult();
    if (!empty($aRows) && is_array($aRows)) {
        foreach ($aRows as $sTitle => $sTimestamp) {
            $date = $wgLang->sprintfDate('j M Y', date('YmdHis', $sTimestamp));
            $oTitle = Title::newFromText($sTitle, NS_MAIN);
            if ($oTitle instanceof Title) {
                $items[] = array('name' => $oTitle->getText(), 'href' => $oTitle->getLocalURL(), 'title' => wfMsg('lastmodifiedat', date('H:i', $sTimestamp), $date));
            }
        }
    }
    wfProfileOut(__METHOD__);
    return WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink(Title::newFromText('Ancientpages', NS_SPECIAL)->getLocalURL());
}
 /**
  * @static
  * @return WidgetFramework
  */
 public static function getInstance()
 {
     if (self::$instance == false) {
         self::$instance = new WidgetFramework();
     }
     return self::$instance;
 }
Example #3
0
function WidgetContribs($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgUser;
    // limit amount of messages
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 10 : $limit;
    // get last edits from API
    $results = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'usercontribs', 'ucuser' => $wgUser->getName(), 'uclimit' => $limit));
    $ret = '';
    if (!empty($results['query']['usercontribs'])) {
        $list = array();
        foreach ($results['query']['usercontribs'] as $contrib) {
            $title = Title::newFromText($contrib['title'], $contrib['ns']);
            if (empty($title)) {
                //bad title returned, cant use it, dont display it
                //note: how did the api return an unusable/bad pagename?
                continue;
            }
            $list[] = array('href' => $title->getLocalURL(), 'name' => $contrib['title']);
        }
        $ret = WidgetFramework::wrapLinks($list);
        // 'more' link...
        $more = Title::newFromText('Contributions/' . $wgUser->getName(), NS_SPECIAL)->getLocalURL();
        $ret .= WidgetFramework::moreLink($more);
    } else {
        $ret = wfMsg('widget-contribs-empty');
    }
    wfProfileOut(__METHOD__);
    return $ret;
}
function WidgetRecentChanges($id, $params)
{
    wfProfileIn(__METHOD__);
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    $api_params = array('action' => 'query', 'list' => 'recentchanges', 'rctype' => 'edit|new', 'rclimit' => $limit);
    if (!empty($params['hidebots'])) {
        $api_params['rcshow'] = '!bot';
    }
    $res = WidgetFramework::callAPI($api_params);
    $ret = '<ul>';
    if (!empty($res) && is_array($res['query']['recentchanges'])) {
        foreach ($res['query']['recentchanges'] as $change) {
            if ($change['pageid'] > 0) {
                $title = Title::newFromText($change['title'], $change['ns']);
                if (is_object($title)) {
                    $display = htmlspecialchars($change['title']);
                    $ret .= '<li><a href="' . $title->getLocalURL() . '" title="' . $display . '">' . $display . '</a>' . '<a class="WidgetRecentChangesDiffLink" href="' . htmlspecialchars($title->getLocalURL('diff=' . $change['revid'])) . '">diff</a></li>';
                }
            }
        }
    }
    $ret .= '</ul>';
    wfProfileOut(__METHOD__);
    return $ret;
}
function WidgetActiveTalkPages($id, $params)
{
    global $wgLang;
    wfProfileIn(__METHOD__);
    // get last edits from API
    $results = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'recentchanges', 'rcnamespace' => NS_TALK, 'rcprop' => 'title|timestamp|ids|user|loginfo', 'rclimit' => 150));
    $list = array();
    if (!empty($results['query']['recentchanges'])) {
        // prevent showing the same page more then once
        foreach ($results['query']['recentchanges'] as $edit) {
            if (isset($edit['logtype']) && $edit['logtype'] == 'delete') {
                continue;
            }
            $timestamp = strtotime($edit['timestamp']);
            $date = $wgLang->sprintfDate('j M Y (H:i)', date('YmdHis', $timestamp));
            $title = Title::newFromText($edit['title'], $edit['ns']);
            if ($title !== null && !isset($list[$edit['title']])) {
                $list[$edit['title']] = array('href' => $title->getLocalURL('diff=' . $edit['revid']), 'title' => $date . ' (rev #' . $edit['revid'] . ')', 'name' => $title->getText());
            }
        }
    }
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    // limit results list
    $list = array_slice($list, 0, $limit);
    // 'more' link...
    $more = Title::newFromText('Recentchanges', NS_SPECIAL)->getLocalURL('namespace=1');
    return WidgetFramework::wrapLinks($list) . WidgetFramework::moreLink($more);
}
Example #6
0
function WidgetNewPages($id, $params)
{
    wfProfileIn(__METHOD__);
    $items = array();
    if (class_exists('DataProvider')) {
        $items = DataProvider::singleton()->GetNewlyCreatedArticles();
    }
    wfProfileOut(__METHOD__);
    return count($items) > 0 ? WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink(Title::newFromText('Newpages', NS_SPECIAL)->getLocalURL()) : wfMsg('widget-empty-list');
}
Example #7
0
function WidgetLanguages($id, $params)
{
    wfProfileIn(__METHOD__);
    $skin = RequestContext::getMain()->getSkin();
    $list = array();
    // only display the widget if there are interlanguage links
    if (!empty($skin->language_urls) && is_array($skin->language_urls)) {
        foreach ($skin->language_urls as $val) {
            $list[] = array('href' => $val['href'], 'name' => $val['text']);
        }
    }
    wfProfileOut(__METHOD__);
    return WidgetFramework::wrapLinks($list);
}
Example #8
0
function WidgetTopUsers($id, $params)
{
    wfProfileIn(__METHOD__);
    $links = array();
    if (class_exists('DataProvider')) {
        $articles =& DataProvider::singleton()->GetTopFiveUsers();
        if (is_array($articles) && count($articles) > 0) {
            foreach ($articles as $article) {
                $links[] = array('href' => $article['url'], 'name' => $article['text']);
            }
        }
    }
    wfProfileOut(__METHOD__);
    return WidgetFramework::wrapLinks($links);
}
Example #9
0
function WidgetTopVoted($id, $params)
{
    wfProfileIn(__METHOD__);
    $items = array();
    if (class_exists('DataProvider')) {
        $articles =& DataProvider::singleton()->GetTopVotedArticles();
        if (is_array($articles) && count($articles) > 0) {
            foreach ($articles as $article) {
                $items[] = array('href' => $article['url'], 'name' => $article['text']);
            }
        }
    }
    //print_pre($items);
    wfProfileOut(__METHOD__);
    return count($items) > 0 ? WidgetFramework::wrapLinks($items) : wfMsg('widget-empty-list');
}
Example #10
0
function WidgetMostVisited($id, $params)
{
    wfProfileIn(__METHOD__);
    $items = array();
    if (class_exists('DataProvider')) {
        $articles =& DataProvider::singleton()->GetMostVisitedArticles();
        if (is_array($articles) && count($articles) > 0) {
            foreach ($articles as $article) {
                $items[] = array('href' => $article['url'], 'name' => $article['text']);
            }
        }
    }
    //print_pre($items);
    wfProfileOut(__METHOD__);
    return count($items) > 0 ? WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink(Title::newFromText('Top', NS_SPECIAL)->getLocalURL() . '/most_visited') : wfMsg('widget-empty-list');
}
Example #11
0
function WidgetWikiPage($id, $params)
{
    global $wgTitle, $wgParser;
    wfProfileIn(__METHOD__);
    if (!is_object($wgTitle)) {
        $wgTitle = new Title();
    }
    // clean up inputs
    $params['source'] = trim($params['source']);
    $params['name'] = trim($params['name']);
    //stopgap for 67038
    $source = Title::newFromText($params['source']);
    if (is_object($source) && !$source->userCan('read')) {
        wfProfileOut(__METHOD__);
        return array('body' => '', 'title' => $params['name']);
    }
    //
    // parse message and clean it up
    //
    // fixes #2774
    if (isset($params['_widgetTag'])) {
        // work-around for WidgetTag
        $parser = new Parser();
    } else {
        $parser =& $wgParser;
    }
    $options = new ParserOptions();
    $options->setMaxIncludeSize(2048);
    if (empty($params['source'])) {
        // blank source pagename, use default message
        $ret = $parser->parse(wfMsg('widgetwikipage', $params['source']), $wgTitle, $options)->getText();
    } else {
        // has a source value
        // get contents
        $article = WidgetFramework::getArticle($params['source']);
        if ($article == false) {
            // failed to get text, show error message, failed pagename is in $1
            $ret = $parser->parse('<span class="widget-error-wikipage-missing">' . wfMsg('widgetwikipagemissing', $params['source']) . '</span>', $wgTitle, $options)->getText();
            // TODO: change title if page missing?
        } else {
            // got text, parse it!
            $ret = $parser->parse($article, $wgTitle, $options)->getText();
        }
    }
    wfProfileOut(__METHOD__);
    return array('body' => $ret, 'title' => $params['name']);
}
function WidgetProblemReports($id, $params)
{
    // check whether ProblemReports extension is enabled on this wiki
    global $wgProblemReportsEnable;
    if (!isset($wgProblemReportsEnable) || !$wgProblemReportsEnable) {
        return '<em>Extension ProblemReports not enabled on this wiki</em>';
        // fallback message
    }
    $params['limit'] = intval($params['limit']);
    $apiParams = array('wkshowall' => $params['pr_raports_from_this_wikia'] == 0 && WikiaApiQueryProblemReports::userCanDoActions() ? 1 : NULL, 'wktype' => intval($params['pr_table_problem_type']) >= 0 ? intval($params['pr_table_problem_type']) : NULL, 'wkstaff' => $params['show'] == 2 ? 1 : NULL, 'wkarchived' => $params['show'] == 1 ? 1 : NULL, 'wklimit' => $params['limit'] <= 0 || $params['limit'] > 50 ? 25 : $params['limit']);
    $apiParams['action'] = 'query';
    $apiParams['list'] = 'problemreports';
    //print_pre($apiParams);
    $data = WidgetFramework::callAPI($apiParams);
    $count = intval($data['query']['reports']);
    if ($count == 0) {
        return array('title' => wfMsg('problemreports'), 'body' => wfMsg('pr_no_reports'));
    }
    $reports = $data['query']['problemreports'];
    $problemTypes = array(wfMsg('pr_what_problem_spam_short'), wfMsg('pr_what_problem_vandalised_short'), wfMsg('pr_what_problem_incorrect_content_short'), wfMsg('pr_what_problem_software_bug_short'), wfMsg('pr_what_problem_other_short'));
    // list reports
    $items = array();
    //url used for linking to PR ids
    $baseUrl = Title::newFromText('ProblemReports', NS_SPECIAL)->getLocalURL();
    // build params for 'more' link based on this widget's settings
    $urlParams = array();
    if ($params['show'] == 2) {
        $urlParams[] = 'staff=1';
    } elseif ($params['show'] == 1) {
        $urlParams[] = 'archived=1';
    }
    if ($apiParams['wkshowall'] == 1) {
        $urlParams[] = 'showall=1';
    }
    if ($apiParams['wktype'] != NULL) {
        $urlParams[] = 'problem=' . $apiParams['wktype'];
    }
    // smush
    $urlParams = implode('&', $urlParams);
    // apply and build
    $moreUrl = Title::newFromText('ProblemReports', NS_SPECIAL)->getLocalURL($urlParams);
    foreach ($reports as $problem) {
        $date = date('d m Y', strtotime($problem['date']));
        $items[] = array('href' => $baseUrl . '/' . $problem['id'], 'title' => '#' . $problem['id'] . ' - ' . wfMsg('pr_table_date_submitted') . ': ' . $date, 'name' => wfShortenText($problem['title'], 25) . ' [' . $problemTypes[$problem['type']] . ($apiParams['wkshowall'] == 1 ? ' | ' . str_replace(array('http://', '.wikia.com', '.wikia-inc.com'), '', $problem['server']) : '') . ']');
    }
    return array('title' => wfMsg('problemreports') . ' (' . $count . ')', 'body' => WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink($moreUrl));
}
Example #13
0
function WidgetTopContentGetSection($id, $functionName)
{
    wfProfileIn(__METHOD__);
    // get list from DataProvider
    $provider =& DataProvider::singleton();
    $articles =& $provider->{$functionName}();
    // make items list
    $items = array();
    if (is_array($articles) && count($articles) > 0) {
        foreach ($articles as $article) {
            if ($article['text'] != 'Not a valid Wikia') {
                $items[] = array('href' => $article['url'], 'name' => $article['text']);
            }
        }
    }
    wfProfileOut(__METHOD__);
    return WidgetFramework::wrapLinks($items);
}
function WidgetEditedRecently($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgTitle, $wgRequest;
    if ((!is_object($wgTitle) || $wgTitle->mArticleID == -1) && $wgRequest->getVal('actionType') == 'add') {
        // ask for page refresh
        wfProfileOut(__METHOD__);
        return wfMsg('refreshpage') . '<br /><br /><button onclick="window.location.reload()">' . wfMsg('go') . '</button>';
    }
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    $title = ($wgTitle->getNamespace() != NS_MAIN ? $wgTitle->getNsText() . ':' : '') . $wgTitle->getText();
    $res = WidgetFramework::callAPI(array('action' => 'query', 'prop' => 'revisions', 'titles' => $title, 'rvprop' => 'user', 'rvlimit' => $limit));
    // create list of recent contributors
    $items = array();
    if (!empty($res['query']['pages'])) {
        $contribs = array_shift($res['query']['pages']);
        if (!empty($contribs['revisions'])) {
            foreach ($contribs['revisions'] as $contrib) {
                $is_anon = isset($contrib['anon']);
                $author = $contrib['user'];
                if ($is_anon) {
                    // don't show anon edits - requested by JohnQ
                    continue;
                } else {
                    $oUser = User::newFromName($author);
                    if ($oUser instanceof User && !$oUser->isBlocked()) {
                        $userPage = $oUser->getUserPage();
                        if ($userPage instanceof Title && $userPage->exists()) {
                            $items[$author] = array('href' => $userPage->getLocalURL(), 'name' => $author);
                        }
                    }
                }
            }
        }
    }
    wfProfileOut(__METHOD__);
    if (count($items) > 0) {
        return WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink($wgTitle->getLocalURL('action=history'));
    } else {
        return wfMsg('nocontributors');
    }
}
Example #15
0
function WidgetLastWikis($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgSitename, $wgCookiePrefix, $wgOut;
    $cookie = isset($_COOKIE["{$wgCookiePrefix}recentlyvisited"]) ? $_COOKIE["{$wgCookiePrefix}recentlyvisited"] : false;
    $server = $_SERVER['SERVER_NAME'];
    $found = false;
    $count = 0;
    $urls = !empty($cookie) ? unserialize($cookie) : array();
    // first, prepare the existing rank
    $items = array();
    if (is_array($urls) && count($urls) > 0) {
        for ($index = 0; $index < 6; $index++) {
            $url = isset($urls[$index]['url']) ? $urls[$index]['url'] : '';
            $name = isset($urls[$index]['name']) ? $urls[$index]['name'] : '';
            if ($url == $server) {
                $found = true;
            } elseif ($url != '') {
                $items[] = array('href' => "http://" . $url, 'name' => $name);
                $count++;
            }
        }
    }
    // next, add the current Wikia into the list, if it's not already there
    if (!$found) {
        if (count($urls) == 5) {
            array_pop($urls);
        }
        if (is_array($url)) {
            array_unshift($urls, array('url' => $server, 'name' => $wgSitename));
        }
        $expire = time() + 3600 * 24 * 7;
        $req = new WebRequest();
        $req->response()->setcookie('recentlyvisited', serialize($urls), $expire);
    }
    if (count($items) > 0) {
        $ret = WidgetFramework::wrapLinks($items);
    } else {
        $ret = $wgOut->parse(wfMsg('wt_lastwikis_noresults'));
    }
    wfProfileOut(__METHOD__);
    return $ret;
}
Example #16
0
function WidgetWatchlist($id, $params)
{
    wfProfileIn(__METHOD__);
    // get last edits from API
    $results = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'watchlist', 'wllimit' => 25));
    $ret = '';
    if (!empty($results['query']['watchlist'])) {
        $list = array();
        foreach ($results['query']['watchlist'] as $watch) {
            $title = Title::newFromText($watch['title'], $watch['ns']);
            $list[] = array('href' => $title->getLocalURL(), 'name' => $watch['title']);
        }
        $ret = WidgetFramework::wrapLinks($list);
    } else {
        $ret = wfMsg('nowatchlist');
    }
    // 'more' link...
    $more = Title::newFromText('Watchlist', NS_SPECIAL)->getLocalURL();
    $ret .= WidgetFramework::moreLink($more);
    wfProfileOut(__METHOD__);
    return $ret;
}
Example #17
0
function WidgetSlideshowGetImagesFromSpecialPage()
{
    wfProfileIn(__METHOD__);
    $images = array();
    // format: "*File_name.ext description goes here\n" (no spaces in the filename; no \newlines inside the description)
    $content = WidgetFramework::getArticle('WidgetSlideshowImages', NS_MEDIAWIKI);
    if (empty($content)) {
        wfProfileOut(__METHOD__);
        return array();
    }
    $list = explode("\n*", trim($content, "\n *"));
    // format data and get image thumb src
    foreach ($list as $row) {
        list($imageName, $description) = explode(' ', trim($row, '* '), 2);
        $img = wfFindFile($imageName);
        if (is_object($img)) {
            $url = Title::newFromText($imageName, NS_IMAGE);
            $thumb = $img->createThumb(250, 125);
            if (!empty($thumb)) {
                $images[] = array('thumb' => $thumb, 'alt' => $description, 'url' => is_object($url) ? $url->getLocalURL() : '');
            }
        }
    }
    wfProfileOut(__METHOD__);
    return $images;
}
Example #18
0
function WidgetReferrers($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgUser, $wgLang, $wgMemc, $wgCityId;
    $limit = array_key_exists('limit', $params) && !empty($params['limit']) ? $params['limit'] : 25;
    $wkuseext = array_key_exists('wt_show_referrers', $params) ? $params['wt_show_referrers'] : 1;
    $wkparamdate = $wkfromdate = array_key_exists('wt_show_period', $params) && !empty($params['wt_show_period']) ? $params['wt_show_period'] : "";
    $memcKey = wfMemcKey('widgets:referers:cloud:' . $limit . ':' . $wkuseext . ':' . $wkparamdate);
    $cloud = $wgMemc->get($memcKey);
    if (is_string($cloud)) {
        //if ( false ) {
        wfProfileOut(__METHOD__);
        return '<!-- using memcache: yes ("' . $memcKey . '") -->' . $cloud;
    }
    wfProfileIn(__METHOD__ . '::miss');
    // get last edits from API
    $api_param = array('action' => 'query', 'list' => 'wkreferer', 'wkcity' => $wgCityId, 'wkusefulldomain' => 1, 'wkuseext' => $wkuseext, 'wknodomain' => 'Unneeded_referrers', 'wklimit' => $limit, 'wkoffset' => 0, 'wkfromdate' => $wkfromdate);
    $results = WidgetFramework::callAPI($api_param);
    if (count($results['query']['wkreferer']) == 0) {
        # show default link to wikia.com
        $default = '<span title="www.wikia.com/1" class="widgetReferrersDomainTag" style="font-size:1em">';
        $default .= '<a href="http://www.wikia.com">www.wikia.com</a></span>';
        return '<div style="text-align:center">' . $default . '</div>';
    }
    $domains = array();
    // prevent showing the IP'like and "wikia.com" domain names
    foreach ($results['query']['wkreferer'] as $domain) {
        if (!User::isIP($domain['domain']) && User::isIP(gethostbyname(trim($domain['domain'])))) {
            if ($wkuseext == 1 && strpos($domain['domain'], 'wikia.com') !== false) {
                continue;
            }
            $domains[$domain['domain']] = $domain['count'];
        }
    }
    // exit early if no domains were found
    if (empty($domains)) {
        $wgMemc->set($memcKey, '', 7200);
        // store for 2h
        // FIXME: should probably give some sort of message to the user
        return '';
    }
    ksort($domains);
    //print_pre($wgCityId);print_pre($results);print_pre($domains);
    // sizing (high math - oh yes ;)
    $min = log(min($domains));
    $max = log(max($domains));
    $min_size = 1;
    $max_size = 3;
    $tags = array();
    // prepare cloud elements
    if ($max) {
        foreach ($domains as $name => $count) {
            $tags[$name] = array('name' => str_replace(array('.com', '.org', '.net', 'www.'), '', $name), 'url' => 'http://' . $name, 'count' => number_format($count, 0, ',', ' '), 'size' => round($min_size + (log($count) - $min) / $max * ($max_size - $min_size), 3));
        }
    }
    //print_pre($tags);
    $ret = '<!-- city: ' . $wgCityId . ' -->';
    foreach ($tags as $tag) {
        $ret .= '<span title="' . htmlspecialchars($tag['name']) . ' / ' . $tag['count'] . '" class="widgetReferrersDomainTag" style="font-size:' . $tag['size'] . 'em">' . '<a href="' . $tag['url'] . '">' . htmlspecialchars($tag['name']) . '</a></span> ';
    }
    $cloud = '<div style="text-align:center">' . $ret . '</div>';
    $wgMemc->set($memcKey, $cloud, 7200);
    // store for 2h
    wfProfileOut(__METHOD__ . '::miss');
    wfProfileOut(__METHOD__);
    return $cloud;
}
Example #19
0
function WidgetShoutBoxGetOnline()
{
    global $wgEnableWhosOnlineExt, $wgMemc;
    if (empty($wgEnableWhosOnlineExt)) {
        return false;
    }
    wfProfileIn(__METHOD__);
    // try memcache
    $key = wfMemcKey('widget::shoutbox::online');
    $online = $wgMemc->get($key);
    // return cached online data
    if (is_array($online)) {
        wfProfileOut(__METHOD__);
        return $online;
    }
    $online = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'whosonline', 'wklimit' => '10'));
    // store in memcache
    if (is_array($online) && isset($online['query'])) {
        $wgMemc->set($key, $online['query'], 600);
    } else {
        $online['query'] = false;
    }
    wfProfileOut(__METHOD__);
    return $online['query'];
}