Merge "Tweaked User::READ_LOCKING to use LOCK IN SHARE MODE"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 16 Jul 2015 22:26:32 +0000 (22:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 16 Jul 2015 22:26:32 +0000 (22:26 +0000)
1  2 
includes/User.php

diff --combined includes/User.php
@@@ -183,50 -183,50 +183,50 @@@ class User implements IDBAccessObject 
         */
        protected static $mAllRights = false;
  
 -      /** @name Cache variables */
 +      /** Cache variables */
        //@{
        public $mId;
 -
 +      /** @var string */
        public $mName;
 -
 +      /** @var string */
        public $mRealName;
 -
        /**
         * @todo Make this actually private
         * @private
 +       * @var Password
         */
        public $mPassword;
 -
        /**
         * @todo Make this actually private
         * @private
 +       * @var Password
         */
        public $mNewpassword;
 -
 +      /** @var string */
        public $mNewpassTime;
 -
 +      /** @var string */
        public $mEmail;
        /** @var string TS_MW timestamp from the DB */
        public $mTouched;
        /** @var string TS_MW timestamp from cache */
        protected $mQuickTouched;
 -
 +      /** @var string */
        protected $mToken;
 -
 +      /** @var string */
        public $mEmailAuthenticated;
 -
 +      /** @var string */
        protected $mEmailToken;
 -
 +      /** @var string */
        protected $mEmailTokenExpires;
 -
 +      /** @var string */
        protected $mRegistration;
 -
 +      /** @var int */
        protected $mEditCount;
 -
 +      /** @var array */
        public $mGroups;
 -
 +      /** @var array */
        protected $mOptionOverrides;
 -
 +      /** @var string */
        protected $mPasswordExpires;
        //@}
  
         * Lazy-initialized variables, invalidated with clearInstanceCache
         */
        protected $mNewtalk;
 -
 +      /** @var string */
        protected $mDatePreference;
 -
 +      /** @var string */
        public $mBlockedby;
 -
 +      /** @var string */
        protected $mHash;
 -
 +      /** @var array */
        public $mRights;
 -
 +      /** @var string */
        protected $mBlockreason;
 -
 +      /** @var array */
        protected $mEffectiveGroups;
 -
 +      /** @var array */
        protected $mImplicitGroups;
 -
 +      /** @var array */
        protected $mFormerGroups;
 -
 +      /** @var bool */
        protected $mBlockedGlobally;
 -
 +      /** @var bool */
        protected $mLocked;
 -
 +      /** @var bool */
        public $mHideName;
 -
 +      /** @var array */
        public $mOptions;
  
        /**
         * able to set their password to this.
         *
         * @param string $password Desired password
 +       * @param string $purpose one of 'login', 'create', 'reset'
         * @return Status
         * @since 1.23
         */
 -      public function checkPasswordValidity( $password ) {
 +      public function checkPasswordValidity( $password, $purpose = 'login' ) {
                global $wgPasswordPolicy;
  
                $upp = new UserPasswordPolicy(
                }
  
                if ( $result === false ) {
 -                      $status->merge( $upp->checkUserPassword( $this, $password ) );
 +                      $status->merge( $upp->checkUserPassword( $this, $password, $purpose ) );
                        return $status;
                } elseif ( $result === true ) {
                        return $status;
                                && $newMessageLinks[0]['wiki'] === wfWikiID()
                                && $newMessageLinks[0]['rev']
                        ) {
 +                              /** @var Revision $newMessageRevision */
                                $newMessageRevision = $newMessageLinks[0]['rev'];
                                $newMessageRevisionId = $newMessageRevision->getId();
                        }
                        $this->clearSharedCache();
                        // User was changed in the meantime or loaded with stale data
                        $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'slave';
 -                      MWExceptionHandler::logException( new MWException(
 +                      throw new MWException(
                                "CAS update failed on user_touched for user ID '{$this->mId}' (read from $from);" .
                                "the version of the user to be saved is older than the current version."
 -                      ) );
 -
 -                      return;
 +                      );
                }
  
                $this->mTouched = $newTouched;
                        : wfGetDB( DB_SLAVE );
  
                $options = ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING )
-                       ? array( 'FOR UPDATE' )
+                       ? array( 'LOCK IN SHARE MODE' )
                        : array();
  
-               $id = $db->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__, $options );
-               if ( $id === false ) {
-                       $id = 0;
-               }
+               $id = $db->selectField( 'user',
+                       'user_id', array( 'user_name' => $s ), __METHOD__, $options );
  
-               return $id;
+               return (int)$id;
        }
  
        /**
         *
         * @param string $subject Message subject
         * @param string $body Message body
 -       * @param string $from Optional From address; if unspecified, default
 +       * @param User|null $from Optional sending user; if unspecified, default
         *   $wgPasswordSender will be used.
         * @param string $replyto Reply-To address
         * @return Status
         */
        public function sendMail( $subject, $body, $from = null, $replyto = null ) {
 -              if ( is_null( $from ) ) {
 -                      global $wgPasswordSender;
 +              global $wgPasswordSender;
 +
 +              if ( $from instanceof User ) {
 +                      $sender = MailAddress::newFromUser( $from );
 +              } else {
                        $sender = new MailAddress( $wgPasswordSender,
                                wfMessage( 'emailsender' )->inContentLanguage()->text() );
 -              } else {
 -                      $sender = MailAddress::newFromUser( $from );
                }
 -
                $to = MailAddress::newFromUser( $this );
 +
                return UserMailer::send( $to, $sender, $subject, $body, $replyto );
        }