Beispiel #1
0
 /**
  * Adds this new notification object to the backend storage.
  */
 protected function insert()
 {
     global $wgEchoBackend, $wgEchoNotifications;
     $row = array('notification_event' => $this->event->getId(), 'notification_user' => $this->user->getId(), 'notification_anon_ip' => $this->user->isAnon() ? $this->user->getName() : $this->user->getId(), 'notification_timestamp' => $this->timestamp, 'notification_read_timestamp' => $this->readTimestamp, 'notification_bundle_hash' => '', 'notification_bundle_display_hash' => '');
     // Get the bundle key for this event if web bundling is enabled
     $bundleKey = '';
     if (!empty($wgEchoNotifications[$this->event->getType()]['bundle']['web'])) {
         wfRunHooks('EchoGetBundleRules', array($this->event, &$bundleKey));
     }
     if ($bundleKey) {
         $hash = md5($bundleKey);
         $row['notification_bundle_hash'] = $hash;
         $lastStat = $wgEchoBackend->getLastBundleStat($this->user, $hash);
         // Use a new display hash if:
         // 1. there was no last bundle notification
         // 2. last bundle notification with the same hash was read
         if ($lastStat && !$lastStat->notification_read_timestamp) {
             $row['notification_bundle_display_hash'] = $lastStat->notification_bundle_display_hash;
         } else {
             $row['notification_bundle_display_hash'] = md5($bundleKey . '-display-hash-' . wfTimestampNow());
         }
     }
     $wgEchoBackend->createNotification($row);
     wfRunHooks('EchoCreateNotificationComplete', array($this));
 }
Beispiel #2
0
 /**
  * Function for logging the event for Schema:Echo
  * @param $user User being notified.
  * @param $event EchoEvent to log detail about.
  * @param $deliveryMethod string containing either 'web' or 'email'
  */
 public static function logSchemaEcho(User $user, EchoEvent $event, $deliveryMethod)
 {
     global $wgEchoConfig, $wgEchoNotifications;
     if (!$wgEchoConfig['eventlogging']['Echo']['enabled']) {
         // Only attempt event logging if Echo schema is enabled
         return;
     }
     // Notifications under system category should have -1 as sender id
     if ($event->getCategory() === 'system') {
         $sender = -1;
     } else {
         $agent = $event->getAgent();
         if ($agent) {
             $sender = $agent->isAnon() ? $agent->getName() : $agent->getId();
         } else {
             $sender = -1;
         }
     }
     if (isset($wgEchoNotifications[$event->getType()]['group'])) {
         $group = $wgEchoNotifications[$event->getType()]['group'];
     } else {
         $group = 'neutral';
     }
     $data = array('version' => $wgEchoConfig['version'], 'eventId' => $event->getId(), 'notificationType' => $event->getType(), 'notificationGroup' => $group, 'sender' => (string) $sender, 'recipientUserId' => $user->getId(), 'recipientEditCount' => (int) $user->getEditCount());
     // Add the source if it exists. (This is mostly for the Thanks extension.)
     $extra = $event->getExtra();
     if (isset($extra['source'])) {
         $data['eventSource'] = (string) $extra['source'];
     }
     if ($deliveryMethod == 'email') {
         $data['deliveryMethod'] = 'email';
     } else {
         // whitelist valid delivery methods so it is always valid
         $data['deliveryMethod'] = 'web';
     }
     // Add revision ID if it exists
     $rev = $event->getRevision();
     if ($rev) {
         $data['revisionId'] = $rev->getId();
     }
     self::actuallyLogTheEvent('Echo', $data);
 }
 /**
  * Hook for email notification
  * @param User $user
  * @param EchoEvent $event
  * @return boolean
  */
 public function onEchoAbortEmailNotification($user, $event)
 {
     //New user notification is only for admins
     if ($event->getType() == 'bs-newuser') {
         if (!$user->isAllowed('wikiadmin')) {
             return false;
         }
     }
     return true;
 }
 /**
  * Add user to be notified on echo event
  * @param EchoEvent $event
  * @param array $users
  * @return bool
  */
 public static function onEchoGetDefaultNotifiedUsers($event, &$users)
 {
     switch ($event->getType()) {
         case 'cx-first-translation':
         case 'cx-tenth-translation':
         case 'cx-hundredth-translation':
             $extra = $event->getExtra();
             if (!isset($extra['recipient'])) {
                 break;
             }
             $recipientId = $extra['recipient'];
             $recipient = User::newFromId($recipientId);
             $users[$recipientId] = $recipient;
             break;
     }
     return true;
 }
 /**
  * Handler for EchoGetDefaultNotifiedUsers hook.
  * @param EchoEvent $event EchoEvent to get implicitly subscribed users for
  * @param array &$users Array to append implicitly subscribed users to.
  * @return bool true in all cases
  */
 public static function onEchoGetDefaultNotifiedUsers($event, &$users)
 {
     switch ($event->getType()) {
         case 'bs-shoutbox-mention':
             $extra = $event->getExtra();
             if (!$extra || !isset($extra['mentioned-user-id'])) {
                 break;
             }
             $recipientId = $extra['mentioned-user-id'];
             //really ugly, but newFromId appears to be broken...
             $oDBr = wfGetDB(DB_SLAVE);
             $row = $oDBr->selectRow('user', '*', array('user_id' => (int) $recipientId));
             $recipient = User::newFromRow($row);
             $users[$recipientId] = $recipient;
             //$event->setExtra('username', $recipient->);
             break;
     }
     return true;
 }
 /**
  * Echo!
  *
  * @param $event EchoEvent
  * @return bool
  */
 public static function onBeforeEchoEventInsert(EchoEvent $event)
 {
     // Don't spam a user with mention notifications if it's a MassMessage
     if ($event->getType() == 'mention' && $event->getAgent() && $event->getAgent()->getId() == MassMessage::getMessengerUser()->getId()) {
         return false;
     }
     return true;
 }