Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -136,16 +136,16 @@ |
137 | 137 | * sslVerifyHost |
138 | 138 | * caInfo |
139 | 139 | */ |
140 | | - function __construct( $url = null, $opt = array()) { |
| 140 | + function __construct( $url = null, $opt = array() ) { |
141 | 141 | global $wgHTTPTimeout, $wgTitle; |
142 | 142 | |
143 | 143 | $this->url = $url; |
144 | | - $this->parsed_url = parse_url($url); |
| 144 | + $this->parsed_url = parse_url( $url ); |
145 | 145 | |
146 | 146 | if ( !ini_get( 'allow_url_fopen' ) ) { |
147 | 147 | throw new MWException( 'allow_url_fopen needs to be enabled for http requests to work' ); |
148 | 148 | } elseif ( !Http::isValidURI( $this->url ) ) { |
149 | | - throw new MWException( 'bad-uri' ); |
| 149 | + throw new MWException( 'Invalid URL' ); |
150 | 150 | } else { |
151 | 151 | $this->status = Status::newGood( 100 ); // continue |
152 | 152 | } |
— | — | @@ -157,7 +157,7 @@ |
158 | 158 | } |
159 | 159 | |
160 | 160 | $members = array( "targetFilePath", "requestKey", "headersOnly", "postdata", |
161 | | - "proxy", "no_proxy", "sslVerifyHost", "caInfo", "method" ); |
| 161 | + "proxy", "no_proxy", "sslVerifyHost", "caInfo", "method" ); |
162 | 162 | foreach ( $members as $o ) { |
163 | 163 | if ( array_key_exists( $o, $opt ) ) { |
164 | 164 | $this->$o = $opt[$o]; |
— | — | @@ -213,7 +213,7 @@ |
214 | 214 | case 'php': |
215 | 215 | return new PhpHttpRequest( $url, $opt ); |
216 | 216 | default: |
217 | | - throw new MWException( 'FIXME' ); |
| 217 | + throw new MWException( 'The setting of $wgHTTPEngine is not valid.' ); |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
— | — | @@ -221,13 +221,13 @@ |
222 | 222 | return $this->content; |
223 | 223 | } |
224 | 224 | |
225 | | - public function initRequest() {} |
226 | | - public function proxySetup() {} |
227 | | - public function setReferrer( $url ) {} |
228 | | - public function setCallback( $cb ) {} |
229 | | - public function read($fh, $content) {} |
230 | | - public function getCode() {} |
231 | | - public function execute() {} |
| 225 | + public function initRequest() { } |
| 226 | + public function proxySetup() { } |
| 227 | + public function setReferrer( $url ) { } |
| 228 | + public function setCallback( $cb ) { } |
| 229 | + public function read( $fh, $content ) { } |
| 230 | + public function getCode() { } |
| 231 | + public function execute() { } |
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
— | — | @@ -261,11 +261,11 @@ |
262 | 262 | } |
263 | 263 | |
264 | 264 | public function execute() { |
265 | | - if( !$this->status->isOK() ) { |
| 265 | + if ( !$this->status->isOK() ) { |
266 | 266 | return $this->status; |
267 | 267 | } |
268 | 268 | |
269 | | - $this->setCallback( array($this, 'read') ); |
| 269 | + $this->setCallback( array( $this, 'read' ) ); |
270 | 270 | |
271 | 271 | curl_setopt( $this->curlHandle, CURLOPT_TIMEOUT, $this->timeout ); |
272 | 272 | curl_setopt( $this->curlHandle, CURLOPT_USERAGENT, Http::userAgent() ); |
— | — | @@ -295,17 +295,15 @@ |
296 | 296 | |
297 | 297 | try { |
298 | 298 | if ( false === curl_exec( $this->curlHandle ) ) { |
299 | | - $error_txt = 'Error sending request: #' . curl_errno( $this->curlHandle ) . ' ' . |
300 | | - curl_error( $this->curlHandle ); |
301 | | - wfDebug( __METHOD__ . $error_txt . "\n" ); |
302 | | - $this->status->fatal( $error_txt ); /* i18n? */ |
| 299 | + $this->status->fatal( 'Error sending request (#$1): $2', |
| 300 | + curl_errno( $this->curlHandle ), |
| 301 | + curl_error( $this->curlHandle ) ); |
303 | 302 | } |
304 | 303 | } catch ( Exception $e ) { |
305 | 304 | $errno = curl_errno( $this->curlHandle ); |
306 | 305 | if ( $errno != CURLE_OK ) { |
307 | 306 | $errstr = curl_error( $this->curlHandle ); |
308 | | - wfDebug( __METHOD__ . ": CURL error code $errno: $errstr\n" ); |
309 | | - $this->status->fatal( "CURL error code $errno: $errstr\n" ); /* i18n? */ |
| 307 | + $this->status->fatal( 'CURL error code $1: $2', $errno, $errstr ); |
310 | 308 | } |
311 | 309 | } |
312 | 310 | |
— | — | @@ -346,15 +344,15 @@ |
347 | 345 | $this->reqHeaders[] = "Content-type: application/x-www-form-urlencoded"; |
348 | 346 | } |
349 | 347 | |
350 | | - if( $this->parsed_url['scheme'] != 'http' ) { |
| 348 | + if ( $this->parsed_url['scheme'] != 'http' ) { |
351 | 349 | $this->status->fatal( "Only http:// is supported currently." ); |
352 | 350 | } |
353 | 351 | } |
354 | 352 | |
355 | | - protected function urlToTcp($url) { |
356 | | - $parsed_url = parse_url($url); |
| 353 | + protected function urlToTcp( $url ) { |
| 354 | + $parsed_url = parse_url( $url ); |
357 | 355 | |
358 | | - return 'tcp://'.$parsed_url['host'].':'.$parsed_url['port']; |
| 356 | + return 'tcp://' . $parsed_url['host'] . ':' . $parsed_url['port']; |
359 | 357 | } |
360 | 358 | |
361 | 359 | public function proxySetup() { |
— | — | @@ -385,13 +383,13 @@ |
386 | 384 | } |
387 | 385 | |
388 | 386 | public function execute() { |
389 | | - if( !$this->status->isOK() ) { |
| 387 | + if ( !$this->status->isOK() ) { |
390 | 388 | return $this->status; |
391 | 389 | } |
392 | 390 | |
393 | 391 | $opts = array(); |
394 | 392 | if ( $this->proxy && !$this->no_proxy ) { |
395 | | - $opts['proxy'] = $this->urlToTCP($this->proxy); |
| 393 | + $opts['proxy'] = $this->urlToTCP( $this->proxy ); |
396 | 394 | $opts['request_fulluri'] = true; |
397 | 395 | } |
398 | 396 | |
— | — | @@ -412,14 +410,14 @@ |
413 | 411 | $context = stream_context_create( array( 'http' => $opts ) ); |
414 | 412 | try { |
415 | 413 | $this->fh = fopen( $this->url, "r", false, $context ); |
416 | | - } catch (Exception $e) { |
417 | | - $this->status->fatal($e->getMessage()); |
| 414 | + } catch ( Exception $e ) { |
| 415 | + $this->status->fatal( $e->getMessage() ); |
418 | 416 | return $this->status; |
419 | 417 | } |
420 | 418 | |
421 | 419 | $result = stream_get_meta_data( $this->fh ); |
422 | 420 | if ( $result['timed_out'] ) { |
423 | | - $this->status->error( __CLASS__ . '::timed-out-in-headers' ); |
| 421 | + $this->status->error( 'The request timed out' ); |
424 | 422 | } |
425 | 423 | |
426 | 424 | $this->headers = $result['wrapper_data']; |