Index: trunk/phase3/includes/UploadFromUrl.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | } |
11 | 11 | static function isEnabled() { |
12 | 12 | global $wgAllowCopyUploads; |
13 | | - return $wgAllowCopyUploads && parent::isEnabled() && function_exists( 'curl_init' ); |
| 13 | + return $wgAllowCopyUploads && parent::isEnabled(); |
14 | 14 | } |
15 | 15 | |
16 | 16 | function initialize( $name, $url ) { |
— | — | @@ -53,18 +53,22 @@ |
54 | 54 | # Could not open temporary file to write in |
55 | 55 | return 'upload-file-error'; |
56 | 56 | } |
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 | + |
64 | 68 | fclose( $this->mCurlDestHandle ); |
65 | 69 | unset( $this->mCurlDestHandle ); |
66 | 70 | |
67 | | - if( $this->curlErrno !== CURLE_OK ) |
68 | | - return "upload-curl-error" . $this->curlErrno; |
| 71 | + if( $error ) |
| 72 | + return "upload-curl-error$errornum"; |
69 | 73 | |
70 | 74 | return true; |
71 | 75 | } |
— | — | @@ -83,7 +87,6 @@ |
84 | 88 | return 0; |
85 | 89 | } |
86 | 90 | fwrite( $this->mCurlDestHandle, $data ); |
87 | | - $this->curlErrno = curl_errno( $ch ); |
88 | 91 | return $length; |
89 | 92 | } |
90 | 93 | } |