Index: trunk/phase3/tests/bootstrap.php |
— | — | @@ -13,12 +13,26 @@ |
14 | 14 | |
15 | 15 | define( 'MEDIAWIKI', true ); |
16 | 16 | define( 'MW_PHPUNIT_TEST', true ); |
17 | | -ini_set( 'include_path', "$IP:" .ini_get( 'include_path' ) ); |
18 | 17 | |
19 | | -require "$IP/includes/Defines.php"; |
20 | | -require "$IP/includes/AutoLoader.php"; |
21 | | -require "$IP/LocalSettings.php"; |
22 | | - |
| 18 | +require_once "$IP/includes/Defines.php"; |
| 19 | +require_once "$IP/includes/AutoLoader.php"; |
| 20 | +require_once "$IP/LocalSettings.php"; |
23 | 21 | require_once "$IP/includes/ProfilerStub.php"; |
24 | 22 | require_once "$IP/includes/GlobalFunctions.php"; |
25 | 23 | require_once "$IP/includes/Hooks.php"; |
| 24 | + |
| 25 | +// for php versions before 5.2.1 |
| 26 | +if ( !function_exists('sys_get_temp_dir')) { |
| 27 | + function sys_get_temp_dir() { |
| 28 | + if( $temp=getenv('TMP') ) return $temp; |
| 29 | + if( $temp=getenv('TEMP') ) return $temp; |
| 30 | + if( $temp=getenv('TMPDIR') ) return $temp; |
| 31 | + $temp=tempnam(__FILE__,''); |
| 32 | + if (file_exists($temp)) { |
| 33 | + unlink($temp); |
| 34 | + return dirname($temp); |
| 35 | + } |
| 36 | + return null; |
| 37 | + } |
| 38 | + } |
| 39 | + |
Index: trunk/phase3/tests/HttpTest.php |
— | — | @@ -1,5 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +if ( !defined( 'MW_PHPUNIT_TEST' ) ) { |
| 5 | + require_once( 'bootstrap.php' ); |
| 6 | +} |
| 7 | + |
4 | 8 | class HttpTest extends PhpUnit_Framework_TestCase { |
5 | 9 | static $content; |
6 | 10 | static $headers; |
— | — | @@ -25,7 +29,7 @@ |
26 | 30 | self::$has_curl = function_exists( 'curl_init' ); |
27 | 31 | |
28 | 32 | if ( !file_exists("/usr/bin/curl") ) { |
29 | | - $this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch."); |
| 33 | + $this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch."); |
30 | 34 | } |
31 | 35 | |
32 | 36 | $content = tempnam( sys_get_temp_dir(), "" ); |
— | — | @@ -65,7 +69,7 @@ |
66 | 70 | function testInstantiation() { |
67 | 71 | Http::$httpEngine = false; |
68 | 72 | |
69 | | - $r = HttpRequest::factory("http://www.example.com/"); |
| 73 | + $r = HttpRequest::factory("http://www.example.com/"); |
70 | 74 | if ( self::$has_curl ) { |
71 | 75 | $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' )); |
72 | 76 | } else { |
— | — | @@ -120,7 +124,7 @@ |
121 | 125 | } |
122 | 126 | |
123 | 127 | /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */ |
124 | | - /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */ |
| 128 | + /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */ |
125 | 129 | /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */ |
126 | 130 | function runHTTPRequests($proxy=null) { |
127 | 131 | $opt = array(); |
— | — | @@ -160,8 +164,8 @@ |
161 | 165 | /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */ |
162 | 166 | /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */ |
163 | 167 | /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */ |
164 | | - /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */ |
165 | | - /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */ |
| 168 | + /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */ |
| 169 | + /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */ |
166 | 170 | /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */ |
167 | 171 | /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */ |
168 | 172 | /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */ |
— | — | @@ -198,7 +202,7 @@ |
199 | 203 | /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */ |
200 | 204 | /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */ |
201 | 205 | /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */ |
202 | | - /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */ |
| 206 | + /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */ |
203 | 207 | function runHTTPGets($proxy=null) { |
204 | 208 | $opt = array(); |
205 | 209 | |
Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -184,7 +184,7 @@ |
185 | 185 | case 'php': |
186 | 186 | if ( !wfIniGetBool( 'allow_url_fopen' ) ) { |
187 | 187 | throw new MWException( __METHOD__.': allow_url_fopen needs to be enabled for pure PHP http requests to work. '. |
188 | | - 'If possible, curl should be used instead. See http://php.net/curl.' ); |
| 188 | + 'If possible, curl should be used instead. See http://php.net/curl.' ); |
189 | 189 | } |
190 | 190 | return new PhpHttpRequest( $url, $options ); |
191 | 191 | default: |
— | — | @@ -365,8 +365,6 @@ |
366 | 366 | } |
367 | 367 | |
368 | 368 | class PhpHttpRequest extends HttpRequest { |
369 | | - private $fh; |
370 | | - |
371 | 369 | protected function urlToTcp( $url ) { |
372 | 370 | $parsedUrl = parse_url( $url ); |
373 | 371 | |
— | — | @@ -376,7 +374,7 @@ |
377 | 375 | public function execute() { |
378 | 376 | if ( $this->parsedUrl['scheme'] != 'http' ) { |
379 | 377 | $this->status->fatal( 'http-invalid-scheme', $this->parsedURL['scheme'] ); |
380 | | - } |
| 378 | + } |
381 | 379 | |
382 | 380 | parent::execute(); |
383 | 381 | if ( !$this->status->isOK() ) { |
— | — | @@ -399,26 +397,33 @@ |
400 | 398 | $options['method'] = $this->method; |
401 | 399 | $options['timeout'] = $this->timeout; |
402 | 400 | $options['header'] = implode("\r\n", $this->getHeaderList()); |
403 | | - // FOR NOW: Force everyone to HTTP 1.0 |
404 | | - /* if ( version_compare( "5.3.0", phpversion(), ">" ) ) { */ |
405 | | - $options['protocol_version'] = "1.0"; |
406 | | - /* } else { */ |
407 | | - /* $options['protocol_version'] = "1.1"; */ |
408 | | - /* } */ |
| 401 | + // Note that at some future point we may want to support |
| 402 | + // HTTP/1.1, but we'd have to write support for chunking |
| 403 | + // in version of PHP < 5.3.1 |
| 404 | + $options['protocol_version'] = "1.0"; |
409 | 405 | |
410 | 406 | if ( $this->postData ) { |
411 | 407 | $options['content'] = $this->postData; |
412 | 408 | } |
413 | 409 | |
| 410 | + $oldTimeout = false; |
| 411 | + if ( version_compare( '5.2.1', phpversion(), '>' ) ) { |
| 412 | + $oldTimeout = ini_set('default_socket_timeout', $this->timeout); |
| 413 | + } |
| 414 | + |
414 | 415 | $context = stream_context_create( array( 'http' => $options ) ); |
415 | | - try { |
416 | | - $this->fh = fopen( $this->url, "r", false, $context ); |
417 | | - } catch ( Exception $e ) { |
418 | | - $this->status->fatal( $e->getMessage() ); /* need some l10n help */ |
| 416 | + wfSuppressWarnings(); |
| 417 | + $fh = fopen( $this->url, "r", false, $context ); |
| 418 | + wfRestoreWarnings(); |
| 419 | + if ( $oldTimeout !== false ) { |
| 420 | + ini_set('default_socket_timeout', $oldTimeout); |
| 421 | + } |
| 422 | + if ( $fh === false ) { |
| 423 | + $this->status->fatal( 'http-request-error' ); |
419 | 424 | return $this->status; |
420 | 425 | } |
421 | 426 | |
422 | | - $result = stream_get_meta_data( $this->fh ); |
| 427 | + $result = stream_get_meta_data( $fh ); |
423 | 428 | if ( $result['timed_out'] ) { |
424 | 429 | $this->status->fatal( 'http-timed-out', $this->url ); |
425 | 430 | return $this->status; |
— | — | @@ -426,16 +431,17 @@ |
427 | 432 | |
428 | 433 | $this->headers = $result['wrapper_data']; |
429 | 434 | |
430 | | - $end = false; |
431 | | - while ( !$end ) { |
432 | | - $contents = fread( $this->fh, 8192 ); |
433 | | - $size = 0; |
434 | | - if ( $contents ) { |
435 | | - $size = call_user_func_array( $this->callback, array( $this->fh, $contents ) ); |
| 435 | + while ( !feof( $fh ) ) { |
| 436 | + $buf = fread( $fh, 8192 ); |
| 437 | + if ( $buf === false ) { |
| 438 | + $this->status->fatal( 'http-read-error' ); |
| 439 | + break; |
436 | 440 | } |
437 | | - $end = ( $size == 0 ) || feof( $this->fh ); |
| 441 | + if ( strlen( $buf ) ) { |
| 442 | + call_user_func( $this->callback, $fh, $buf ); |
| 443 | + } |
438 | 444 | } |
439 | | - fclose( $this->fh ); |
| 445 | + fclose( $fh ); |
440 | 446 | |
441 | 447 | return $this->status; |
442 | 448 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2154,7 +2154,7 @@ |
2155 | 2155 | # HTTP errors |
2156 | 2156 | 'http-invalid-url' => 'Invalid URL: $1', |
2157 | 2157 | 'http-invalid-scheme' => 'URLs with the "$1" scheme are not supported', |
2158 | | -'http-request-error' => 'Error sending request:', |
| 2158 | +'http-request-error' => 'Unknown error sending request.', |
2159 | 2159 | |
2160 | 2160 | # Some likely curl errors. More could be added from <http://curl.haxx.se/libcurl/c/libcurl-errors.html> |
2161 | 2161 | 'upload-curl-error6' => 'Could not reach URL', |