Merge "Convert article delete to use OOUI"
[lhc/web/wiklou.git] / includes / auth / AuthManager.php
index 89a22f8..c3f798f 100644 (file)
@@ -24,6 +24,7 @@
 namespace MediaWiki\Auth;
 
 use Config;
+use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerInterface;
 use Status;
@@ -146,7 +147,7 @@ class AuthManager implements LoggerAwareInterface {
                if ( self::$instance === null ) {
                        self::$instance = new self(
                                \RequestContext::getMain()->getRequest(),
-                               \ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
+                               MediaWikiServices::getInstance()->getMainConfig()
                        );
                }
                return self::$instance;
@@ -606,6 +607,7 @@ class AuthManager implements LoggerAwareInterface {
 
                        $user = User::newFromName( $res->username, 'usable' );
                        if ( !$user ) {
+                               $provider = $this->getAuthenticationProvider( $state['primary'] );
                                throw new \DomainException(
                                        get_class( $provider ) . " returned an invalid username: {$res->username}"
                                );
@@ -681,6 +683,7 @@ class AuthManager implements LoggerAwareInterface {
                        $this->logger->info( 'Login for {user} succeeded', [
                                'user' => $user->getName(),
                        ] );
+                       /** @var RememberMeAuthenticationRequest $req */
                        $req = AuthenticationRequest::getRequestByClass(
                                $beginReqs, RememberMeAuthenticationRequest::class
                        );
@@ -1398,7 +1401,7 @@ class AuthManager implements LoggerAwareInterface {
                                        'creator' => $creator->getName(),
                                ] );
                                $status = $user->addToDatabase();
-                               if ( !$status->isOk() ) {
+                               if ( !$status->isOK() ) {
                                        // @codeCoverageIgnoreStart
                                        $ret = AuthenticationResponse::newFail( $status->getMessage() );
                                        $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
@@ -1429,6 +1432,7 @@ class AuthManager implements LoggerAwareInterface {
                                        );
                                        $logEntry->setPerformer( $isAnon ? $user : $creator );
                                        $logEntry->setTarget( $user->getUserPage() );
+                                       /** @var CreationReasonAuthenticationRequest $req */
                                        $req = AuthenticationRequest::getRequestByClass(
                                                $state['reqs'], CreationReasonAuthenticationRequest::class
                                        );
@@ -1601,7 +1605,7 @@ class AuthManager implements LoggerAwareInterface {
                        $this->logger->debug( __METHOD__ . ': name "{username}" is not creatable', [
                                'username' => $username,
                        ] );
-                       $session->set( 'AuthManager::AutoCreateBlacklist', 'noname', 600 );
+                       $session->set( 'AuthManager::AutoCreateBlacklist', 'noname' );
                        $user->setId( 0 );
                        $user->loadFromId();
                        return Status::newFatal( 'noname' );
@@ -1614,7 +1618,7 @@ class AuthManager implements LoggerAwareInterface {
                                'username' => $username,
                                'ip' => $anon->getName(),
                        ] );
-                       $session->set( 'AuthManager::AutoCreateBlacklist', 'authmanager-autocreate-noperm', 600 );
+                       $session->set( 'AuthManager::AutoCreateBlacklist', 'authmanager-autocreate-noperm' );
                        $session->persist();
                        $user->setId( 0 );
                        $user->loadFromId();
@@ -1649,14 +1653,14 @@ class AuthManager implements LoggerAwareInterface {
                                        'username' => $username,
                                        'reason' => $ret->getWikiText( null, null, 'en' ),
                                ] );
-                               $session->set( 'AuthManager::AutoCreateBlacklist', $status, 600 );
+                               $session->set( 'AuthManager::AutoCreateBlacklist', $status );
                                $user->setId( 0 );
                                $user->loadFromId();
                                return $ret;
                        }
                }
 
-               $backoffKey = wfMemcKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
+               $backoffKey = $cache->makeKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
                if ( $cache->get( $backoffKey ) ) {
                        $this->logger->debug( __METHOD__ . ': {username} denied by prior creation attempt failures', [
                                'username' => $username,
@@ -1675,10 +1679,10 @@ class AuthManager implements LoggerAwareInterface {
 
                // Ignore warnings about master connections/writes...hard to avoid here
                $trxProfiler = \Profiler::instance()->getTransactionProfiler();
-               $trxProfiler->setSilenced( true );
+               $old = $trxProfiler->setSilenced( true );
                try {
                        $status = $user->addToDatabase();
-                       if ( !$status->isOk() ) {
+                       if ( !$status->isOK() ) {
                                // Double-check for a race condition (T70012). We make use of the fact that when
                                // addToDatabase fails due to the user already existing, the user object gets loaded.
                                if ( $user->getId() ) {
@@ -1691,9 +1695,9 @@ class AuthManager implements LoggerAwareInterface {
                                        $status = Status::newGood();
                                        $status->warning( 'userexists' );
                                } else {
-                                       $this->logger->error( __METHOD__ . ': {username} failed with message {message}', [
+                                       $this->logger->error( __METHOD__ . ': {username} failed with message {msg}', [
                                                'username' => $username,
-                                               'message' => $status->getWikiText( null, null, 'en' )
+                                               'msg' => $status->getWikiText( null, null, 'en' )
                                        ] );
                                        $user->setId( 0 );
                                        $user->loadFromId();
@@ -1701,7 +1705,7 @@ class AuthManager implements LoggerAwareInterface {
                                return $status;
                        }
                } catch ( \Exception $ex ) {
-                       $trxProfiler->setSilenced( false );
+                       $trxProfiler->setSilenced( $old );
                        $this->logger->error( __METHOD__ . ': {username} failed with exception {exception}', [
                                'username' => $username,
                                'exception' => $ex,
@@ -1740,7 +1744,7 @@ class AuthManager implements LoggerAwareInterface {
                        $logEntry->insert();
                }
 
-               $trxProfiler->setSilenced( false );
+               $trxProfiler->setSilenced( $old );
 
                if ( $login ) {
                        $this->setSessionDataForUser( $user );
@@ -2379,7 +2383,7 @@ class AuthManager implements LoggerAwareInterface {
                $session->set( 'AuthManager:lastAuthTimestamp', time() );
                $session->persist();
 
-               \ScopedCallback::consume( $delay );
+               \Wikimedia\ScopedCallback::consume( $delay );
 
                \Hooks::run( 'UserLoggedIn', [ $user ] );
        }