示例#1
0
function WidgetCommunity($id, $params)
{
    global $wgEnableCommunityWidget, $wgTitle;
    if (empty($wgEnableCommunityWidget)) {
        return '';
    }
    if ($params['skinname'] != 'oasis') {
        return '';
    }
    if (!class_exists('ActivityFeedHelper')) {
        return '';
    }
    wfProfileIn(__METHOD__);
    global $wgUser, $wgLang, $wgLanguageCode, $wgStylePath, $wgEnableMyHomeExt, $wgContentNamespaces;
    $total = SiteStats::articles();
    /* RT#64490: Strange Article Count in Latest Activity on some new wikis */
    if ($total < 0 || $total > 1.0E+18) {
        $total = 0;
    }
    $total = $wgLang->formatNum($total);
    $footerButton = array();
    if (!empty($wgEnableMyHomeExt)) {
        $footerButton['text'] = wfMsg('widget-community-more');
        $footerButton['href'] = Skin::makeSpecialUrl($wgUser->isLoggedIn() ? 'MyHome' : 'ActivityFeed');
        $footerButton['class'] = 'wikia-button forward';
    } else {
        $footerButton['text'] = wfMsg('recentchanges');
        $footerButton['href'] = Skin::makeSpecialUrl('RecentChanges');
        $footerButton['class'] = 'wikia-button forward';
    }
    $maxElements = 5;
    $includeNamespaces = implode('|', $wgContentNamespaces);
    $uselang = $wgLang->getCode();
    //this should be the same as in /extensions/wikia/MyHome/ActivityFeedHelper.php
    $parameters = array('type' => 'widget', 'tagid' => $id, 'maxElements' => $maxElements, 'flags' => array('shortlist'), 'uselang' => $uselang, 'includeNamespaces' => $includeNamespaces);
    $userLangEqContent = $uselang == $wgLanguageCode;
    $feedHTML = ActivityFeedHelper::getListForWidget($parameters, $userLangEqContent);
    // template stuff
    $tmpl = new EasyTemplate(dirname(__FILE__));
    $tmpl->set_vars(array('tagid' => $id, 'timestamp' => wfTimestampNow(), 'header' => wfMsg('monaco-articles-on', $total), 'feedHTML' => $feedHTML, 'footerButton' => $footerButton));
    $output = $tmpl->render('WidgetCommunity');
    wfProfileOut(__METHOD__);
    return $output;
}
示例#2
0
/**
 * @author Maciej Błaszkowski <marooned at wikia-inc.com>
 */
function CommunityWidgetAjax()
{
    global $wgRequest, $wgLang, $wgLanguageCode, $wgContentNamespaces;
    wfProfileIn(__METHOD__);
    //this should be the same as in /extensions/wikia/WidgetFramework/Widgets/WidgetCommunity/WidgetCommunity.php
    $parameters = array('type' => 'widget', 'maxElements' => 5, 'flags' => array('shortlist'), 'includeNamespaces' => implode('|', $wgContentNamespaces));
    $uselang = $wgRequest->getVal('uselang');
    $langCode = $wgLang->getCode();
    if (!empty($uselang) && $langCode != $uselang) {
        $wgLang = Language::factory($uselang);
    } else {
        $uselang = $langCode;
    }
    $parameters['uselang'] = $uselang;
    $userLangEqContent = $uselang == $wgLanguageCode && $uselang == 'en';
    //since we are using jQuery `timeago` plugin which works only for en, let's cache longer only this language
    $feedHTML = ActivityFeedHelper::getListForWidget($parameters, $userLangEqContent);
    $data = array('data' => $feedHTML, 'timestamp' => wfTimestampNow());
    $json = json_encode($data);
    $response = new AjaxResponse($json);
    $response->setContentType('application/json; charset=utf-8');
    $response->setCacheDuration($userLangEqContent ? 60 * 60 * 24 : 60 * 5);
    wfProfileOut(__METHOD__);
    return $response;
}