예제 #1
0
 /**
  * Immediate version of notifyOnPageChange().
  *
  * Send emails corresponding to the user $editor editing the page $title.
  *
  * @note Do not call directly. Use notifyOnPageChange so that wl_notificationtimestamp is updated.
  * @param User $editor
  * @param Title $title
  * @param string $timestamp Edit timestamp
  * @param string $summary Edit summary
  * @param bool $minorEdit
  * @param int $oldid Revision ID
  * @param array $watchers Array of user IDs
  * @param string $pageStatus
  * @throws MWException
  */
 public function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus = 'changed')
 {
     # we use $wgPasswordSender as sender's address
     global $wgEnotifWatchlist;
     global $wgEnotifMinorEdits, $wgEnotifUserTalk;
     # The following code is only run, if several conditions are met:
     # 1. EmailNotification for pages (other than user_talk pages) must be enabled
     # 2. minor edits (changes) are only regarded if the global flag indicates so
     $isUserTalkPage = $title->getNamespace() == NS_USER_TALK;
     $this->title = $title;
     $this->timestamp = $timestamp;
     $this->summary = $summary;
     $this->minorEdit = $minorEdit;
     $this->oldid = $oldid;
     $this->editor = $editor;
     $this->composed_common = false;
     $this->pageStatus = $pageStatus;
     $formattedPageStatus = array('deleted', 'created', 'moved', 'restored', 'changed');
     Hooks::run('UpdateUserMailerFormattedPageStatus', array(&$formattedPageStatus));
     if (!in_array($this->pageStatus, $formattedPageStatus)) {
         throw new MWException('Not a valid page status!');
     }
     $userTalkId = false;
     if (!$minorEdit || $wgEnotifMinorEdits && !$editor->isAllowed('nominornewtalk')) {
         if ($wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail($editor, $title, $minorEdit)) {
             $targetUser = User::newFromName($title->getText());
             $this->compose($targetUser);
             $userTalkId = $targetUser->getId();
         }
         if ($wgEnotifWatchlist) {
             // Send updates to watchers other than the current editor
             $userArray = UserArray::newFromIDs($watchers);
             foreach ($userArray as $watchingUser) {
                 if ($watchingUser->getOption('enotifwatchlistpages') && (!$minorEdit || $watchingUser->getOption('enotifminoredits')) && $watchingUser->isEmailConfirmed() && $watchingUser->getID() != $userTalkId) {
                     if (Hooks::run('SendWatchlistEmailNotification', array($watchingUser, $title, $this))) {
                         $this->compose($watchingUser);
                     }
                 }
             }
         }
     }
     global $wgUsersNotifiedOnAllChanges;
     foreach ($wgUsersNotifiedOnAllChanges as $name) {
         if ($editor->getName() == $name) {
             // No point notifying the user that actually made the change!
             continue;
         }
         $user = User::newFromName($name);
         $this->compose($user);
     }
     $this->sendMails();
 }
 /**
  * Do a LinkBatch query to minimise database load when generating all these links
  * @param $result
  */
 function preprocessResults($result)
 {
     wfProfileIn(__METHOD__);
     # Do a link batch query
     $lb = new LinkBatch();
     $lb->setCaller(__METHOD__);
     $userids = array();
     foreach ($result as $row) {
         $userids[] = $row->ipb_by;
         # Usernames and titles are in fact related by a simple substitution of space -> underscore
         # The last few lines of Title::secureAndSplit() tell the story.
         $name = str_replace(' ', '_', $row->ipb_address);
         $lb->add(NS_USER, $name);
         $lb->add(NS_USER_TALK, $name);
     }
     $ua = UserArray::newFromIDs($userids);
     foreach ($ua as $user) {
         $name = str_replace(' ', '_', $user->getName());
         $lb->add(NS_USER, $name);
         $lb->add(NS_USER_TALK, $name);
     }
     $lb->execute();
     wfProfileOut(__METHOD__);
 }
