Fixed http_build_query warnings on PHP < 5.4
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 9 Jan 2014 21:38:55 +0000 (13:38 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 9 Jan 2014 21:46:29 +0000 (13:46 -0800)
* bug: 59880

Change-Id: I2eae4bed17a72b58ac33f3538dd7d16f4356a3a0

includes/libs/MultiHttpClient.php

index 29f737e..0675b38 100644 (file)
@@ -6,11 +6,13 @@
  * HTTP request maps use the following format:
  *   - method   : GET/HEAD/PUT/POST/DELETE
  *   - url      : HTTP/HTTPS URL
- *   - query    : <query parameter field/value associative array>
+ *   - query    : <query parameter field/value associative array> (uses RFC 3986)
  *   - headers  : <header name/value associative array>
  *   - body     : source to get the HTTP request body from;
  *                this can simply be a string (always), a resource for
- *                PUT requests, and a field/value array for POST request
+ *                PUT requests, and a field/value array for POST request;
+ *                array bodies are encoded as multipart/form-data and strings
+ *                use application/x-www-form-urlencoded (headers sent automatically)
  *   - stream   : resource to stream the HTTP response body to
  *
  * @author Aaron Schulz
@@ -179,7 +181,12 @@ class MultiHttpClient {
                curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 
                $url = $req['url'];
-               $query = http_build_query( $req['query'], '', '&', PHP_QUERY_RFC3986 );
+               // PHP_QUERY_RFC3986 is PHP 5.4+ only
+               $query = str_replace(
+                       array( '+', '%7E' ),
+                       array( '%20', '~' ),
+                       http_build_query( $req['query'], '', '&' )
+               );
                if ( $query != '' ) {
                        $url .= strpos( $req['url'], '?' ) === false ? "?$query" : "&$query";
                }