/**
  * Get all sandboxed users.
  * @return UserArray List of users.
  */
 public static function getUsers()
 {
     $dbw = wfGetDB(DB_MASTER);
     $tables = array('user', 'user_groups');
     $fields = User::selectFields();
     $conds = array('ug_group' => 'translate-sandboxed', 'ug_user = user_id');
     $res = $dbw->select($tables, $fields, $conds, __METHOD__);
     return UserArray::newFromResult($res);
 }
 function execute($par)
 {
     global $wgOut, $wgUser, $wgEmailAuthentication;
     $this->setHeaders();
     if (!$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         return;
     }
     $error = SpecialEmailUser::getPermissionsError($wgUser, $wgUser->editToken());
     if ($error) {
         switch ($error) {
             case 'blockedemailuser':
                 $wgOut->blockedPage();
                 return;
             case 'actionthrottledtext':
                 $wgOut->rateLimited();
                 return;
             case 'mailnologin':
                 $wgOut->showErrorPage('mailnologin', 'mailnologintext');
                 return;
             default:
                 list($title, $msg, $params) = $error;
                 $wgOut->showErrorPage($title, $msg, $params);
                 return;
         }
     }
     $dbr = wfGetDB(DB_SLAVE);
     # $conds can be not that strict but cannot be too strict.
     $conds = array("user_email <> ''");
     if ($wgEmailAuthentication) {
         $conds[] = 'user_email_authenticated IS NOT NULL';
     }
     $res = $dbr->select('user', '*', $conds);
     $users = UserArray::newFromResult($res);
     $usernames = array();
     foreach ($users as $user) {
         if ($user->canReceiveEmail() && $user->getId() != $wgUser->getId()) {
             $usernames[$user->getName()] = $user->getId();
         }
     }
     $this->userIds = array_values($usernames);
     if (empty($usernames)) {
         # No one to send mail to
         $wgOut->addWikiMsg('emailusers-norecipient');
         $wgOut->returnToMain();
         return;
     }
     $form = array('target' => array('type' => 'multiselect', 'label-message' => 'emailto', 'options' => $usernames, 'validation-callback' => array($this, 'validateTarget')), 'target-reverse' => array('type' => 'check', 'default' => true, 'label-message' => 'emailusers-target-reverse'), 'subject' => array('type' => 'text', 'default' => wfMsg('defemailsubject'), 'label-message' => 'emailsubject'), 'text' => array('type' => 'textarea', 'label-message' => 'emailmessage'), 'ccme' => array('type' => 'check', 'default' => $wgUser->getOption('ccmeonemails'), 'label-message' => 'emailccme'));
     $htmlForm = new HTMLForm($form);
     $htmlForm->setTitle($this->getTitle($par));
     $htmlForm->setSubmitCallback(array($this, 'submit'));
     $this->outputHeader();
     if ($htmlForm->show()) {
         $wgOut->addWikiMsg('emailsenttext');
         $htmlForm->displayForm(false);
     }
 }
 protected function preprocessResults($results)
 {
     $names = array();
     foreach ($results as $result) {
         $names[] = $result->utr_name;
     }
     if (!$names) {
         return;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select(array('user', 'ipblocks'), User::selectFields(), array('user_name' => array_unique($names), 'ipb_deleted IS NULL OR ipb_deleted = 0'), __METHOD__, array(), array('ipblocks' => array('LEFT JOIN', 'user_id = ipb_user')));
     $userArray = UserArray::newFromResult($res);
     $lb = new LinkBatch();
     foreach ($userArray as $user) {
         $this->users[$user->getName()] = $user;
         $lb->addObj($user->getUserPage());
         $lb->addObj($user->getTalkPage());
     }
     $lb->execute();
 }
 function getUsersFromDb()
 {
     $sqlOptions = array();
     $dbr = wfGetDB(DB_SLAVE);
     // SQL WHERE based on filter
     $sqlConds = '';
     if (strlen($this->filtertext) > 0) {
         $sqlConds = $this->mLookupUserField[$this->filterby] . ' ';
         if ($this->filterneg) {
             $sqlConds .= $this->mNegFilterOps[$this->filterop] . ' ';
         } else {
             $sqlConds .= $this->mFilterOps[$this->filterop] . ' ';
         }
         $sqlConds .= $dbr->addQuotes($this->filtertext);
     }
     $result = $dbr->select('user', 'user_id', $sqlConds);
     $estRowCount = $result->numRows();
     //    $estRowCount = $dbr->estimateRowCount('user', '*', $sqlConds);
     // SQL LIMIT based on pagenum/pagesize
     if ($this->pagesize != 'all') {
         $this->pagemax = intval($estRowCount / $this->pagesize) + 1;
         $this->pagenum = min($this->pagenum, $this->pagemax);
         $sqlOptions['OFFSET'] = ($this->pagenum - 1) * $this->pagesize;
         $sqlOptions['LIMIT'] = $this->pagesize;
     } else {
         $this->pagemax = 1;
     }
     $sqlOptions['ORDER BY'] = $this->mLookupUserField[$this->sortby];
     // SQL ORDER BY  based on sortby/sortasc
     if ($this->sortasc == '0') {
         $sqlOptions['ORDER BY'] .= ' DESC';
     }
     $MW_users = UserArray::newFromResult($dbr->select('user', '*', $sqlConds, 'DatabaseBase::select', $sqlOptions));
     return array($MW_users, $estRowCount);
 }
Пример #5
0
 function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false)
 {
     # we use $wgPasswordSender as sender's address
     global $wgEnotifWatchlist;
     global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker;
     global $wgEnotifImpersonal;
     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;
     $enotifusertalkpage = $isUserTalkPage && $wgEnotifUserTalk;
     $enotifwatchlistpage = $wgEnotifWatchlist;
     $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')) {
                 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
             $userCondition = 'wl_user != ' . $editor->getID();
             if ($userTalkId !== false) {
                 // Already sent an email to this person
                 $userCondition .= ' AND wl_user != ' . intval($userTalkId);
             }
             $dbr = wfGetDB(DB_SLAVE);
             list($user) = $dbr->tableNamesN('user');
             $res = $dbr->select(array('watchlist', 'user'), array("{$user}.*"), array('wl_user=user_id', 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), $userCondition, 'wl_notificationtimestamp IS NULL'), __METHOD__);
             $userArray = UserArray::newFromResult($res);
             foreach ($userArray as $watchingUser) {
                 if ($watchingUser->getOption('enotifwatchlistpages') && (!$minorEdit || $watchingUser->getOption('enotifminoredits')) && $watchingUser->isEmailConfirmed()) {
                     $this->compose($watchingUser);
                 }
             }
         }
     }
     global $wgUsersNotifiedOnAllChanges;
     foreach ($wgUsersNotifiedOnAllChanges as $name) {
         $user = User::newFromName($name);
         $this->compose($user);
     }
     $this->sendMails();
     $latestTimestamp = Revision::getTimestampFromId($title, $title->getLatestRevID());
     // Do not update watchlists if something else already did.
     if ($timestamp >= $latestTimestamp && ($wgShowUpdatedMarker || $wgEnotifWatchlist)) {
         # Mark the changed watch-listed page with a timestamp, so that the page is
         # listed with an "updated since your last visit" icon in the watch list. Do
         # not do this to users for their own edits.
         $dbw = wfGetDB(DB_MASTER);
         $dbw->update('watchlist', array('wl_notificationtimestamp' => $dbw->timestamp($timestamp)), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_notificationtimestamp IS NULL', 'wl_user != ' . $editor->getID()), __METHOD__);
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * @return UserArray
  */
 public static function getAdminsToNotify()
 {
     $groups = User::getGroupsWithPermission('confirmaccount-notify');
     if (!count($groups)) {
         return UserArray::newFromResult(new FakeResultWrapper(array()));
     }
     $dbr = wfGetDB(DB_SLAVE);
     return UserArray::newFromResult($dbr->select(array('user'), array('*'), array('EXISTS (' . $dbr->selectSqlText('user_groups', '1', array('ug_user = user_id', 'ug_group' => $groups)) . ')'), __METHOD__, array('LIMIT' => 200)));
 }