Replace $wgUser with RequestContext::getUser in User::getBlockedStatus
[lhc/web/wiklou.git] / includes / user / User.php
index 76691ea..86bb27b 100644 (file)
@@ -1775,7 +1775,7 @@ class User implements IDBAccessObject, UserIdentity {
         *   Check when actually saving should be done against master.
         */
        private function getBlockedStatus( $bFromSlave = true ) {
-               global $wgProxyWhitelist, $wgUser, $wgApplyIpBlocksToXff, $wgSoftBlockRanges;
+               global $wgProxyWhitelist, $wgApplyIpBlocksToXff, $wgSoftBlockRanges;
 
                if ( -1 != $this->mBlockedby ) {
                        return;
@@ -1795,11 +1795,12 @@ class User implements IDBAccessObject, UserIdentity {
                # know which IP address they're actually coming from
                $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() );
+                       $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();
                        }
@@ -1881,9 +1882,9 @@ class User implements IDBAccessObject, UserIdentity {
                }
 
                // Avoid PHP 7.1 warning of passing $this by reference
-               $user = $this;
+               $thisUser = $this;
                // Extensions
-               Hooks::run( 'GetBlockedStatus', [ &$user ] );
+               Hooks::run( 'GetBlockedStatus', [ &$thisUser ] );
        }
 
        /**