public function index()
 {
     wfProfileIn(__METHOD__);
     Wikia::addAssetsToOutput('recent_wiki_activity_scss');
     Wikia::addAssetsToOutput('recent_wiki_activity_js');
     $this->changeList = WikiaDataAccess::cache(wfMemcKey(self::$memcKey), 0, function () {
         global $wgContentNamespaces, $wgLang;
         $maxElements = 4;
         $includeNamespaces = implode('|', $wgContentNamespaces);
         $parameters = array('type' => 'widget', 'maxElements' => $maxElements, 'flags' => array('shortlist'), 'uselang' => $wgLang->getCode(), 'includeNamespaces' => $includeNamespaces);
         $feedProxy = new ActivityFeedAPIProxy($includeNamespaces, $this->userName);
         $feedProvider = new DataFeedProvider($feedProxy, 1, $parameters);
         $feedData = $feedProvider->get($maxElements);
         foreach ($feedData['results'] as &$result) {
             if (!empty($result['articleComment'])) {
                 $title = Title::newFromText($result['title'], $result['ns']);
                 if ($title instanceof Title) {
                     $result['url'] = $title->getLocalURL();
                 }
             }
         }
         return $feedData['results'];
     });
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 2
0
 public static function getFeed()
 {
     wfProfileIn(__METHOD__);
     // get request params
     global $wgRequest;
     //$type  = $wgRequest->getVal('type', false);
     $since = $wgRequest->getVal('since', wfTimestamp(TS_MW, time()));
     $limit = $wgRequest->getInt('limit', 60);
     $feedProxy = new ActivityFeedAPIProxy();
     $feedRenderer = new ActivityFeedRenderer();
     $feedProvider = new DataFeedProvider($feedProxy);
     $feedData = $feedProvider->get($limit, $since);
     $feedHTML = $feedRenderer->render($feedData, false);
     wfProfileOut(__METHOD__);
     // get feed
     return array('fetchSince' => isset($feedData['query-continue']) ? $feedData['query-continue'] : false, 'html' => $feedHTML);
 }
Ejemplo n.º 3
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $attributes = '';
     $parameters = ActivityFeedHelper::parseParameters($attributes);
     $removeDuplicatesType = in_array('shortlist', $parameters['flags']) ? 1 : 0;
     //remove duplicates using only title for shortlist
     $feedProxy = new ActivityFeedAPIProxy($parameters['includeNamespaces']);
     $feedRenderer = new ActivityFeedRenderer();
     $feedProvider = new DataFeedProvider($feedProxy, $removeDuplicatesType, $parameters);
     $feedData = $feedProvider->get($parameters['maxElements']);
     #echo "<pre>";
     #print_r($feedData);
     #die;
     $data = array();
     foreach ($feedData["results"] as $id => $row) {
         $data[] = $this->rewriteRow($row);
     }
     #print_r($data);
     #die;
     $this->getResult()->setIndexedTagName($data, "af");
     $this->getResult()->addValue("query", $this->getModuleName(), $data);
 }
