Ejemplo n.º 1
0
 public function execute()
 {
     // To avoid API warning, register the parameter used to bust browser cache
     $this->getMain()->getVal('_');
     $user = $this->getUser();
     //XXCHANGEDXX - allow anons [sc|rs]
     // if ( $user->isAnon() ) {
     // $this->dieUsage( 'Login is required', 'login-required' );
     // }
     $notifUser = MWEchoNotifUser::newFromUser($user);
     $params = $this->extractRequestParams();
     $prop = $params['prop'];
     $result = array();
     if (in_array('list', $prop)) {
         $result['list'] = self::getNotifications($user, $params['format'], $params['limit'] + 1, $params['continue']);
         // check if there is more elements than we request
         if (count($result['list']) > $params['limit']) {
             $lastItem = array_pop($result['list']);
             $result['continue'] = $lastItem['timestamp']['utcunix'] . '|' . $lastItem['id'];
         } else {
             $result['continue'] = null;
         }
         $this->getResult()->setIndexedTagName($result['list'], 'notification');
     }
     if (in_array('count', $prop)) {
         $rawCount = $notifUser->getNotificationCount();
         $result['rawcount'] = $rawCount;
         $result['count'] = EchoNotificationController::formatNotificationCount($rawCount);
     }
     if (in_array('index', $prop)) {
         $result['index'] = array();
         foreach (array_keys($result['list']) as $key) {
             // Don't include the XML tag name ('_element' key)
             if ($key != '_element') {
                 $result['index'][] = $key;
             }
         }
         $this->getResult()->setIndexedTagName($result['index'], 'id');
     }
     $this->getResult()->setIndexedTagName($result, 'notification');
     $this->getResult()->addValue('query', $this->getModuleName(), $result);
 }
Ejemplo n.º 2
0
 public function execute()
 {
     // To avoid API warning, register the parameter used to bust browser cache
     $this->getMain()->getVal('_');
     $user = $this->getUser();
     //XXCHANGEDXX - allow anons [sc|rs]
     // if ( $user->isAnon() ) {
     // $this->dieUsage( 'Login is required', 'login-required' );
     // }
     $notifUser = MWEchoNotifUser::newFromUser($user);
     $params = $this->extractRequestParams();
     // There is no need to trigger markRead if all notifications are read
     if ($notifUser->getNotificationCount() > 0) {
         if (count($params['list'])) {
             // Make sure there is a limit to the update
             $notifUser->markRead(array_slice($params['list'], 0, ApiBase::LIMIT_SML2));
         } elseif ($params['all']) {
             $notifUser->markAllRead();
         }
     }
     $rawCount = $notifUser->getNotificationCount();
     $result = array('result' => 'success', 'rawcount' => $rawCount, 'count' => EchoNotificationController::formatNotificationCount($rawCount));
     $this->getResult()->addValue('query', $this->getModuleName(), $result);
 }
 /**
  * Prepares the user button.
  * @param QuickTemplate $tpl
  */
 protected function prepareUserButton(QuickTemplate $tpl)
 {
     // Set user button to empty string by default
     $tpl->set('secondaryButton', '');
     $notificationsTitle = '';
     $countLabel = '';
     $isZero = true;
     $user = $this->getUser();
     $newtalks = $this->getNewtalks();
     $currentTitle = $this->getTitle();
     // If Echo is available, the user is logged in, and they are not already on the
     // notifications archive, show the notifications icon in the header.
     if ($this->useEcho() && $user->isLoggedIn()) {
         $notificationsTitle = SpecialPage::getTitleFor('Notifications');
         $notificationsMsg = wfMessage('mobile-frontend-user-button-tooltip');
         if ($currentTitle->getPrefixedText() !== $notificationsTitle->getPrefixedText()) {
             $count = MWEchoNotifUser::newFromUser($user)->getNotificationCount();
             $isZero = $count === 0;
             $countLabel = EchoNotificationController::formatNotificationCount($count);
         }
     } elseif (!empty($newtalks)) {
         $notificationsTitle = SpecialPage::getTitleFor('Mytalk');
         $notificationsMsg = wfMessage('mobile-frontend-user-newmessages')->text();
     }
     if ($notificationsTitle) {
         $spanClass = $isZero ? 'zero notification-count' : 'notification-count';
         $url = $notificationsTitle->getLocalURL(array('returnto' => $currentTitle->getPrefixedText()));
         $tpl->set('secondaryButton', $this->createSecondaryButton($notificationsMsg, $url, $countLabel, $spanClass));
     }
 }
Ejemplo n.º 4
0
 /**
  * Retrieves formatted number of unread notifications that a user has.
  * @param $cached bool Set to false to bypass the cache.
  * @param $dbSource int use master or slave database to pull count
  * @return String: Number of unread notifications.
  */
 public function getFormattedNotificationCount($cached = true, $dbSource = DB_SLAVE)
 {
     return EchoNotificationController::formatNotificationCount($this->getNotificationCount($cached, $dbSource));
 }
Ejemplo n.º 5
0
 /**
  * Handler for PersonalUrls hook.
  * Add a "Notifications" item to the user toolbar ('personal URLs').
  * @see http://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
  * @param &$personal_urls Array of URLs to append to.
  * @param &$title Title of page being visited.
  * @param SkinTemplate $sk
  * @return bool true in all cases
  */
 static function onPersonalUrls(&$personal_urls, &$title, $sk)
 {
     global $wgEchoNewMsgAlert;
     $user = $sk->getUser();
     if ($user->isAnon() || self::isEchoDisabled($user)) {
         return true;
     }
     // Add a "My notifications" item to personal URLs
     if ($user->getOption('echo-notify-show-link')) {
         $notificationCount = MWEchoNotifUser::newFromUser($user)->getNotificationCount();
         $text = EchoNotificationController::formatNotificationCount($notificationCount);
         $url = SpecialPage::getTitleFor('Notifications')->getLocalURL();
         if ($notificationCount == 0) {
             $linkClasses = array('mw-echo-notifications-badge');
         } else {
             $linkClasses = array('mw-echo-unread-notifications', 'mw-echo-notifications-badge');
         }
         $notificationsLink = array('href' => $url, 'text' => $text, 'active' => $url == $title->getLocalUrl(), 'class' => $linkClasses);
         $insertUrls = array('notifications' => $notificationsLink);
         $personal_urls = wfArrayInsertAfter($personal_urls, $insertUrls, 'userpage');
     }
     // If the user has new messages, display a talk page alert
     if ($wgEchoNewMsgAlert && $user->getOption('echo-show-alert') && $user->getNewtalk()) {
         $personal_urls['mytalk']['text'] = $sk->msg('echo-new-messages')->text();
         $personal_urls['mytalk']['class'] = array('mw-echo-alert');
         $sk->getOutput()->addModuleStyles('ext.echo.alert');
     }
     return true;
 }