follow up r61356 -- remove global
authorMark A. Hershberger <mah@users.mediawiki.org>
Sat, 23 Jan 2010 06:23:18 +0000 (06:23 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sat, 23 Jan 2010 06:23:18 +0000 (06:23 +0000)
includes/DefaultSettings.php
includes/HttpFunctions.php
tests/HttpTest.php

index c67bd26..450d69b 100644 (file)
@@ -3697,14 +3697,6 @@ $wgTrustedMediaFormats= array(
  */
 $wgAllowSpecialInclusion = true;
 
-/**
- * 'curl' to use curl or 'php' to use pure php (for which
- * allow_url_fopen needs to be enabled).  If left as false,
- * HttpFunctions will attempt to use curl if it is available.  The use
- * of curl is strongly encouraged.
- */
-$wgHTTPEngine = false;
-
 /**
  * Timeout for HTTP requests done internally
  */
index add4f60..2de2675 100644 (file)
@@ -8,6 +8,8 @@
  * @ingroup HTTP
  */
 class Http {
+       static $httpEngine = false;
+
        /**
         * Perform an HTTP request
         * @param $method string HTTP method. Usually GET/POST
@@ -169,16 +171,13 @@ class HttpRequest {
         * @see HttpRequest::__construct
         */
        public static function factory( $url, $options ) {
-               global $wgHTTPEngine;
-               $engine = $wgHTTPEngine;
-
-               if ( !$wgHTTPEngine ) {
-                       $wgHTTPEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
-               } elseif ( $wgHTTPEngine == 'curl' && !function_exists( 'curl_init' ) ) {
-                       throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but $wgHTTPEngine is set to "curl"' );
+               if ( !Http::$httpEngine ) {
+                       Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
+               } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
+                       throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but Http::$httpEngine is set to "curl"' );
                }
 
-               switch( $wgHTTPEngine ) {
+               switch( Http::$httpEngine ) {
                case 'curl':
                        return new CurlHttpRequest( $url, $options );
                case 'php':
@@ -188,7 +187,7 @@ class HttpRequest {
                        }
                        return new PhpHttpRequest( $url, $options );
                default:
-                       throw new MWException( __METHOD__.': The setting of $wgHTTPEngine is not valid.' );
+                       throw new MWException( __METHOD__.': The setting of Http::$httpEngine is not valid.' );
                }
        }
 
index c407ab6..f4f85eb 100644 (file)
@@ -63,9 +63,8 @@ class HttpTest extends PhpUnit_Framework_TestCase {
 
 
        function testInstantiation() {
-               global $wgHTTPEngine;
+               Http::$httpEngine = false;
 
-               unset($wgHTTPEngine);
            $r = new HttpRequest("http://www.example.com/");
                if ( self::$has_curl ) {
                        $this->isInstanceOf( $r, 'CurlHttpRequest' );
@@ -74,7 +73,7 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                }
                unset($r);
 
-               $wgHTTPEngine = 'php';
+               Http::$httpEngine = 'php';
                $r = new HttpRequest("http://www.example.com/");
                $this->isInstanceOf( $r, 'PhpHttpRequest' );
                unset($r);
@@ -82,7 +81,7 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                if( !self::$has_curl ) {
                        $this->setExpectedException( 'MWException' );
                }
-               $wgHTTPEngine = 'curl';
+               Http::$httpEngine = 'curl';
                $r = new HttpRequest("http://www.example.com/");
                if( self::$has_curl ) {
                        $this->isInstanceOf( $r, 'CurlHttpRequest' );
@@ -90,7 +89,6 @@ class HttpTest extends PhpUnit_Framework_TestCase {
        }
 
        function runHTTPFailureChecks() {
-               global $wgHTTPEngine;
                // Each of the following requests should result in a failure.
 
                $timeout = 1;
@@ -98,32 +96,26 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                $r = HTTP::get( "http://www.example.com:1/", $timeout);
                $end_time = time();
                $this->assertLessThan($timeout+2, $end_time - $start_time,
-                                                         "Request took less than {$timeout}s via $wgHTTPEngine");
+                                                         "Request took less than {$timeout}s via ".Http::$httpEngine);
                $this->assertEquals($r, false, "false -- what we get on error from Http::get()");
        }
 
        function testFailureDefault() {
-               global $wgHTTPEngine;
-
-               unset($wgHTTPEngine);
+               Http::$httpEngine = false;
                self::runHTTPFailureChecks();
        }
 
        function testFailurePhp() {
-               global $wgHTTPEngine;
-
-               $wgHTTPEngine = "php";
+               Http::$httpEngine = "php";
                self::runHTTPFailureChecks();
        }
 
        function testFailureCurl() {
-               global $wgHTTPEngine;
-
                if (!self::$has_curl ) {
                        $this->markTestIncomplete("This test requires curl.");
                }
 
-               $wgHTTPEngine = "curl";
+               Http::$httpEngine = "curl";
                self::runHTTPFailureChecks();
        }
 
@@ -131,7 +123,6 @@ class HttpTest extends PhpUnit_Framework_TestCase {
        /* ./includes/Import.php:1124:          $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
        /* ./includes/Import.php:1134:                  return ImportStreamSource::newFromURL( $url, "POST" ); */
        function runHTTPRequests($proxy=null) {
-               global $wgHTTPEngine;
                $opt = array();
 
                if($proxy) {
@@ -141,32 +132,26 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                /* no postData here because the only request I could find in code so far didn't have any */
                foreach ( $this->test_requesturl as $u ) {
                        $r = Http::request( "POST", $u, $opt );
-                       $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with $wgHTTPEngine" );
+                       $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
                }
        }
 
        function testRequestDefault() {
-               global $wgHTTPEngine;
-
-               unset($wgHTTPEngine);
+               Http::$httpEngine = false;
                self::runHTTPRequests();
        }
 
        function testRequestPhp() {
-               global $wgHTTPEngine;
-
-               $wgHTTPEngine = "php";
+               Http::$httpEngine = "php";
                self::runHTTPRequests();
        }
 
        function testRequestCurl() {
-               global $wgHTTPEngine;
-
                if (!self::$has_curl ) {
                        $this->markTestIncomplete("This test requires curl.");
                }
 
-               $wgHTTPEngine = "curl";
+               Http::$httpEngine = "curl";
                self::runHTTPRequests();
        }
 
@@ -215,7 +200,6 @@ class HttpTest extends PhpUnit_Framework_TestCase {
        /* ./extensions/Interlanguage/Interlanguage.php:56:             $a = Http::get( $url ); */
        /* ./extensions/MWSearch/MWSearch_body.php:492:         $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts);  */
        function runHTTPGets($proxy=null) {
-               global $wgHTTPEngine;
                $opt = array();
 
                if($proxy) {
@@ -224,38 +208,31 @@ class HttpTest extends PhpUnit_Framework_TestCase {
 
                foreach ( $this->test_geturl as $u ) {
                        $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
-                       $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with $wgHTTPEngine" );
+                       $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
                }
        }
 
        function testGetDefault() {
-               global $wgHTTPEngine;
-
-               unset($wgHTTPEngine);
+               Http::$httpEngine = false;
                self::runHTTPGets();
        }
 
        function testGetPhp() {
-               global $wgHTTPEngine;
-
-               $wgHTTPEngine = "php";
+               Http::$httpEngine = "php";
                self::runHTTPGets();
        }
 
        function testGetCurl() {
-               global $wgHTTPEngine;
-
                if (!self::$has_curl ) {
                        $this->markTestIncomplete("This test requires curl.");
                }
 
-               $wgHTTPEngine = "curl";
+               Http::$httpEngine = "curl";
                self::runHTTPGets();
        }
 
        /* ./phase3/maintenance/parserTests.inc:1618:           return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
        function runHTTPPosts($proxy=null) {
-               global $wgHTTPEngine;
                $opt = array();
 
                if($proxy) {
@@ -266,38 +243,30 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                        $opt['postData'] = $postData;
                        $r = Http::post( $u, $opt );
                        $this->assertEquals( self::$content["POST $u => $postData"], "$r",
-                                                                "POST $u (postData=$postData) with $wgHTTPEngine" );
+                                                                "POST $u (postData=$postData) with ".Http::$httpEngine );
                }
        }
 
        function testPostDefault() {
-               global $wgHTTPEngine;
-
-               unset($wgHTTPEngine);
+               Http::$httpEngine = false;
                self::runHTTPPosts();
        }
 
        function testPostPhp() {
-               global $wgHTTPEngine;
-
-               $wgHTTPEngine = "php";
+               Http::$httpEngine = "php";
                self::runHTTPPosts();
        }
 
        function testPostCurl() {
-               global $wgHTTPEngine;
-
                if (!self::$has_curl ) {
                        $this->markTestIncomplete("This test requires curl.");
                }
 
-               $wgHTTPEngine = "curl";
+               Http::$httpEngine = "curl";
                self::runHTTPPosts();
        }
 
        function runProxyRequests() {
-               global $wgHTTPEngine;
-
                if(!self::$has_proxy) {
                        $this->markTestIncomplete("This test requires a proxy.");
                }
@@ -307,27 +276,21 @@ class HttpTest extends PhpUnit_Framework_TestCase {
        }
 
        function testProxyDefault() {
-               global $wgHTTPEngine;
-
-               unset($wgHTTPEngine);
+               Http::$httpEngine = false;
                self::runProxyRequests();
        }
 
        function testProxyPhp() {
-               global $wgHTTPEngine;
-
-               $wgHTTPEngine = 'php';
+               Http::$httpEngine = 'php';
                self::runProxyRequests();
        }
 
        function testProxyCurl() {
-               global $wgHTTPEngine;
-
                if (!self::$has_curl ) {
                        $this->markTestIncomplete("This test requires curl.");
                }
 
-               $wgHTTPEngine = 'curl';
+               Http::$httpEngine = 'curl';
                self::runProxyRequests();
        }