Merge "Add non DBMS depending SQL tests for DatabaseBase"
[lhc/web/wiklou.git] / includes / HttpFunctions.php
index 9e280db..489a83a 100644 (file)
@@ -305,7 +305,7 @@ class MWHttpRequest {
 
        /**
         * Set the parameters of the request
-
+        *
         * @param $args Array
         * @todo overload the args param
         */
@@ -563,8 +563,8 @@ class MWHttpRequest {
                        $this->parseHeader();
                }
 
-               if ( isset( $this->respHeaders[strtolower ( $header ) ] ) ) {
-                       $v = $this->respHeaders[strtolower ( $header ) ];
+               if ( isset( $this->respHeaders[strtolower( $header )] ) ) {
+                       $v = $this->respHeaders[strtolower( $header )];
                        return $v[count( $v ) - 1];
                }
 
@@ -646,17 +646,17 @@ class MWHttpRequest {
                $headers = $this->getResponseHeaders();
 
                //return full url (fix for incorrect but handled relative location)
-               if ( isset( $headers[ 'location' ] ) ) {
-                       $locations = $headers[ 'location' ];
+               if ( isset( $headers['location'] ) ) {
+                       $locations = $headers['location'];
                        $domain = '';
                        $foundRelativeURI = false;
                        $countLocations = count( $locations );
 
                        for ( $i = $countLocations - 1; $i >= 0; $i-- ) {
-                               $url = parse_url( $locations[ $i ] );
+                               $url = parse_url( $locations[$i] );
 
                                if ( isset( $url['host'] ) ) {
-                                       $domain = $url[ 'scheme' ] . '://' . $url[ 'host' ];
+                                       $domain = $url['scheme'] . '://' . $url['host'];
                                        break; //found correct URI (with host)
                                } else {
                                        $foundRelativeURI = true;
@@ -665,15 +665,15 @@ class MWHttpRequest {
 
                        if ( $foundRelativeURI ) {
                                if ( $domain ) {
-                                       return $domain . $locations[ $countLocations - 1 ];
+                                       return $domain . $locations[$countLocations - 1];
                                } else {
                                        $url = parse_url( $this->url );
-                                       if ( isset($url[ 'host' ]) ) {
-                                               return $url[ 'scheme' ] . '://' . $url[ 'host' ] . $locations[ $countLocations - 1 ];
+                                       if ( isset( $url['host'] ) ) {
+                                               return $url['scheme'] . '://' . $url['host'] . $locations[$countLocations - 1];
                                        }
                                }
                        } else {
-                               return $locations[ $countLocations - 1 ];
+                               return $locations[$countLocations - 1];
                        }
                }
 
@@ -696,11 +696,6 @@ class MWHttpRequest {
 class CurlHttpRequest extends MWHttpRequest {
        const SUPPORTS_FILE_POSTS = true;
 
-       static $curlMessageMap = array(
-               6 => 'http-host-unreachable',
-               28 => 'http-timed-out'
-       );
-
        protected $curlOptions = array();
        protected $headerText = "";
 
@@ -779,14 +774,11 @@ class CurlHttpRequest extends MWHttpRequest {
                        wfRestoreWarnings();
                }
 
-               if ( false === curl_exec( $curlHandle ) ) {
-                       $code = curl_error( $curlHandle );
-
-                       if ( isset( self::$curlMessageMap[$code] ) ) {
-                               $this->status->fatal( self::$curlMessageMap[$code] );
-                       } else {
-                               $this->status->fatal( 'http-curl-error', curl_error( $curlHandle ) );
-                       }
+               $curlRes = curl_exec( $curlHandle );
+               if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
+                       $this->status->fatal( 'http-timed-out', $this->url );
+               } elseif ( $curlRes === false ) {
+                       $this->status->fatal( 'http-curl-error', curl_error( $curlHandle ) );
                } else {
                        $this->headerList = explode( "\r\n", $this->headerText );
                }
@@ -938,8 +930,7 @@ class PhpHttpRequest extends MWHttpRequest {
 
                // If everything went OK, or we received some error code
                // get the response body content.
-               if ( $this->status->isOK()
-                               || (int)$this->respStatus >= 300) {
+               if ( $this->status->isOK() || (int)$this->respStatus >= 300 ) {
                        while ( !feof( $fh ) ) {
                                $buf = fread( $fh, 8192 );