]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/User.php
MediaWiki 1.16.5
[autoinstallsdev/mediawiki.git] / includes / User.php
index 51ffe70a5087584ae134808decf9e29bce994faa..fb19ddf2e88f3dca15b0f0f8a72d49cadd99b127 100644 (file)
@@ -897,24 +897,25 @@ class User {
                }
 
                $passwordCorrect = FALSE;
-               $this->mId = $sId;
-               if ( !$this->loadFromId() ) {
-                       # Not a valid ID, loadFromId has switched the object to anon for us
+               $proposedUser = User::newFromId( $sId );
+               if ( !$proposedUser->isLoggedIn() ) {
+                       # Not a valid ID
+                       $this->loadDefaults();
                        return false;
                }
 
                global $wgBlockDisablesLogin;
-               if( $wgBlockDisablesLogin && $this->isBlocked() ) {
+               if( $wgBlockDisablesLogin && $proposedUser->isBlocked() ) {
                        # User blocked and we've disabled blocked user logins
                        $this->loadDefaults();
                        return false;
                }
 
                if ( isset( $_SESSION['wsToken'] ) ) {
-                       $passwordCorrect = $_SESSION['wsToken'] == $this->mToken;
+                       $passwordCorrect = $proposedUser->getToken() === $_SESSION['wsToken'];
                        $from = 'session';
                } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
-                       $passwordCorrect = $this->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
+                       $passwordCorrect = $proposedUser->getToken() === $_COOKIE["{$wgCookiePrefix}Token"];
                        $from = 'cookie';
                } else {
                        # No session or persistent login cookie
@@ -922,7 +923,8 @@ class User {
                        return false;
                }
 
-               if ( ( $sName == $this->mName ) && $passwordCorrect ) {
+               if ( ( $sName === $proposedUser->getName() ) && $passwordCorrect ) {
+                       $this->loadFromUserObject( $proposedUser );
                        $_SESSION['wsToken'] = $this->mToken;
                        wfDebug( "Logged in from $from\n" );
                        return true;
@@ -934,6 +936,18 @@ class User {
                }
        }
 
+       /**
+        * Load the data for this user object from another user object. 
+        */
+       protected function loadFromUserObject( $user ) {
+               $user->load();
+               $user->loadGroups();
+               $user->loadOptions();
+               foreach ( self::$mCacheVars as $var ) {
+                       $this->$var = $user->$var;
+               }
+       }
+
        /**
         * Load user and user_group data from the database.
         * $this::mId must be set, this is how the user is identified.