Merge "Use READ_NORMAL for User cache regenerations"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 9 Jun 2016 19:45:04 +0000 (19:45 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 9 Jun 2016 19:45:04 +0000 (19:45 +0000)
1  2 
includes/user/User.php

diff --combined includes/user/User.php
@@@ -477,7 -477,7 +477,7 @@@ class User implements IDBAccessObject 
                                $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
                                wfDebug( "User: cache miss for user {$this->mId}\n" );
  
-                               $this->loadFromDatabase();
+                               $this->loadFromDatabase( self::READ_NORMAL );
                                $this->loadGroups();
                                $this->loadOptions();
  
                                throw new LogicException( 'Cannot set a password for a user that is not in the database.' );
                        }
  
 -                      $data = [
 +                      $status = $this->changeAuthenticationData( [
                                'username' => $this->getName(),
                                'password' => $str,
                                'retype' => $str,
 -                      ];
 -                      $reqs = $manager->getAuthenticationRequests( AuthManager::ACTION_CHANGE, $this );
 -                      $reqs = AuthenticationRequest::loadRequestsFromSubmission( $reqs, $data );
 -                      foreach ( $reqs as $req ) {
 -                              $status = $manager->allowsAuthenticationDataChange( $req );
 -                              if ( !$status->isGood() ) {
 -                                      \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )
 -                                              ->info( __METHOD__ . ': Password change rejected: ' . $status->getWikiText() );
 -                                      return false;
 -                              }
 -                      }
 -                      foreach ( $reqs as $req ) {
 -                              $manager->changeAuthenticationData( $req );
 +                      ] );
 +                      if ( !$status->isGood() ) {
 +                              \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )
 +                                      ->info( __METHOD__ . ': Password change rejected: '
 +                                              . $status->getWikiText( null, null, 'en' ) );
 +                              return false;
                        }
  
                        $this->setOption( 'watchlisttoken', false );
                return true;
        }
  
 +      /**
 +       * Changes credentials of the user.
 +       *
 +       * This is a convenience wrapper around AuthManager::changeAuthenticationData.
 +       * Note that this can return a status that isOK() but not isGood() on certain types of failures,
 +       * e.g. when no provider handled the change.
 +       *
 +       * @param array $data A set of authentication data in fieldname => value format. This is the
 +       *   same data you would pass the changeauthenticationdata API - 'username', 'password' etc.
 +       * @return Status
 +       * @since 1.27
 +       */
 +      public function changeAuthenticationData( array $data ) {
 +              global $wgDisableAuthManager;
 +              if ( $wgDisableAuthManager ) {
 +                      throw new LogicException( __METHOD__ . ' cannot be called when $wgDisableAuthManager '
 +                              . 'is true' );
 +              }
 +
 +              $manager = AuthManager::singleton();
 +              $reqs = $manager->getAuthenticationRequests( AuthManager::ACTION_CHANGE, $this );
 +              $reqs = AuthenticationRequest::loadRequestsFromSubmission( $reqs, $data );
 +
 +              $status = Status::newGood( 'ignored' );
 +              foreach ( $reqs as $req ) {
 +                      $status->merge( $manager->allowsAuthenticationDataChange( $req ), true );
 +              }
 +              if ( $status->getValue() === 'ignored' ) {
 +                      $status->warning( 'authenticationdatachange-ignored' );
 +              }
 +
 +              if ( $status->isGood() ) {
 +                      foreach ( $reqs as $req ) {
 +                              $manager->changeAuthenticationData( $req );
 +                      }
 +              }
 +              return $status;
 +      }
 +
        /**
         * Get the user's current token.
         * @param bool $forceCreation Force the generation of a new token if the