Example #1
0
 /**
  * @param $wikiPage
  * @param \User $user
  * @param $content
  * @param $summary
  * @param $isMinor
  * @param $isWatch
  * @param $section
  * @param $flags
  * @param \Status $status
  *
  * @return bool
  */
 public function onPageContentSave($wikiPage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $status)
 {
     if ($user && !$user->isEmailConfirmed()) {
         if (!$this->testResponse()) {
             $status->setResult(false);
             $status->error("recaptcha-failed");
             return false;
         }
     }
     return true;
 }
	protected function showEmail( $step ) {
		$header = new HtmlTag( 'h2' );
		$step_message = 'translate-fs-email-title';
		$header->style( 'opacity', 0.4 )->content( wfMsg( $step_message ) );

		if ( $step && ( $step !== 'translate-fs-target-title' && $step !== 'translate-fs-permissions-title' ) ) {
			$this->out->addHtml( $header );
			return $step;
		}

		if ( $this->user->isEmailConfirmed() ) {
			$header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
			$this->out->addHtml( $header );
			return $step; // Start translating step
		}

		$this->out->addHtml( $header->style( 'opacity', false ) );
		$this->out->addWikiMsg( 'translate-fs-email-text' );

		return $step_message;
	}
Example #3
0
 /**
  * Check that the user isn't blocked from editing.
  *
  * @param string $action The action to check
  * @param User $user User to check
  * @param array $errors List of current errors
  * @param string $rigor Same format as Title::getUserPermissionsErrors()
  * @param bool $short Short circuit on first error
  *
  * @return array List of errors
  */
 private function checkUserBlock($action, $user, $errors, $rigor, $short)
 {
     // Account creation blocks handled at userlogin.
     // Unblocking handled in SpecialUnblock
     if ($rigor === 'quick' || in_array($action, array('createaccount', 'unblock'))) {
         return $errors;
     }
     global $wgEmailConfirmToEdit;
     if ($wgEmailConfirmToEdit && !$user->isEmailConfirmed()) {
         $errors[] = array('confirmedittext');
     }
     $useSlave = $rigor !== 'secure';
     if (($action == 'edit' || $action == 'create') && !$user->isBlockedFrom($this, $useSlave)) {
         // Don't block the user from editing their own talk page unless they've been
         // explicitly blocked from that too.
     } elseif ($user->isBlocked() && $user->getBlock()->prevents($action) !== false) {
         // @todo FIXME: Pass the relevant context into this function.
         $errors[] = $user->getBlock()->getPermissionsError(RequestContext::getMain());
     }
     return $errors;
 }
Example #4
0
 /**
  * Check whether a user is allowed to send email
  *
  * @param User $user
  * @param string $editToken Edit token
  * @param Config $config optional for backwards compatibility
  * @return string|null Null on success or string on error
  */
 public static function getPermissionsError($user, $editToken, Config $config = null)
 {
     if ($config === null) {
         wfDebug(__METHOD__ . ' called without a Config instance passed to it');
         $config = ConfigFactory::getDefaultInstance()->makeConfig('main');
     }
     if (!$config->get('EnableEmail') || !$config->get('EnableUserEmail')) {
         return 'usermaildisabled';
     }
     if (!$user->isAllowed('sendemail')) {
         return 'badaccess';
     }
     if (!$user->isEmailConfirmed()) {
         return 'mailnologin';
     }
     if ($user->isBlockedFromEmailuser()) {
         wfDebug("User is blocked from sending e-mail.\n");
         return "blockedemailuser";
     }
     if ($user->pingLimiter('emailuser')) {
         wfDebug("Ping limiter triggered.\n");
         return 'actionthrottledtext';
     }
     $hookErr = false;
     Hooks::run('UserCanSendEmail', array(&$user, &$hookErr));
     Hooks::run('EmailUserPermissionsErrors', array($user, $editToken, &$hookErr));
     if ($hookErr) {
         return $hookErr;
     }
     return null;
 }
