]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/ProxyTools.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / ProxyTools.php
index 771fd5779664db0a99b45f16c5896acd61bf2b69..13c199654d606c9943179d0eaf5d56d47341449b 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
  * Functions for dealing with proxies
+ *
  * @file
  */
 
@@ -67,22 +68,26 @@ function wfGetAgent() {
  * @return string
  */
 function wfGetIP() {
-       global $wgIP, $wgUsePrivateIPs;
+       global $wgUsePrivateIPs, $wgCommandLineMode;
+       static $ip = false;
 
        # Return cached result
-       if ( !empty( $wgIP ) ) {
-               return $wgIP;
+       if ( !empty( $ip ) ) {
+               return $ip;
        }
 
+       $ipchain = array();
+
        /* collect the originating ips */
        # Client connecting to this webserver
        if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
-               $ipchain = array( IP::canonicalize( $_SERVER['REMOTE_ADDR'] ) );
-       } else {
-               # Running on CLI?
-               $ipchain = array( '127.0.0.1' );
+               $ip = IP::canonicalize( $_SERVER['REMOTE_ADDR'] );
+       } elseif( $wgCommandLineMode ) {
+               $ip = '127.0.0.1';
+       }
+       if( $ip ) {
+               $ipchain[] = $ip;
        }
-       $ip = $ipchain[0];
 
        # Append XFF on to $ipchain
        $forwardedFor = wfGetForwardedFor();
@@ -107,8 +112,14 @@ function wfGetIP() {
                }
        }
 
+       # Allow extensions to improve our guess
+       wfRunHooks( 'GetIP', array( &$ip ) );
+
+       if( !$ip ) {
+               throw new MWException( "Unable to determine IP" );
+       }
+
        wfDebug( "IP: $ip\n" );
-       $wgIP = $ip;
        return $ip;
 }
 
@@ -116,7 +127,7 @@ function wfGetIP() {
  * Checks if an IP is a trusted proxy providor
  * Useful to tell if X-Fowarded-For data is possibly bogus
  * Squid cache servers for the site and AOL are whitelisted
- * @param string $ip
+ * @param $ip String
  * @return bool
  */
 function wfIsTrustedProxy( $ip ) {
@@ -166,7 +177,7 @@ function wfProxyCheck() {
                                                escapeshellarg( $port ),
                                                escapeshellarg( $url )
                                                ));
-                       exec( "php $params &>/dev/null &" );
+                       exec( "php $params >" . wfGetNull() . " 2>&1 &" );
                }
                # Set MemCached key
                $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
@@ -175,9 +186,12 @@ function wfProxyCheck() {
 
 /**
  * Convert a network specification in CIDR notation to an integer network and a number of bits
+ *
+ * @deprecated Call IP::parseCIDR() directly, will be removed in 1.19
  * @return array(string, int)
  */
 function wfParseCIDR( $range ) {
+       wfDeprecated( __FUNCTION__ );
        return IP::parseCIDR( $range );
 }
 
@@ -187,12 +201,11 @@ function wfParseCIDR( $range ) {
  */
 function wfIsLocallyBlockedProxy( $ip ) {
        global $wgProxyList;
-       $fname = 'wfIsLocallyBlockedProxy';
 
        if ( !$wgProxyList ) {
                return false;
        }
-       wfProfileIn( $fname );
+       wfProfileIn( __METHOD__ );
 
        if ( !is_array( $wgProxyList ) ) {
                # Load from the specified file
@@ -209,7 +222,7 @@ function wfIsLocallyBlockedProxy( $ip ) {
        } else {
                $ret = false;
        }
-       wfProfileOut( $fname );
+       wfProfileOut( __METHOD__ );
        return $ret;
 }