Merge "TableDiffFormatter: Don't repeatedly call array_shift()"
[lhc/web/wiklou.git] / includes / session / SessionManager.php
index 0a304a9..a364045 100644 (file)
@@ -23,6 +23,7 @@
 
 namespace MediaWiki\Session;
 
+use MWException;
 use Psr\Log\LoggerInterface;
 use BagOStuff;
 use CachedBagOStuff;
@@ -197,13 +198,17 @@ final class SessionManager implements SessionManagerInterface {
                }
 
                $session = null;
+               $info = new SessionInfo( SessionInfo::MIN_PRIORITY, [ 'id' => $id, 'idIsSafe' => true ] );
 
-               // Test this here to provide a better log message for the common case
-               // of "no such ID"
+               // If we already have the backend loaded, use it directly
+               if ( isset( $this->allSessionBackends[$id] ) ) {
+                       return $this->getSessionFromInfo( $info, $request );
+               }
+
+               // Test if the session is in storage, and if so try to load it.
                $key = wfMemcKey( 'MWSession', $id );
                if ( is_array( $this->store->get( $key ) ) ) {
-                       $create = false;
-                       $info = new SessionInfo( SessionInfo::MIN_PRIORITY, [ 'id' => $id, 'idIsSafe' => true ] );
+                       $create = false; // If loading fails, don't bother creating because it probably will fail too.
                        if ( $this->loadSessionInfoFromStore( $info, $request ) ) {
                                $session = $this->getSessionFromInfo( $info, $request );
                        }
@@ -494,10 +499,12 @@ final class SessionManager implements SessionManagerInterface {
                                                        'username' => $userName,
                                                ] );
                                } else {
-                                       $logger->error( __METHOD__ . ': failed with message ' . $status->getWikiText(),
+                                       $logger->error(
+                                               __METHOD__ . ': failed with message ' . $status->getWikiText( false, false, 'en' ),
                                                [
                                                        'username' => $userName,
-                                               ] );
+                                               ]
+                                       );
                                }
                                $user->setId( $id );
                                $user->loadFromId( User::READ_LATEST );
@@ -548,7 +555,7 @@ final class SessionManager implements SessionManagerInterface {
         * The intention is that the named account will never again be usable for
         * normal login (i.e. there is no way to undo the prevention of access).
         *
-        * @private For use from \\User::newSystemUser only
+        * @private For use from \User::newSystemUser only
         * @param string $username
         */
        public function preventSessionsForUser( $username ) {
@@ -619,7 +626,7 @@ final class SessionManager implements SessionManagerInterface {
                        }
                        // @codeCoverageIgnoreEnd
                        foreach ( $this->allSessionBackends as $backend ) {
-                               $backend->save( true );
+                               $backend->shutdown();
                        }
                }
        }
@@ -1022,7 +1029,7 @@ final class SessionManager implements SessionManagerInterface {
 
        /**
         * Deregister a SessionBackend
-        * @private For use from \\MediaWiki\\Session\\SessionBackend only
+        * @private For use from \MediaWiki\Session\SessionBackend only
         * @param SessionBackend $backend
         */
        public function deregisterSessionBackend( SessionBackend $backend ) {
@@ -1040,7 +1047,7 @@ final class SessionManager implements SessionManagerInterface {
 
        /**
         * Change a SessionBackend's ID
-        * @private For use from \\MediaWiki\\Session\\SessionBackend only
+        * @private For use from \MediaWiki\Session\SessionBackend only
         * @param SessionBackend $backend
         */
        public function changeBackendId( SessionBackend $backend ) {