public function index() { if ($this->_view == "admin") { $Users = new UserArray(); $Users->load(); $tplData = array("Users" => $Users->getArray()); $this->_viewProcessor->_tplData = $tplData; } $this->_viewProcessor->display(); }
public function tryLogin(Credentials $userCredentials, UserArray $users) { //First check to make sure the user is not already logged in (this is also checked in controller, but I prefer to check in all places to minimize errors) if (!$this->isUserLoggedIn()) { //If input matches any saved user, return true (successful login attempt) and save in session variable as 'logged in' if ($users->getUserByName($userCredentials->getUserName()) != null && password_verify($userCredentials->getUserPassword(), $users->getUserByName($userCredentials->getUserName())->getPassword())) { $_SESSION['LoggedIn'] = $userCredentials->getUserName(); return true; } } //In all other cases, return false return false; }
/** * 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(); }
/** * 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__); }
/** * 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(); }
/** * 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__); }
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); }
public function getAllUserData() { $UserArray = new UserArray(); $UserArray->load(); return $UserArray->getArray(); }
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))); }
/** * 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__); }
/** * 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); }