Example #5
0
 /**
  * notify user on user right change
  *
  * @author      Piotr Molski <*****@*****.**>
  * @version     1.0.0
  * @param       User    $user object
  * @param       Array   $addgroup - selected groups for user
  * @param       Array   $removegroup - disabled groups for user
  */
 public static function notifyUserOnRightsChange(&$user, $addgroup, $removegroup)
 {
     global $wgUsersNotifiedOnAllChanges, $wgUsersNotifiedOfRightsChanges, $wgUser;
     # rt#66961: rights change email sent to !emailconfirmed users
     if (!$user->isEmailConfirmed()) {
         #if your not confirmed, no email for you, so dont bother adding to On* lists
         return true;
         #i said no, so stop here
     }
     # FB: 1085 Don't send notif to myself on user rights change
     if ($user->getID() == $wgUser->getID()) {
         return true;
     }
     // Using wgUsersNotifiedOnAllChanges is a hack to get the UserMailer to notify these users.  The use
     // of wgUsersNotifiedOfRightsChanges is to prevent the same user from being notified multiple times if
     // multiple actions occur on the same page.
     if (!isset($wgUsersNotifiedOfRightsChanges)) {
         $wgUsersNotifiedOfRightsChanges = array();
     }
     $wgUsersNotifiedOnAllChanges = array_diff($wgUsersNotifiedOnAllChanges, $wgUsersNotifiedOfRightsChanges);
     $userName = $user->getName();
     if (!in_array($userName, $wgUsersNotifiedOnAllChanges)) {
         $wgUsersNotifiedOnAllChanges[] = $userName;
         // We only add them to this if THIS is the reason they're in wgUsersNotifiedOnAllChanges so that we don't accidentally over-remove.
         $wgUsersNotifiedOfRightsChanges[] = $userName;
     }
     return true;
 }