예제 #3
0
 /**
  * Immediate version of notifyOnPageChange().
  *
  * Send emails corresponding to the user $editor editing the page $title.
  * Also updates wl_notificationtimestamp.
  *
  * @param array $watchers
  */
 private function actuallyNotifyOnPageChange($watchers)
 {
     $this->setReplyToAndFromAddresses();
     # The following code is only run, if several conditions are met:
     # 1. EmailNotification for pages (other than user_talk pages) must be enabled
     # 2. minor edits (changes) are only regarded if the global flag indicates so
     if (!$this->isMinorEdit() || $this->notifyUsersOnMinorEdits() && $this->editorWantsToNotifyOnMinorEdits()) {
         $userTalkId = 0;
         if ($this->isUserTalkPage() && $this->canSendUserTalkEmail()) {
             $targetUser = User::newFromName($this->title->getText());
             $this->compose($targetUser);
             $userTalkId = $targetUser->getId();
             // Send mail to user when comment on his user talk has been added
             $fakeUser = null;
             wfRunHooks('UserMailer::NotifyUser', [$this->title, &$fakeUser]);
             if ($fakeUser instanceof User && $fakeUser->getGlobalPreference('enotifusertalkpages') && $fakeUser->isEmailConfirmed()) {
                 $this->compose($fakeUser);
             }
         }
         if (F::app()->wg->EnotifWatchlist) {
             // Send updates to watchers other than the current editor
             $userArray = UserArray::newFromIDs($watchers);
             /* @var $watchingUser User */
             foreach ($userArray as $watchingUser) {
                 if ($watchingUser->getGlobalPreference('enotifwatchlistpages') && (!$this->isMinorEdit() || $watchingUser->getGlobalPreference('enotifminoredits')) && $watchingUser->isEmailConfirmed() && $watchingUser->getID() != $userTalkId && !(bool) $watchingUser->getGlobalPreference('unsubscribed')) {
                     $this->compose($watchingUser);
                 }
             }
         }
     }
     $this->emailUsersNotifiedOnAllChanges();
 }
예제 #4
0
 /**
  * Immediate version of notifyOnPageChange().
  *
  * Send emails corresponding to the user $editor editing the page $title.
  * Also updates wl_notificationtimestamp.
  *
  * @param $editor User object
  * @param $title Title object
  * @param $timestamp string Edit timestamp
  * @param $summary string Edit summary
  * @param $minorEdit bool
  * @param $oldid int Revision ID
  * @param $watchers array of user IDs
  */
 public function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers)
 {
     # we use $wgPasswordSender as sender's address
     global $wgEnotifWatchlist;
     global $wgEnotifMinorEdits, $wgEnotifUserTalk;
     wfProfileIn(__METHOD__);
     # The following code is only run, if several conditions are met:
     # 1. EmailNotification for pages (other than user_talk pages) must be enabled
     # 2. minor edits (changes) are only regarded if the global flag indicates so
     $isUserTalkPage = $title->getNamespace() == NS_USER_TALK;
     $this->title = $title;
     $this->timestamp = $timestamp;
     $this->summary = $summary;
     $this->minorEdit = $minorEdit;
     $this->oldid = $oldid;
     $this->editor = $editor;
     $this->composed_common = false;
     $userTalkId = false;
     if (!$minorEdit || $wgEnotifMinorEdits && !$editor->isAllowed('nominornewtalk')) {
         if ($wgEnotifUserTalk && $isUserTalkPage) {
             $targetUser = User::newFromName($title->getText());
             if (!$targetUser || $targetUser->isAnon()) {
                 wfDebug(__METHOD__ . ": user talk page edited, but user does not exist\n");
             } elseif ($targetUser->getId() == $editor->getId()) {
                 wfDebug(__METHOD__ . ": user edited their own talk page, no notification sent\n");
             } elseif ($targetUser->getOption('enotifusertalkpages') && (!$minorEdit || $targetUser->getOption('enotifminoredits'))) {
                 if ($targetUser->isEmailConfirmed()) {
                     wfDebug(__METHOD__ . ": sending talk page update notification\n");
                     $this->compose($targetUser);
                     $userTalkId = $targetUser->getId();
                 } else {
                     wfDebug(__METHOD__ . ": talk page owner doesn't have validated email\n");
                 }
             } else {
                 wfDebug(__METHOD__ . ": talk page owner doesn't want notifications\n");
             }
         }
         if ($wgEnotifWatchlist) {
             // Send updates to watchers other than the current editor
             $userArray = UserArray::newFromIDs($watchers);
             foreach ($userArray as $watchingUser) {
                 if ($watchingUser->getOption('enotifwatchlistpages') && (!$minorEdit || $watchingUser->getOption('enotifminoredits')) && $watchingUser->isEmailConfirmed() && $watchingUser->getID() != $userTalkId) {
                     $this->compose($watchingUser);
                 }
             }
         }
     }
     global $wgUsersNotifiedOnAllChanges;
     foreach ($wgUsersNotifiedOnAllChanges as $name) {
         $user = User::newFromName($name);
         $this->compose($user);
     }
     $this->sendMails();
     wfProfileOut(__METHOD__);
 }
