r42238 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42237‎ | r42238 | r42239 >
Date:00:16, 20 October 2008
Author:brion
Status:old
Tags:
Comment:
Back out r42188 for now "* Disable this entirely unless curl is available so we don't blow up. Needs a-fixin
* Move the curl calls to http::request() so we can at least start to make this work for the file_get_contents() fallback"

Sticking CURL-specific options in the Http::get call seems unwise as that ties you to a specific backend, assuming Http::get won't change. Further, it seems that if it does use the backend, it just plain won't work -- the returned data will be thrown away instead of saved to the target file.
Modified paths:
  • /trunk/phase3/includes/UploadFromUrl.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/UploadFromUrl.php
@@ -9,7 +9,7 @@
1010 }
1111 static function isEnabled() {
1212 global $wgAllowCopyUploads;
13 - return $wgAllowCopyUploads && parent::isEnabled() && function_exists( 'curl_init' );
 13+ return $wgAllowCopyUploads && parent::isEnabled();
1414 }
1515
1616 function initialize( $name, $url ) {
@@ -53,18 +53,22 @@
5454 # Could not open temporary file to write in
5555 return 'upload-file-error';
5656 }
57 -
58 - $opts = array( CURLOPT_HTTP_VERSION => 1.0,
59 - CURLOPT_LOW_SPEED_LIMIT => 512,
60 - CURLOPT_WRITEFUNCTION => array( $this, 'uploadCurlCallback' )
61 - );
62 - Http::get( $this->mUrl, 10, $opts );
63 -
 57+
 58+ $ch = curl_init();
 59+ curl_setopt( $ch, CURLOPT_HTTP_VERSION, 1.0); # Probably not needed, but apparently can work around some bug
 60+ curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout
 61+ curl_setopt( $ch, CURLOPT_LOW_SPEED_LIMIT, 512); # 0.5KB per second minimum transfer speed
 62+ curl_setopt( $ch, CURLOPT_URL, $this->mUrl);
 63+ curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) );
 64+ curl_exec( $ch );
 65+ $error = curl_errno( $ch );
 66+ curl_close( $ch );
 67+
6468 fclose( $this->mCurlDestHandle );
6569 unset( $this->mCurlDestHandle );
6670
67 - if( $this->curlErrno !== CURLE_OK )
68 - return "upload-curl-error" . $this->curlErrno;
 71+ if( $error )
 72+ return "upload-curl-error$errornum";
6973
7074 return true;
7175 }
@@ -83,7 +87,6 @@
8488 return 0;
8589 }
8690 fwrite( $this->mCurlDestHandle, $data );
87 - $this->curlErrno = curl_errno( $ch );
8891 return $length;
8992 }
9093 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r42188* Disable this entirely unless curl is available so we don't blow up. Needs a...demon00:48, 18 October 2008

Status & tagging log