Example #6
0
 /**
  * @todo document
  * @param $title Title object
  * @param $timestamp
  * @param $summary
  * @param $minorEdit
  * @param $oldid (default: false)
  */
 function notifyOnPageChange(&$title, $timestamp, $summary, $minorEdit, $oldid = false)
 {
     # we use $wgEmergencyContact as sender's address
     global $wgUser, $wgEnotifWatchlist;
     global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker;
     $fname = 'UserMailer::notifyOnPageChange';
     wfProfileIn($fname);
     # 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;
     if (!$minorEdit || $wgEnotifMinorEdits) {
         if ($wgEnotifWatchlist) {
             // Send updates to watchers other than the current editor
             $userCondition = 'wl_user <> ' . intval($wgUser->getId());
         } elseif ($wgEnotifUserTalk && $title->getNamespace() == NS_USER_TALK) {
             $targetUser = User::newFromName($title->getText());
             if (is_null($targetUser)) {
                 wfDebug("{$fname}: user-talk-only mode; no such user\n");
                 $userCondition = false;
             } elseif ($targetUser->getId() == $wgUser->getId()) {
                 wfDebug("{$fname}: user-talk-only mode; editor is target user\n");
                 $userCondition = false;
             } else {
                 // Don't notify anyone other than the owner of the talk page
                 $userCondition = 'wl_user = '******'watchlist', array('wl_user'), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), $userCondition, 'wl_notificationtimestamp IS NULL'), $fname);
             # if anyone is watching ... set up the email message text which is
             # common for all receipients ...
             if ($dbr->numRows($res) > 0) {
                 $this->title =& $title;
                 $this->timestamp = $timestamp;
                 $this->summary = $summary;
                 $this->minorEdit = $minorEdit;
                 $this->oldid = $oldid;
                 $this->composeCommonMailtext();
                 $watchingUser = new User();
                 # ... now do for all watching users ... if the options fit
                 for ($i = 1; $i <= $dbr->numRows($res); $i++) {
                     $wuser = $dbr->fetchObject($res);
                     $watchingUser->setID($wuser->wl_user);
                     if ($enotifwatchlistpage && $watchingUser->getOption('enotifwatchlistpages') || $enotifusertalkpage && $watchingUser->getOption('enotifusertalkpages') && $title->equals($watchingUser->getTalkPage()) && (!$minorEdit || $wgEnotifMinorEdits && $watchingUser->getOption('enotifminoredits')) && $watchingUser->isEmailConfirmed()) {
                         # ... adjust remaining text and page edit time placeholders
                         # which needs to be personalized for each user
                         $this->composeAndSendPersonalisedMail($watchingUser);
                     }
                     # if the watching user has an email address in the preferences
                 }
             }
         }
         # if anyone is watching
     }
     # if $wgEnotifWatchlist = true
     if ($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, ...
         $dbw =& wfGetDB(DB_MASTER);
         $success = $dbw->update('watchlist', array('wl_notificationtimestamp' => $dbw->timestamp($timestamp)), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace()), 'UserMailer::NotifyOnChange');
         # FIXME what do we do on failure ?
     }
     wfProfileOut($fname);
 }
 /**
  * Check whether a user is allowed to send email
  *
  * @param User $user
  * @param string $editToken Edit token
  * @return string|null Null on success or string on error
  */
 public static function getPermissionsError($user, $editToken)
 {
     global $wgEnableEmail, $wgEnableUserEmail;
     if (!$wgEnableEmail || !$wgEnableUserEmail) {
         return 'usermaildisabled';
     }
     if (!$user->isAllowed('sendemail')) {
         return 'badaccess';
     }
     if (!$user->isEmailConfirmed()) {
         return 'mailnologin';
     }
     if ($user->isBlockedFromEmailuser()) {
         wfDebug("User is blocked from sending e-mail.\n");
         return "blockedemailuser";
     }
     if ($user->pingLimiter('emailuser')) {
         wfDebug("Ping limiter triggered.\n");
         return 'actionthrottledtext';
     }
     $hookErr = false;
     wfRunHooks('UserCanSendEmail', array(&$user, &$hookErr));
     wfRunHooks('EmailUserPermissionsErrors', array($user, $editToken, &$hookErr));
     if ($hookErr) {
         return $hookErr;
     }
     return null;
 }
 /**
  * @todo document
  * @param $currentPage
  * @param $currentNs
  * @param $timestamp
  * @param $currentSummary
  * @param $currentMinorEdit
  * @param $oldid (default: false)
  */
 function notifyOnPageChange(&$title, $timestamp, $summary, $minorEdit, $oldid = false)
 {
     # we use $wgEmergencyContact as sender's address
     global $wgUser, $wgLang, $wgEmergencyContact;
     global $wgEnotifWatchlist, $wgEnotifMinorEdits;
     global $wgEnotifUserTalk;
     global $wgEnotifRevealEditorAddress;
     global $wgEnotifFromEditor;
     global $wgEmailAuthentication;
     global $wgShowUpdatedMarker;
     $fname = 'UserMailer::notifyOnPageChange';
     wfProfileIn($fname);
     # 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 = !$isUserTalkPage && $wgEnotifWatchlist;
     if (($enotifusertalkpage || $enotifwatchlistpage) && (!$minorEdit || $wgEnotifMinorEdits)) {
         $dbr =& wfGetDB(DB_MASTER);
         extract($dbr->tableNames('watchlist'));
         $res = $dbr->select('watchlist', array('wl_user'), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user <> ' . $wgUser->getID(), 'wl_notificationtimestamp <= 1'), $fname);
         # if anyone is watching ... set up the email message text which is
         # common for all receipients ...
         if ($dbr->numRows($res) > 0) {
             $this->user &= $wgUser;
             $this->title =& $title;
             $this->timestamp = $timestamp;
             $this->summary = $summary;
             $this->minorEdit = $minorEdit;
             $this->oldid = $oldid;
             $this->composeCommonMailtext();
             $watchingUser = new User();
             # ... now do for all watching users ... if the options fit
             for ($i = 1; $i <= $dbr->numRows($res); $i++) {
                 $wuser = $dbr->fetchObject($res);
                 $watchingUser->setID($wuser->wl_user);
                 if ($enotifwatchlistpage && $watchingUser->getOption('enotifwatchlistpages') || $enotifusertalkpage && $watchingUser->getOption('enotifusertalkpages') && (!$minorEdit || $wgEnotifMinorEdits && $watchingUser->getOption('enotifminoredits')) && $watchingUser->isEmailConfirmed()) {
                     # ... adjust remaining text and page edit time placeholders
                     # which needs to be personalized for each user
                     $this->composeAndSendPersonalisedMail($watchingUser);
                 }
                 # if the watching user has an email address in the preferences
             }
         }
         # if anyone is watching
     }
     # if $wgEnotifWatchlist = true
     if ($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, ...
         $dbw =& wfGetDB(DB_MASTER);
         $success = $dbw->update('watchlist', array('wl_notificationtimestamp' => $timestamp), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace()), 'UserMailer::NotifyOnChange');
     }
 }