Ejemplo n.º 4
0
 /**
  * @author Maciej Błaszkowski <marooned at wikia-inc.com>
  */
 static function getList($parameters)
 {
     wfProfileIn(__METHOD__);
     $removeDuplicatesType = in_array('shortlist', $parameters['flags']) ? 1 : 0;
     //remove duplicates using only title for shortlist
     $feedProxy = new ActivityFeedAPIProxy($parameters['includeNamespaces']);
     $feedRenderer = new ActivityFeedRenderer();
     $feedProvider = new DataFeedProvider($feedProxy, $removeDuplicatesType, $parameters);
     $feedData = $feedProvider->get($parameters['maxElements']);
     if (!isset($feedData['results']) || count($feedData['results']) == 0) {
         wfProfileOut(__METHOD__);
         return '';
     }
     $feedHTML = $feedRenderer->render($feedData, false, $parameters);
     $feedHTML = str_replace("\n", '', $feedHTML);
     wfProfileOut(__METHOD__);
     return $feedHTML;
 }
 public function executeIndex()
 {
     wfProfileIn(__METHOD__);
     $maxElements = 4;
     global $wgLang, $wgContentNamespaces, $wgMemc, $wgUser;
     $this->moduleHeader = wfMsg('oasis-activity-header');
     if (empty($this->userName)) {
         $mKey = wfMemcKey('mOasisLatestActivity');
         $feedData = $wgMemc->get($mKey);
     }
     if (empty($feedData)) {
         // data provider
         $includeNamespaces = implode('|', $wgContentNamespaces);
         $parameters = array('type' => 'widget', 'maxElements' => $maxElements, 'flags' => array('shortlist'), 'uselang' => $wgLang->getCode(), 'includeNamespaces' => $includeNamespaces);
         $feedProxy = new ActivityFeedAPIProxy($includeNamespaces, $this->userName);
         $feedProvider = new DataFeedProvider($feedProxy, 1, $parameters);
         $feedData = $feedProvider->get($maxElements);
         if (empty($this->userName)) {
             $wgMemc->set($mKey, $feedData);
         }
     }
     // Time strings are slow to calculate, but we still want them to update frequently (60 seconds)
     if (empty($this->userName)) {
         $mKeyTimes = wfMemcKey('mOasisLatestActivity_times', $wgLang->getCode());
         $this->changeList = $wgMemc->get($mKeyTimes, array());
     }
     if (empty($this->changeList) && !empty($feedData) && is_array($feedData['results'])) {
         $changeList = array();
         foreach ($feedData['results'] as $change) {
             $item = array();
             $item['time_ago'] = wfTimeFormatAgoOnlyRecent($change['timestamp']);
             // TODO: format the timestamp on front-end to allow longer caching in memcache?
             $item['user_name'] = $change['username'];
             $item['avatar_url'] = AvatarService::getAvatarUrl($item['user_name'], 20);
             $item['user_href'] = AvatarService::renderLink($item['user_name']);
             $item['page_title'] = $change['title'];
             $item['changetype'] = $change['type'];
             $title = Title::newFromText($change['title'], $change['ns']);
             if (!empty($change['articleComment']) && !empty($change['url'])) {
                 $item['page_href'] = Xml::element('a', array('href' => $change['url']), $item['page_title']);
             } else {
                 if (is_object($title)) {
                     $item['page_href'] = Xml::element('a', array('href' => $title->getLocalUrl()), $item['page_title']);
                 }
             }
             switch ($change['type']) {
                 case 'new':
                 case 'edit':
                 case 'delete':
                     // different formatting for User Profile Pages
                     if (!empty($this->userName)) {
                         $item['page_href'] = wfMsg("userprofilepage-activity-{$change['type']}", $item['page_href']);
                         $item['changemessage'] = $item['time_ago'];
                     } else {
                         // format message (RT #144814)
                         $item['changemessage'] = wfMsg("oasis-latest-activity-{$change['type']}-details", $item['user_href'], $item['time_ago']);
                     }
                     $item['changeicon'] = $change['type'];
                     break;
                 default:
                     // show just a timestamp
                     $item['changemessage'] = $item['time_ago'];
                     break;
             }
             $changeList[] = $item;
         }
         $this->changeList = $changeList;
         if (empty($this->userName)) {
             $wgMemc->set($mKeyTimes, $this->changeList, 60);
         }
     }
     // Cache the response in CDN and browser
     $this->response->setCacheValidity(600);
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 6
0
 private function filterHiddenCategories($categories)
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     if (!is_array(self::$hiddenCategories)) {
         $memcKey = wfMemcKey('hidden-categories');
         self::$hiddenCategories = $wgMemc->get($memcKey);
         if (!is_array(self::$hiddenCategories)) {
             $dbr = wfGetDB(DB_SLAVE);
             $res = $dbr->query("SELECT page_title FROM page JOIN page_props ON page_id=pp_page AND pp_propname='hiddencat';");
             self::$hiddenCategories = array();
             while ($row = $dbr->fetchObject($res)) {
                 self::$hiddenCategories[] = $row->page_title;
             }
             $wgMemc->set($memcKey, self::$hiddenCategories, 60 * 60);
         }
     }
     $categories = array_values(array_diff($categories, self::$hiddenCategories));
     wfProfileOut(__METHOD__);
     return $categories;
 }
