Include IP address in "Login for $1 succeeded" log entry
[lhc/web/wiklou.git] / includes / auth / AuthManager.php
index 9407c42..611a8cd 100644 (file)
@@ -31,6 +31,7 @@ use Status;
 use StatusValue;
 use User;
 use WebRequest;
+use Wikimedia\ObjectFactory;
 
 /**
  * This serves as the entry point to the authentication system.
@@ -680,8 +681,9 @@ class AuthManager implements LoggerAwareInterface {
                        // Step 4: Authentication complete! Set the user in the session and
                        // clean up.
 
-                       $this->logger->info( 'Login for {user} succeeded', [
+                       $this->logger->info( 'Login for {user} succeeded from {clientip}', [
                                'user' => $user->getName(),
+                               'clientip' => $this->request->getIP(),
                        ] );
                        /** @var RememberMeAuthenticationRequest $req */
                        $req = AuthenticationRequest::getRequestByClass(
@@ -1415,7 +1417,7 @@ class AuthManager implements LoggerAwareInterface {
                                $state['userid'] = $user->getId();
 
                                // Update user count
-                               \DeferredUpdates::addUpdate( new \SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
+                               \DeferredUpdates::addUpdate( \SiteStatsUpdate::factory( [ 'users' => 1 ] ) );
 
                                // Watch user's userpage and talk page
                                $user->addWatch( $user->getUserPage(), User::IGNORE_USER_RIGHTS );
@@ -1551,7 +1553,10 @@ class AuthManager implements LoggerAwareInterface {
                // Fetch the user ID from the master, so that we don't try to create the user
                // when they already exist, due to replication lag
                // @codeCoverageIgnoreStart
-               if ( !$localId && wfGetLB()->getReaderIndex() != 0 ) {
+               if (
+                       !$localId &&
+                       MediaWikiServices::getInstance()->getDBLoadBalancer()->getReaderIndex() != 0
+               ) {
                        $localId = User::idFromName( $username, User::READ_LATEST );
                        $flags = User::READ_LATEST;
                }
@@ -1726,7 +1731,7 @@ class AuthManager implements LoggerAwareInterface {
                $user->saveSettings();
 
                // Update user count
-               \DeferredUpdates::addUpdate( new \SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
+               \DeferredUpdates::addUpdate( \SiteStatsUpdate::factory( [ 'users' => 1 ] ) );
                // Watch user's userpage and talk page
                \DeferredUpdates::addCallableUpdate( function () use ( $user ) {
                        $user->addWatch( $user->getUserPage(), User::IGNORE_USER_RIGHTS );
@@ -2289,7 +2294,7 @@ class AuthManager implements LoggerAwareInterface {
 
                $ret = [];
                foreach ( $specs as $spec ) {
-                       $provider = \ObjectFactory::getObjectFromSpec( $spec );
+                       $provider = ObjectFactory::getObjectFromSpec( $spec );
                        if ( !$provider instanceof $class ) {
                                throw new \RuntimeException(
                                        "Expected instance of $class, got " . get_class( $provider )