Rearrange code in User::getBlockedStatus to avoid isAllowed calls
authorGergő Tisza <tgr.huwiki@gmail.com>
Thu, 21 Mar 2019 16:00:49 +0000 (09:00 -0700)
committerGergő Tisza <tgr.huwiki@gmail.com>
Thu, 21 Mar 2019 16:00:49 +0000 (09:00 -0700)
User::isAllowed() triggers session loading, which results in a loop
if it is called during session loading. Session providers need to
check block status when $wgBlockDisablesLogin is enabled, so try to
avoid isAllowed calls in that situation.

Bug: T218608
Change-Id: Iab24923c613d6aeed4b574f587fc4cee8f33077c

includes/user/User.php

index 786f288..fe15034 100644 (file)
@@ -1844,16 +1844,14 @@ class User implements IDBAccessObject, UserIdentity {
                # user is not immune to autoblocks/hardblocks, and they are the current user so we
                # know which IP address they're actually coming from
                $ip = null;
-               if ( !$this->isAllowed( 'ipblock-exempt' ) ) {
-                       $sessionUser = RequestContext::getMain()->getUser();
-                       // the session user is set up towards the end of Setup.php. Until then,
-                       // assume it's a logged-out user.
-                       $globalUserName = $sessionUser->isSafeToLoad()
-                               ? $sessionUser->getName()
-                               : IP::sanitizeIP( $sessionUser->getRequest()->getIP() );
-                       if ( $this->getName() === $globalUserName ) {
-                               $ip = $this->getRequest()->getIP();
-                       }
+               $sessionUser = RequestContext::getMain()->getUser();
+               // the session user is set up towards the end of Setup.php. Until then,
+               // assume it's a logged-out user.
+               $globalUserName = $sessionUser->isSafeToLoad()
+                       ? $sessionUser->getName()
+                       : IP::sanitizeIP( $sessionUser->getRequest()->getIP() );
+               if ( $this->getName() === $globalUserName && !$this->isAllowed( 'ipblock-exempt' ) ) {
+                       $ip = $this->getRequest()->getIP();
                }
 
                // User/IP blocking