From e663f9bce630dbe4d9c1a0767c751c1c92c91551 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 19 Jun 2011 12:57:31 +0000 Subject: [PATCH] Moved wfIsLocallyBlockedProxy() to User::isLocallyBlockedProxy() to put it near other proxy checks. No other call to that function in core or extension. Also added a check to not execute a part of User::getBlockedStatus() if $ip is null. --- includes/ProxyTools.php | 32 -------------------------------- includes/User.php | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index 76b92bffd7..c7c1d5ae17 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -179,35 +179,3 @@ function wfProxyCheck() { $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry ); } } - -/** - * Check if an IP address is in the local proxy list - * @return bool - */ -function wfIsLocallyBlockedProxy( $ip ) { - global $wgProxyList; - - if ( !$wgProxyList ) { - return false; - } - wfProfileIn( __METHOD__ ); - - if ( !is_array( $wgProxyList ) ) { - # Load from the specified file - $wgProxyList = array_map( 'trim', file( $wgProxyList ) ); - } - - if ( !is_array( $wgProxyList ) ) { - $ret = false; - } elseif ( array_search( $ip, $wgProxyList ) !== false ) { - $ret = true; - } elseif ( array_key_exists( $ip, $wgProxyList ) ) { - # Old-style flipped proxy list - $ret = true; - } else { - $ret = false; - } - wfProfileOut( __METHOD__ ); - return $ret; -} - diff --git a/includes/User.php b/includes/User.php index 80c2962138..23938d614a 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1220,9 +1220,9 @@ class User { } # Proxy blocking - if ( !$this->isAllowed( 'proxyunbannable' ) && !in_array( $ip, $wgProxyWhitelist ) ) { + if ( $ip !== null && !$this->isAllowed( 'proxyunbannable' ) && !in_array( $ip, $wgProxyWhitelist ) ) { # Local list - if ( wfIsLocallyBlockedProxy( $ip ) ) { + if ( self::isLocallyBlockedProxy( $ip ) ) { $this->mBlockedby = wfMsg( 'proxyblocker' ); $this->mBlockreason = wfMsg( 'proxyblockreason' ); } @@ -1300,6 +1300,37 @@ class User { return $found; } + /** + * Check if an IP address is in the local proxy list + * @return bool + */ + public static function isLocallyBlockedProxy( $ip ) { + global $wgProxyList; + + if ( !$wgProxyList ) { + return false; + } + wfProfileIn( __METHOD__ ); + + if ( !is_array( $wgProxyList ) ) { + # Load from the specified file + $wgProxyList = array_map( 'trim', file( $wgProxyList ) ); + } + + if ( !is_array( $wgProxyList ) ) { + $ret = false; + } elseif ( array_search( $ip, $wgProxyList ) !== false ) { + $ret = true; + } elseif ( array_key_exists( $ip, $wgProxyList ) ) { + # Old-style flipped proxy list + $ret = true; + } else { + $ret = false; + } + wfProfileOut( __METHOD__ ); + return $ret; + } + /** * Is this user subject to rate limiting? * -- 2.20.1