From 0a7d4476da5f5e25828ce14a19f145d755b2c0cd Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sat, 18 Oct 2008 00:48:33 +0000 Subject: [PATCH] * 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 --- includes/UploadFromUrl.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/includes/UploadFromUrl.php b/includes/UploadFromUrl.php index 7e23b8cd37..eb74cc8f0b 100644 --- a/includes/UploadFromUrl.php +++ b/includes/UploadFromUrl.php @@ -9,7 +9,7 @@ class UploadFromUrl extends UploadBase { } static function isEnabled() { global $wgAllowCopyUploads; - return $wgAllowCopyUploads && parent::isEnabled(); + return $wgAllowCopyUploads && parent::isEnabled() && function_exists( 'curl_init' ); } function initialize( $name, $url ) { @@ -53,22 +53,18 @@ class UploadFromUrl extends UploadBase { # Could not open temporary file to write in return 'upload-file-error'; } - - $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 ); - + + $opts = array( CURLOPT_HTTP_VERSION => 1.0, + CURLOPT_LOW_SPEED_LIMIT => 512, + CURLOPT_WRITEFUNCTION => array( $this, 'uploadCurlCallback' ) + ); + Http::get( $this->mUrl, 10, $opts ); + fclose( $this->mCurlDestHandle ); unset( $this->mCurlDestHandle ); - if( $error ) - return "upload-curl-error$errornum"; + if( $this->curlErrno !== CURLE_OK ) + return "upload-curl-error" . $this->curlErrno; return true; } @@ -87,6 +83,7 @@ class UploadFromUrl extends UploadBase { return 0; } fwrite( $this->mCurlDestHandle, $data ); + $this->curlErrno = curl_errno( $ch ); return $length; } } -- 2.20.1