Ejemplo n.º 7
0
 /**
  * Get list of hidden categories (cached in memcached using WikiaDataAccess).
  *
  * Using WikiaDataAccess to limit number of processes regenerating cache and prevent delay when other
  * process is already regenerating data. The stalled data is returned in the latter case.
  *
  * @see https://wikia-inc.atlassian.net/browse/PLATFORM-615
  *
  * @return array
  */
 private function getHiddenCategories()
 {
     wfProfileIn(__METHOD__);
     $fname = __METHOD__;
     if (!is_array(self::$hiddenCategories)) {
         self::$hiddenCategories = WikiaDataAccess::cacheWithLock(wfMemcKey('hidden-categories-v2'), WikiaResponse::CACHE_SHORT, function () use($fname) {
             $dbr = wfGetDB(DB_SLAVE);
             $res = $dbr->query("SELECT page_title FROM page JOIN page_props ON page_id=pp_page AND pp_propname='hiddencat' LIMIT " . self::HIDDEN_CATEGORIES_LIMIT, $fname);
             $hiddenCategories = array();
             while ($row = $dbr->fetchObject($res)) {
                 $hiddenCategories[] = $row->page_title;
             }
             return $hiddenCategories;
         });
     }
     wfProfileOut(__METHOD__);
     return self::$hiddenCategories;
 }
    function execute($par)
    {
        wfProfileIn(__METHOD__);
        global $wgOut, $wgUser, $wgBlankImgUrl;
        $this->setHeaders();
        // not available for skins different than Oasis
        if (!F::app()->checkSkin('oasis')) {
            $wgOut->addWikiMsg('myhome-switch-to-monaco');
            wfProfileOut(__METHOD__);
            return;
        }
        // choose default view (RT #68074)
        if ($wgUser->isLoggedIn()) {
            $this->defaultView = MyHome::getDefaultView();
            if ($par == '') {
                $par = $this->defaultView;
            }
        } else {
            $this->defaultView = false;
        }
        // watchlist feed
        if ($par == 'watchlist') {
            $this->classWatchlist = "selected";
            // not available for anons
            if ($wgUser->isAnon()) {
                if (get_class(RequestContext::getMain()->getSkin()) == 'SkinOasis') {
                    $wgOut->wrapWikiMsg('<div class="latest-activity-watchlist-login" >$1</div>', array('oasis-activity-watchlist-login', wfGetReturntoParam()));
                } else {
                    $wgOut->wrapWikiMsg('<div id="myhome-log-in">$1</div>', array('myhome-log-in', wfGetReturntoParam()));
                }
                //oasis-activity-watchlist-login
                // RT #23970
                $wgOut->addInlineScript(<<<JS
\$(function() {
\t\$('#myhome-log-in').find('a').click(function(ev) {
\t\topenLogin(ev);
\t});
});
JS
);
                wfProfileOut(__METHOD__);
                return;
            } else {
                $this->feedSelected = 'watchlist';
                $feedProxy = new WatchlistFeedAPIProxy();
                $feedRenderer = new WatchlistFeedRenderer();
            }
        } else {
            //for example: wiki-domain.com/wiki/Special:WikiActivity
            $this->feedSelected = 'activity';
            $feedProxy = new ActivityFeedAPIProxy();
            $feedRenderer = new ActivityFeedRenderer();
        }
        $feedProvider = new DataFeedProvider($feedProxy);
        global $wgJsMimeType, $wgExtensionsPath;
        $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgExtensionsPath}/wikia/MyHome/WikiActivity.js\"></script>\n");
        $wgOut->addExtensionStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/MyHome/oasis.scss'));
        wfRunHooks('SpecialWikiActivityExecute', array($wgOut, $wgUser));
        $data = $feedProvider->get(50);
        // this breaks when set to 60...
        // FIXME: do it in AchievementsII extension
        global $wgEnableAchievementsInActivityFeed, $wgEnableAchievementsExt;
        if (!empty($wgEnableAchievementsInActivityFeed) && !empty($wgEnableAchievementsExt)) {
            $wgOut->addExtensionStyle("{$wgExtensionsPath}/wikia/AchievementsII/css/achievements_sidebar.css");
        }
        // use message from MyHome as special page title
        $wgOut->setPageTitle(wfMsg('oasis-activity-header'));
        $template = new EasyTemplate(dirname(__FILE__) . '/templates');
        $template->set('data', $data['results']);
        $showMore = isset($data['query-continue']);
        if ($showMore) {
            $template->set('query_continue', $data['query-continue']);
        }
        if (empty($data['results'])) {
            $template->set('emptyMessage', wfMsgExt("myhome-activity-feed-empty", array('parse')));
        }
        $template->set_vars(array('showMore' => $showMore, 'type' => $this->feedSelected, 'wgBlankImgUrl' => $wgBlankImgUrl));
        $wgOut->addHTML($template->render('activityfeed.oasis'));
        // page header: replace subtitle with navigation
        global $wgHooks;
        $wgHooks['PageHeaderIndexAfterExecute'][] = array(&$this, 'addNavigation');
        wfProfileOut(__METHOD__);
    }