예제 #1
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);
 }
 /**
  *  Creates a link to the user page (user given by event)
  * @param EchoEvent $event
  * @param Message $message
  * @param type $props
  * @return type
  */
 public function setUserpageLink($event, $message, $props = array())
 {
     if (isset($props['created']) && $props['created']) {
         unset($props['created']);
         $aExtra = $event->getExtra();
         $oUser = User::newFromName($aExtra['user']);
         if (is_object($oUser)) {
             $title = $oUser->getUserPage();
         } else {
             $title = null;
         }
     } else {
         $title = $event->getAgent()->getUserPage();
     }
     if ($title === null) {
         $message->params("'''" . wfMessage('bs-echo-unknown-user') . "'''")->parse();
     } else {
         $this->buildLink($title, $message, $props, false);
     }
 }
 /**
  * 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;
 }
예제 #4
0
 /**
  * Helper function for getLink()
  *
  * @param EchoEvent $event
  * @param User $user The user receiving the notification
  * @param String $destination The destination type for the link
  * @return Array including target and query parameters
  */
 protected function getLinkParams($event, $user, $destination)
 {
     $target = null;
     $query = array();
     // Set up link parameters based on the destination (or pass to parent)
     switch ($destination) {
         case 'link-from-page':
             if ($this->bundleData['use-bundle']) {
                 if ($event->getTitle()) {
                     $target = SpecialPage::getTitleFor('WhatLinksHere', $event->getTitle()->getPrefixedText());
                 }
             } else {
                 $extra = self::extractExtra($event->getExtra());
                 if ($this->isTitleSet($extra)) {
                     $target = Title::newFromId($extra['link-from-page-id']);
                 }
             }
             break;
         default:
             return parent::getLinkParams($event, $user, $destination);
     }
     return array($target, $query);
 }
 /**
  * Don't send email notifications that are imported from LiquidThreads.  It will
  * still be in their web notifications (if enabled), but they will never be
  * notified via email (regardless of batching settings) for this particular
  * notification.
  *
  */
 public static function onEchoAbortEmailNotification(User $user, EchoEvent $event)
 {
     $extra = $event->getExtra();
     if (isset($extra['lqtThreadId']) && $extra['lqtThreadId'] !== null) {
         return false;
     }
     return true;
 }
 /**
  * Returns a revision snippet
  * @param EchoEvent $event The event that the notification is for.
  * @param User $user The user to format the notification for.
  * @return String The revision snippet (or empty string)
  */
 public function getRevisionSnippet($event, $user)
 {
     $extra = $event->getExtra();
     if (!isset($extra['section-text']) || !$event->userCan(Revision::DELETED_TEXT, $user)) {
         return '';
     }
     $snippet = trim($extra['section-text']);
     return $snippet;
 }
 /**
  * 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;
 }
예제 #8
0
 /**
  * Extract the subject anchor (linkable portion of the edited page) from
  * the event.
  *
  * @param $event EchoEvent The event to format the subject anchor of
  * @return string The anchor on page, or an empty string
  */
 protected function formatSubjectAnchor(EchoEvent $event)
 {
     global $wgParser, $wgUser;
     if (!$event->userCan(Revision::DELETED_TEXT, $wgUser)) {
         return $this->getMessage('echo-rev-deleted-text-view')->text();
     }
     $extra = $event->getExtra();
     if (empty($extra['section-title'])) {
         return '';
     }
     // Strip out #, keeping # in the i18n message makes it look more clear
     return substr($wgParser->guessLegacySectionNameFromWikiText($extra['section-title']), 1);
 }