Merge "Avoid unstubbing $wgUser before the end of Setup.php in User::getBlockedStatus()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 4 Feb 2016 16:42:07 +0000 (16:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Feb 2016 16:42:07 +0000 (16:42 +0000)
includes/user/User.php

index 8e3b2ec..3635f5c 100644 (file)
@@ -1535,10 +1535,16 @@ class User implements IDBAccessObject {
                # We only need to worry about passing the IP address to the Block generator if the
                # user is not immune to autoblocks/hardblocks, and they are the current user so we
                # know which IP address they're actually coming from
-               if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->equals( $wgUser ) ) {
-                       $ip = $this->getRequest()->getIP();
-               } else {
-                       $ip = null;
+               $ip = null;
+               if ( !$this->isAllowed( 'ipblock-exempt' ) ) {
+                       // $wgUser->getName() only works after the end of Setup.php. Until
+                       // then, assume it's a logged-out user.
+                       $globalUserName = $wgUser->isSafeToLoad()
+                               ? $wgUser->getName()
+                               : IP::sanitizeIP( $wgUser->getRequest()->getIP() );
+                       if ( $this->getName() === $globalUserName ) {
+                               $ip = $this->getRequest()->getIP();
+                       }
                }
 
                // User/IP blocking