r61353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61352‎ | r61353 | r61354 >
Date:03:01, 22 January 2010
Author:mah
Status:resolved
Tags:
Comment:
stylize, message fixups.
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HttpFunctions.php
@@ -136,16 +136,16 @@
137137 * sslVerifyHost
138138 * caInfo
139139 */
140 - function __construct( $url = null, $opt = array()) {
 140+ function __construct( $url = null, $opt = array() ) {
141141 global $wgHTTPTimeout, $wgTitle;
142142
143143 $this->url = $url;
144 - $this->parsed_url = parse_url($url);
 144+ $this->parsed_url = parse_url( $url );
145145
146146 if ( !ini_get( 'allow_url_fopen' ) ) {
147147 throw new MWException( 'allow_url_fopen needs to be enabled for http requests to work' );
148148 } elseif ( !Http::isValidURI( $this->url ) ) {
149 - throw new MWException( 'bad-uri' );
 149+ throw new MWException( 'Invalid URL' );
150150 } else {
151151 $this->status = Status::newGood( 100 ); // continue
152152 }
@@ -157,7 +157,7 @@
158158 }
159159
160160 $members = array( "targetFilePath", "requestKey", "headersOnly", "postdata",
161 - "proxy", "no_proxy", "sslVerifyHost", "caInfo", "method" );
 161+ "proxy", "no_proxy", "sslVerifyHost", "caInfo", "method" );
162162 foreach ( $members as $o ) {
163163 if ( array_key_exists( $o, $opt ) ) {
164164 $this->$o = $opt[$o];
@@ -213,7 +213,7 @@
214214 case 'php':
215215 return new PhpHttpRequest( $url, $opt );
216216 default:
217 - throw new MWException( 'FIXME' );
 217+ throw new MWException( 'The setting of $wgHTTPEngine is not valid.' );
218218 }
219219 }
220220
@@ -221,13 +221,13 @@
222222 return $this->content;
223223 }
224224
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() { }
232232 }
233233
234234 /**
@@ -261,11 +261,11 @@
262262 }
263263
264264 public function execute() {
265 - if( !$this->status->isOK() ) {
 265+ if ( !$this->status->isOK() ) {
266266 return $this->status;
267267 }
268268
269 - $this->setCallback( array($this, 'read') );
 269+ $this->setCallback( array( $this, 'read' ) );
270270
271271 curl_setopt( $this->curlHandle, CURLOPT_TIMEOUT, $this->timeout );
272272 curl_setopt( $this->curlHandle, CURLOPT_USERAGENT, Http::userAgent() );
@@ -295,17 +295,15 @@
296296
297297 try {
298298 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 ) );
303302 }
304303 } catch ( Exception $e ) {
305304 $errno = curl_errno( $this->curlHandle );
306305 if ( $errno != CURLE_OK ) {
307306 $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 );
310308 }
311309 }
312310
@@ -346,15 +344,15 @@
347345 $this->reqHeaders[] = "Content-type: application/x-www-form-urlencoded";
348346 }
349347
350 - if( $this->parsed_url['scheme'] != 'http' ) {
 348+ if ( $this->parsed_url['scheme'] != 'http' ) {
351349 $this->status->fatal( "Only http:// is supported currently." );
352350 }
353351 }
354352
355 - protected function urlToTcp($url) {
356 - $parsed_url = parse_url($url);
 353+ protected function urlToTcp( $url ) {
 354+ $parsed_url = parse_url( $url );
357355
358 - return 'tcp://'.$parsed_url['host'].':'.$parsed_url['port'];
 356+ return 'tcp://' . $parsed_url['host'] . ':' . $parsed_url['port'];
359357 }
360358
361359 public function proxySetup() {
@@ -385,13 +383,13 @@
386384 }
387385
388386 public function execute() {
389 - if( !$this->status->isOK() ) {
 387+ if ( !$this->status->isOK() ) {
390388 return $this->status;
391389 }
392390
393391 $opts = array();
394392 if ( $this->proxy && !$this->no_proxy ) {
395 - $opts['proxy'] = $this->urlToTCP($this->proxy);
 393+ $opts['proxy'] = $this->urlToTCP( $this->proxy );
396394 $opts['request_fulluri'] = true;
397395 }
398396
@@ -412,14 +410,14 @@
413411 $context = stream_context_create( array( 'http' => $opts ) );
414412 try {
415413 $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() );
418416 return $this->status;
419417 }
420418
421419 $result = stream_get_meta_data( $this->fh );
422420 if ( $result['timed_out'] ) {
423 - $this->status->error( __CLASS__ . '::timed-out-in-headers' );
 421+ $this->status->error( 'The request timed out' );
424422 }
425423
426424 $this->headers = $result['wrapper_data'];

Status & tagging log