From 8adc7befe56cbb9fe1528914d377229fe015a1b6 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Fri, 12 Nov 2010 07:32:09 +0000 Subject: [PATCH] (Bug 25872) Rename HttpRequest class to MWHttpRequest to avoid conflict with php extension. This also keeps the old HttpRequest class name around, so it should not break backwards compatability. --- RELEASE-NOTES | 2 ++ includes/AutoLoader.php | 3 ++- includes/HttpFunctions.old.php | 24 +++++++++++++++++++ includes/HttpFunctions.php | 19 ++++++++------- includes/filerepo/ForeignAPIRepo.php | 2 +- includes/upload/UploadFromUrl.php | 4 ++-- .../tests/phpunit/includes/HttpTest.php | 10 ++++---- .../tests/phpunit/includes/api/ApiTest.php | 4 ++-- 8 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 includes/HttpFunctions.old.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ec86c60ad6..50847280ac 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -421,6 +421,8 @@ LocalSettings.php. The specific bugs are listed below in the general notes. some cases * (bug 25670) wfFindFile() now checks the namespace of the given title, only "File" and "Media" are allowed now +* (bug 25872) Rename the HttpRequest class to MWHttpRequest to avoid conflict + with php extension that defines same class. === API changes in 1.17 === * (bug 22738) Allow filtering by action type on query=logevent. diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 6a6ed8d5a2..417c74d7f8 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -125,7 +125,7 @@ $wgAutoloadLocalClasses = array( 'HTMLRadioField' => 'includes/HTMLForm.php', 'HTMLInfoField' => 'includes/HTMLForm.php', 'Http' => 'includes/HttpFunctions.php', - 'HttpRequest' => 'includes/HttpFunctions.php', + 'HttpRequest' => 'includes/HttpFunctions.old.php', 'ImageGallery' => 'includes/ImageGallery.php', 'ImageHistoryList' => 'includes/ImagePage.php', 'ImageHistoryPseudoPager' => 'includes/ImagePage.php', @@ -167,6 +167,7 @@ $wgAutoloadLocalClasses = array( 'MessageCache' => 'includes/MessageCache.php', 'MimeMagic' => 'includes/MimeMagic.php', 'MWException' => 'includes/Exception.php', + 'MWHttpRequest' => 'includes/HttpFunctions.php', 'MWMemcached' => 'includes/memcached-client.php', 'MWNamespace' => 'includes/Namespace.php', 'OldChangesList' => 'includes/ChangesList.php', diff --git a/includes/HttpFunctions.old.php b/includes/HttpFunctions.old.php new file mode 100644 index 0000000000..166d2cdf4f --- /dev/null +++ b/includes/HttpFunctions.old.php @@ -0,0 +1,24 @@ +execute(); if ( $status->isOK() ) { @@ -133,8 +133,11 @@ class Http { /** * This wrapper class will call out to curl (if available) or fallback * to regular PHP if necessary for handling internal HTTP requests. + * + * Renamed from HttpRequest to MWHttpRequst to avoid conflict with + * php's HTTP extension. */ -class HttpRequest { +class MWHttpRequest { protected $content; protected $timeout = 'default'; protected $headersOnly = null; @@ -195,7 +198,7 @@ class HttpRequest { /** * Generate a new request object - * @see HttpRequest::__construct + * @see MWHttpRequest::__construct */ public static function factory( $url, $options = null ) { if ( !Http::$httpEngine ) { @@ -477,7 +480,7 @@ class HttpRequest { } /** - * Tells the HttpRequest object to use this pre-loaded CookieJar. + * Tells the MWHttpRequest object to use this pre-loaded CookieJar. * * @param $jar CookieJar */ @@ -792,9 +795,9 @@ class CookieJar { } /** - * HttpRequest implemented using internal curl compiled into PHP + * MWHttpRequest implemented using internal curl compiled into PHP */ -class CurlHttpRequest extends HttpRequest { +class CurlHttpRequest extends MWHttpRequest { static $curlMessageMap = array( 6 => 'http-host-unreachable', 28 => 'http-timed-out' @@ -907,7 +910,7 @@ class CurlHttpRequest extends HttpRequest { } } -class PhpHttpRequest extends HttpRequest { +class PhpHttpRequest extends MWHttpRequest { protected function urlToTcp( $url ) { $parsedUrl = parse_url( $url ); diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 47bfaa2b4d..ef175962ab 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -362,7 +362,7 @@ class ForeignAPIRepo extends FileRepo { $options['timeout'] = 'default'; } - $req = HttpRequest::factory( $url, $options ); + $req = MWHttpRequest::factory( $url, $options ); $req->setUserAgent( ForeignAPIRepo::getUserAgent() ); $status = $req->execute(); diff --git a/includes/upload/UploadFromUrl.php b/includes/upload/UploadFromUrl.php index 42b382750f..99f6c2a680 100644 --- a/includes/upload/UploadFromUrl.php +++ b/includes/upload/UploadFromUrl.php @@ -100,7 +100,7 @@ class UploadFromUrl extends UploadBase { /** * Save the result of a HTTP request to the temporary file * - * @param $req HttpRequest + * @param $req MWHttpRequest * @return Status */ private function saveTempFile( $req ) { @@ -120,7 +120,7 @@ class UploadFromUrl extends UploadBase { * size and set $mRemoveTempFile to true. */ protected function reallyFetchFile() { - $req = HttpRequest::factory( $this->mUrl ); + $req = MWHttpRequest::factory( $this->mUrl ); $status = $req->execute(); if ( !$status->isOk() ) { diff --git a/maintenance/tests/phpunit/includes/HttpTest.php b/maintenance/tests/phpunit/includes/HttpTest.php index 994a4890d7..b11ce4c5a5 100644 --- a/maintenance/tests/phpunit/includes/HttpTest.php +++ b/maintenance/tests/phpunit/includes/HttpTest.php @@ -76,7 +76,7 @@ class HttpTest extends PHPUnit_Framework_TestCase { function testInstantiation() { Http::$httpEngine = false; - $r = HttpRequest::factory( "http://www.example.com/" ); + $r = MWHttpRequest::factory( "http://www.example.com/" ); if ( self::$has_curl ) { $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) ); } else { @@ -88,7 +88,7 @@ class HttpTest extends PHPUnit_Framework_TestCase { $this->setExpectedException( 'MWException' ); } Http::$httpEngine = 'php'; - $r = HttpRequest::factory( "http://www.example.com/" ); + $r = MWHttpRequest::factory( "http://www.example.com/" ); $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) ); unset( $r ); @@ -96,7 +96,7 @@ class HttpTest extends PHPUnit_Framework_TestCase { $this->setExpectedException( 'MWException' ); } Http::$httpEngine = 'curl'; - $r = HttpRequest::factory( "http://www.example.com/" ); + $r = MWHttpRequest::factory( "http://www.example.com/" ); if ( self::$has_curl ) { $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) ); } @@ -117,7 +117,7 @@ class HttpTest extends PHPUnit_Framework_TestCase { $this->assertFalse( $r, "False on 404s" ); - $r = HttpRequest::factory( "http://www.example.com/this-file-does-not-exist" ); + $r = MWHttpRequest::factory( "http://www.example.com/this-file-does-not-exist" ); $er = $r->execute(); if ( is_a( $r, 'PhpHttpRequest' ) && version_compare( '5.2.10', phpversion(), '>' ) ) { $this->assertRegexp( "/HTTP request failed/", $er->getWikiText() ); @@ -532,7 +532,7 @@ class HttpTest extends PHPUnit_Framework_TestCase { } function runCookieRequests() { - $r = HttpRequest::factory( "http://www.php.net/manual", array( 'followRedirects' => true ) ); + $r = MWHttpRequest::factory( "http://www.php.net/manual", array( 'followRedirects' => true ) ); $r->execute(); $jar = $r->getCookieJar(); diff --git a/maintenance/tests/phpunit/includes/api/ApiTest.php b/maintenance/tests/phpunit/includes/api/ApiTest.php index 2f1deec09d..d953cbd3af 100644 --- a/maintenance/tests/phpunit/includes/api/ApiTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiTest.php @@ -171,7 +171,7 @@ class ApiTest extends ApiTestSetup { if ( !isset( $wgServer ) ) { $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } - $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", + $req = MWHttpRequest::factory( self::$apiUrl . "?action=login&format=xml", array( "method" => "POST", "postData" => array( "lgname" => self::$user->userName, @@ -214,7 +214,7 @@ class ApiTest extends ApiTestSetup { if ( $wgServer == "http://localhost" ) { $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } - $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&" . + $req = MWHttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&" . "titles=Main%20Page&rvprop=timestamp|user|comment|content" ); $req->setCookieJar( $cj ); $req->execute(); -- 2.20.1