예제 #5
0
 /**
  * Immediate version of notifyOnPageChange().
  *
  * Send emails corresponding to the user $editor editing the page $title.
  * Also updates wl_notificationtimestamp.
  *
  * @param $editor User object
  * @param $title Title object
  * @param $timestamp string Edit timestamp
  * @param $summary string Edit summary
  * @param $minorEdit bool
  * @param $oldid int Revision ID
  * @param $watchers array of user IDs
  * @param $action (Wikia)
  * @param $otherParam
  */
 public function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $action = '', $otherParam = array())
 {
     # we use $wgPasswordSender as sender's address
     global $wgEnotifWatchlist;
     global $wgEnotifMinorEdits, $wgEnotifUserTalk;
     wfProfileIn(__METHOD__);
     # The following code is only run, if several conditions are met:
     # 1. EmailNotification for pages (other than user_talk pages) must be enabled
     # 2. minor edits (changes) are only regarded if the global flag indicates so
     $isUserTalkPage = $title->getNamespace() == NS_USER_TALK;
     $this->title = $title;
     $this->timestamp = $timestamp;
     $this->summary = $summary;
     $this->minorEdit = $minorEdit;
     $this->oldid = $oldid;
     $this->action = $action;
     $this->editor = $editor;
     $this->composed_common = false;
     $this->other_param = $otherParam;
     $userTalkId = false;
     if (!$minorEdit || $wgEnotifMinorEdits && !$editor->isAllowed('nominornewtalk')) {
         if ($wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail($editor, $title, $minorEdit)) {
             $targetUser = User::newFromName($title->getText());
             $this->compose($targetUser);
             $userTalkId = $targetUser->getId();
             /* Wikia change begin - @author: Marooned */
             /* Send mail to user when comment on his user talk has been added - see RT#44830 */
             $fakeUser = null;
             wfRunHooks('UserMailer::NotifyUser', array($title, &$fakeUser));
             if ($fakeUser instanceof User && $fakeUser->getOption('enotifusertalkpages') && $fakeUser->isEmailConfirmed()) {
                 wfDebug(__METHOD__ . ": sending talk page update notification\n");
                 $this->compose($fakeUser);
             }
             /* Wikia change end */
         }
         if ($wgEnotifWatchlist) {
             // Send updates to watchers other than the current editor
             $userArray = UserArray::newFromIDs($watchers);
             foreach ($userArray as $watchingUser) {
                 if ($watchingUser->getOption('enotifwatchlistpages') && (!$minorEdit || $watchingUser->getOption('enotifminoredits')) && $watchingUser->isEmailConfirmed() && $watchingUser->getID() != $userTalkId) {
                     $this->compose($watchingUser);
                 }
             }
         }
     }
     global $wgUsersNotifiedOnAllChanges;
     foreach ($wgUsersNotifiedOnAllChanges as $name) {
         if ($editor->getName() == $name) {
             // No point notifying the user that actually made the change!
             continue;
         }
         $user = User::newFromName($name);
         $this->compose($user);
     }
     $this->sendMails();
     wfProfileOut(__METHOD__);
 }
예제 #6
0
파일: User.php 프로젝트: paladox/mediawiki
 /**
  * Return the users who are members of the given group(s). In case of multiple groups,
  * users who are members of at least one of them are returned.
  *
  * @param string|array $groups A single group name or an array of group names
  * @param int $limit Max number of users to return. The actual limit will never exceed 5000
  *   records; larger values are ignored.
  * @param int $after ID the user to start after
  * @return UserArrayFromResult
  */
 public static function findUsersByGroup($groups, $limit = 5000, $after = null)
 {
     if ($groups === []) {
         return UserArrayFromResult::newFromIDs([]);
     }
     $groups = array_unique((array) $groups);
     $limit = min(5000, $limit);
     $conds = ['ug_group' => $groups];
     if ($after !== null) {
         $conds[] = 'ug_user > ' . (int) $after;
     }
     $dbr = wfGetDB(DB_REPLICA);
     $ids = $dbr->selectFieldValues('user_groups', 'ug_user', $conds, __METHOD__, ['DISTINCT' => true, 'ORDER BY' => 'ug_user', 'LIMIT' => $limit]) ?: [];
     return UserArray::newFromIDs($ids);
 }