r61408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61407‎ | r61408 | r61409 >
Date:06:23, 23 January 2010
Author:mah
Status:ok
Tags:
Comment:
follow up r61356 -- remove global
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/tests/HttpTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/HttpTest.php
@@ -63,9 +63,8 @@
6464
6565
6666 function testInstantiation() {
67 - global $wgHTTPEngine;
 67+ Http::$httpEngine = false;
6868
69 - unset($wgHTTPEngine);
7069 $r = new HttpRequest("http://www.example.com/");
7170 if ( self::$has_curl ) {
7271 $this->isInstanceOf( $r, 'CurlHttpRequest' );
@@ -74,7 +73,7 @@
7574 }
7675 unset($r);
7776
78 - $wgHTTPEngine = 'php';
 77+ Http::$httpEngine = 'php';
7978 $r = new HttpRequest("http://www.example.com/");
8079 $this->isInstanceOf( $r, 'PhpHttpRequest' );
8180 unset($r);
@@ -82,7 +81,7 @@
8382 if( !self::$has_curl ) {
8483 $this->setExpectedException( 'MWException' );
8584 }
86 - $wgHTTPEngine = 'curl';
 85+ Http::$httpEngine = 'curl';
8786 $r = new HttpRequest("http://www.example.com/");
8887 if( self::$has_curl ) {
8988 $this->isInstanceOf( $r, 'CurlHttpRequest' );
@@ -90,7 +89,6 @@
9190 }
9291
9392 function runHTTPFailureChecks() {
94 - global $wgHTTPEngine;
9593 // Each of the following requests should result in a failure.
9694
9795 $timeout = 1;
@@ -98,32 +96,26 @@
9997 $r = HTTP::get( "http://www.example.com:1/", $timeout);
10098 $end_time = time();
10199 $this->assertLessThan($timeout+2, $end_time - $start_time,
102 - "Request took less than {$timeout}s via $wgHTTPEngine");
 100+ "Request took less than {$timeout}s via ".Http::$httpEngine);
103101 $this->assertEquals($r, false, "false -- what we get on error from Http::get()");
104102 }
105103
106104 function testFailureDefault() {
107 - global $wgHTTPEngine;
108 -
109 - unset($wgHTTPEngine);
 105+ Http::$httpEngine = false;
110106 self::runHTTPFailureChecks();
111107 }
112108
113109 function testFailurePhp() {
114 - global $wgHTTPEngine;
115 -
116 - $wgHTTPEngine = "php";
 110+ Http::$httpEngine = "php";
117111 self::runHTTPFailureChecks();
118112 }
119113
120114 function testFailureCurl() {
121 - global $wgHTTPEngine;
122 -
123115 if (!self::$has_curl ) {
124116 $this->markTestIncomplete("This test requires curl.");
125117 }
126118
127 - $wgHTTPEngine = "curl";
 119+ Http::$httpEngine = "curl";
128120 self::runHTTPFailureChecks();
129121 }
130122
@@ -131,7 +123,6 @@
132124 /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
133125 /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
134126 function runHTTPRequests($proxy=null) {
135 - global $wgHTTPEngine;
136127 $opt = array();
137128
138129 if($proxy) {
@@ -141,32 +132,26 @@
142133 /* no postData here because the only request I could find in code so far didn't have any */
143134 foreach ( $this->test_requesturl as $u ) {
144135 $r = Http::request( "POST", $u, $opt );
145 - $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with $wgHTTPEngine" );
 136+ $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
146137 }
147138 }
148139
149140 function testRequestDefault() {
150 - global $wgHTTPEngine;
151 -
152 - unset($wgHTTPEngine);
 141+ Http::$httpEngine = false;
153142 self::runHTTPRequests();
154143 }
155144
156145 function testRequestPhp() {
157 - global $wgHTTPEngine;
158 -
159 - $wgHTTPEngine = "php";
 146+ Http::$httpEngine = "php";
160147 self::runHTTPRequests();
161148 }
162149
163150 function testRequestCurl() {
164 - global $wgHTTPEngine;
165 -
166151 if (!self::$has_curl ) {
167152 $this->markTestIncomplete("This test requires curl.");
168153 }
169154
170 - $wgHTTPEngine = "curl";
 155+ Http::$httpEngine = "curl";
171156 self::runHTTPRequests();
172157 }
173158
@@ -215,7 +200,6 @@
216201 /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
217202 /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
218203 function runHTTPGets($proxy=null) {
219 - global $wgHTTPEngine;
220204 $opt = array();
221205
222206 if($proxy) {
@@ -224,38 +208,31 @@
225209
226210 foreach ( $this->test_geturl as $u ) {
227211 $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
228 - $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with $wgHTTPEngine" );
 212+ $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
229213 }
230214 }
231215
232216 function testGetDefault() {
233 - global $wgHTTPEngine;
234 -
235 - unset($wgHTTPEngine);
 217+ Http::$httpEngine = false;
236218 self::runHTTPGets();
237219 }
238220
239221 function testGetPhp() {
240 - global $wgHTTPEngine;
241 -
242 - $wgHTTPEngine = "php";
 222+ Http::$httpEngine = "php";
243223 self::runHTTPGets();
244224 }
245225
246226 function testGetCurl() {
247 - global $wgHTTPEngine;
248 -
249227 if (!self::$has_curl ) {
250228 $this->markTestIncomplete("This test requires curl.");
251229 }
252230
253 - $wgHTTPEngine = "curl";
 231+ Http::$httpEngine = "curl";
254232 self::runHTTPGets();
255233 }
256234
257235 /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
258236 function runHTTPPosts($proxy=null) {
259 - global $wgHTTPEngine;
260237 $opt = array();
261238
262239 if($proxy) {
@@ -266,38 +243,30 @@
267244 $opt['postData'] = $postData;
268245 $r = Http::post( $u, $opt );
269246 $this->assertEquals( self::$content["POST $u => $postData"], "$r",
270 - "POST $u (postData=$postData) with $wgHTTPEngine" );
 247+ "POST $u (postData=$postData) with ".Http::$httpEngine );
271248 }
272249 }
273250
274251 function testPostDefault() {
275 - global $wgHTTPEngine;
276 -
277 - unset($wgHTTPEngine);
 252+ Http::$httpEngine = false;
278253 self::runHTTPPosts();
279254 }
280255
281256 function testPostPhp() {
282 - global $wgHTTPEngine;
283 -
284 - $wgHTTPEngine = "php";
 257+ Http::$httpEngine = "php";
285258 self::runHTTPPosts();
286259 }
287260
288261 function testPostCurl() {
289 - global $wgHTTPEngine;
290 -
291262 if (!self::$has_curl ) {
292263 $this->markTestIncomplete("This test requires curl.");
293264 }
294265
295 - $wgHTTPEngine = "curl";
 266+ Http::$httpEngine = "curl";
296267 self::runHTTPPosts();
297268 }
298269
299270 function runProxyRequests() {
300 - global $wgHTTPEngine;
301 -
302271 if(!self::$has_proxy) {
303272 $this->markTestIncomplete("This test requires a proxy.");
304273 }
@@ -307,27 +276,21 @@
308277 }
309278
310279 function testProxyDefault() {
311 - global $wgHTTPEngine;
312 -
313 - unset($wgHTTPEngine);
 280+ Http::$httpEngine = false;
314281 self::runProxyRequests();
315282 }
316283
317284 function testProxyPhp() {
318 - global $wgHTTPEngine;
319 -
320 - $wgHTTPEngine = 'php';
 285+ Http::$httpEngine = 'php';
321286 self::runProxyRequests();
322287 }
323288
324289 function testProxyCurl() {
325 - global $wgHTTPEngine;
326 -
327290 if (!self::$has_curl ) {
328291 $this->markTestIncomplete("This test requires curl.");
329292 }
330293
331 - $wgHTTPEngine = 'curl';
 294+ Http::$httpEngine = 'curl';
332295 self::runProxyRequests();
333296 }
334297
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3698,14 +3698,6 @@
36993699 $wgAllowSpecialInclusion = true;
37003700
37013701 /**
3702 - * 'curl' to use curl or 'php' to use pure php (for which
3703 - * allow_url_fopen needs to be enabled). If left as false,
3704 - * HttpFunctions will attempt to use curl if it is available. The use
3705 - * of curl is strongly encouraged.
3706 - */
3707 -$wgHTTPEngine = false;
3708 -
3709 -/**
37103702 * Timeout for HTTP requests done internally
37113703 */
37123704 $wgHTTPTimeout = 25;
Index: trunk/phase3/includes/HttpFunctions.php
@@ -8,6 +8,8 @@
99 * @ingroup HTTP
1010 */
1111 class Http {
 12+ static $httpEngine = false;
 13+
1214 /**
1315 * Perform an HTTP request
1416 * @param $method string HTTP method. Usually GET/POST
@@ -169,16 +171,13 @@
170172 * @see HttpRequest::__construct
171173 */
172174 public static function factory( $url, $options ) {
173 - global $wgHTTPEngine;
174 - $engine = $wgHTTPEngine;
175 -
176 - if ( !$wgHTTPEngine ) {
177 - $wgHTTPEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
178 - } elseif ( $wgHTTPEngine == 'curl' && !function_exists( 'curl_init' ) ) {
179 - throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but $wgHTTPEngine is set to "curl"' );
 175+ if ( !Http::$httpEngine ) {
 176+ Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
 177+ } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
 178+ throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but Http::$httpEngine is set to "curl"' );
180179 }
181180
182 - switch( $wgHTTPEngine ) {
 181+ switch( Http::$httpEngine ) {
183182 case 'curl':
184183 return new CurlHttpRequest( $url, $options );
185184 case 'php':
@@ -188,7 +187,7 @@
189188 }
190189 return new PhpHttpRequest( $url, $options );
191190 default:
192 - throw new MWException( __METHOD__.': The setting of $wgHTTPEngine is not valid.' );
 191+ throw new MWException( __METHOD__.': The setting of Http::$httpEngine is not valid.' );
193192 }
194193 }
195194

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61356follow up r61352 forgot to add the new global.mah04:55, 22 January 2010

Status & tagging log