Properly check whether a user exists
authorKunal Mehta <legoktm@gmail.com>
Mon, 14 Jul 2014 05:03:00 +0000 (22:03 -0700)
committerKunal Mehta <legoktm@gmail.com>
Mon, 14 Jul 2014 05:03:00 +0000 (22:03 -0700)
User::newFromId() will never return false. We have to actually
load from the database to see whether the user still exists.

Change-Id: Id9329635717e6a4f1f34d0b2b665bb790685d2fa

includes/context/RequestContext.php

index cd18404..efdc6db 100644 (file)
@@ -471,7 +471,8 @@ class RequestContext implements IContextSource {
 
                if ( $params['userId'] ) { // logged-in user
                        $user = User::newFromId( $params['userId'] );
-                       if ( !$user ) {
+                       $user->load();
+                       if ( !$user->getId() ) {
                                throw new MWException( "No user with ID '{$params['userId']}'." );
                        }
                } elseif ( !IP::isValid( $params['ip'] ) ) {