Back out r42188 for now "* Disable this entirely unless curl is available so we don...
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 20 Oct 2008 00:16:29 +0000 (00:16 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 20 Oct 2008 00:16:29 +0000 (00:16 +0000)
* 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.

includes/UploadFromUrl.php

index eb74cc8..7e23b8c 100644 (file)
@@ -9,7 +9,7 @@ class UploadFromUrl extends UploadBase {
        }
        static function isEnabled() {
                global $wgAllowCopyUploads;
-               return $wgAllowCopyUploads && parent::isEnabled() && function_exists( 'curl_init' );
+               return $wgAllowCopyUploads && parent::isEnabled();
        }
        
        function initialize( $name, $url ) {
@@ -53,18 +53,22 @@ class UploadFromUrl extends UploadBase {
                        # Could not open temporary file to write in
                        return 'upload-file-error';
                }
-               
-               $opts = array(  CURLOPT_HTTP_VERSION => 1.0,
-                                               CURLOPT_LOW_SPEED_LIMIT => 512,
-                                               CURLOPT_WRITEFUNCTION => array( $this, 'uploadCurlCallback' )
-                                               );
-               Http::get( $this->mUrl, 10, $opts );
-               
+
+               $ch = curl_init();
+               curl_setopt( $ch, CURLOPT_HTTP_VERSION, 1.0); # Probably not needed, but apparently can work around some bug
+               curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout
+               curl_setopt( $ch, CURLOPT_LOW_SPEED_LIMIT, 512); # 0.5KB per second minimum transfer speed
+               curl_setopt( $ch, CURLOPT_URL, $this->mUrl);
+               curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) );
+               curl_exec( $ch );
+               $error =  curl_errno( $ch );
+               curl_close( $ch );
+
                fclose( $this->mCurlDestHandle );
                unset( $this->mCurlDestHandle );
                
-               if( $this->curlErrno !== CURLE_OK ) 
-                       return "upload-curl-error" . $this->curlErrno;
+               if( $error ) 
+                       return "upload-curl-error$errornum";
 
                return true;
        }
@@ -83,7 +87,6 @@ class UploadFromUrl extends UploadBase {
                        return 0;
                }
                fwrite( $this->mCurlDestHandle, $data );
-               $this->curlErrno = curl_errno( $ch );
                return $length;
        }
 }