Example #9
0
 private function onAuthenticateUserDataResetPass(User $u)
 {
     // The e-mailed temporary password should not be used for actu-
     // al logins; that's a very sloppy habit, and insecure if an
     // attacker has a few seconds to click "search" on someone's o-
     // pen mail reader.
     //
     // Allow it to be used only to reset the password a single time
     // to a new value, which won't be in the user's e-mail ar-
     // chives.
     //
     // For backwards compatibility, we'll still recognize it at the
     // login form to minimize surprises for people who have been
     // logging in with a temporary password for some time.
     //
     // As a side-effect, we can authenticate the user's e-mail ad-
     // dress if it's not already done, since the temporary password
     // was sent via e-mail.
     if (!$u->isEmailConfirmed()) {
         $u->confirmEmail();
         $u->saveSettings();
     }
 }
Example #10
0
 /**
  * Returns the survey user types the provided user has.
  * 
  * @since 0.1
  * 
  * @param User $user
  * 
  * @return array of Survey::$USER_
  */
 public static function getTypesForUser(User $user)
 {
     $userTypes = array(Survey::$USER_ALL);
     $userTypes[] = $user->isLoggedIn() ? Survey::$USER_LOGGEDIN : Survey::$USER_ANON;
     if ($user->isEmailConfirmed()) {
         $userTypes[] = Survey::$USER_CONFIRMED;
     }
     if ($user->getEditCount() > 0) {
         $userTypes[] = Survey::$USER_EDITOR;
     }
     return $userTypes;
 }
Example #11
0
 /**
  * Can the user take a subscription? (not renewal or a plan change, but a simple subscription)
  * Can be a first subscription, or a new subscription with an unactive ended one
  * @param User $user
  * @return boolean/string true = can subscribe , string = reason (i18n message key) why cannot subscribe:
  * <ul>
  * <li>wp-subscribe-loggedout</li>User need to be logged in to subscribe
  * <li>wp-subscribe-email</li>User has not yet confirmed her email address
  * <li>wp-subscribe-already</li>User has already an active or a "payment pending" subscription
  * </ul>
  */
 public static function canSubscribe($user)
 {
     if (!$user instanceof User) {
         throw new MWException('Invalid user argument.');
     }
     if (!$user->isLoggedIn()) {
         return 'wp-subscribe-loggedout';
     }
     if (!$user->isEmailConfirmed()) {
         return 'wp-subscribe-email';
     }
     $dbr = wfGetDB(DB_MASTER);
     $now = $dbr->addQuotes(self::now());
     $conds = $dbr->makeList(array("wps_buyer_user_id" => $user->getId(), $dbr->makeList(array("wps_active" => 1, $dbr->makeList(array("wps_active" => 0, "wps_tmr_status != 'KO'", $dbr->makeList(array("wps_start_date IS NULL", "wps_start_date >= {$now}"), LIST_OR)), LIST_AND)), LIST_OR)), LIST_AND);
     $results = $dbr->select('wp_subscription', '*', $conds, __METHOD__);
     if ($dbr->numRows($results) != 0) {
         return 'wp-subscribe-already';
     }
     return true;
 }
 /**
  * @param User $user
  * @throws Exception
  */
 private function checkIfEmailConfirmed(\User $user)
 {
     if (!$user->isEmailConfirmed()) {
         throw new Exception('Email is not confirmed.');
     }
 }