Index: trunk/phase3/includes/upload/UploadFromUrl.php |
— | — | @@ -78,44 +78,25 @@ |
79 | 79 | if( !self::isValidUrl( $this->mUrl ) ) { |
80 | 80 | return Status::newFatal( 'upload-proto-error' ); |
81 | 81 | } |
82 | | - $res = $this->curlCopy(); |
83 | | - if( $res !== true ) { |
84 | | - return Status::newFatal( $res ); |
85 | | - } |
86 | | - return Status::newGood(); |
87 | | - } |
88 | 82 | |
89 | | - /** |
90 | | - * Safe copy from URL |
91 | | - * Returns true if there was an error, false otherwise |
92 | | - */ |
93 | | - private function curlCopy() { |
94 | | - global $wgOut; |
95 | | - |
96 | 83 | # Open temporary file |
97 | 84 | $this->mCurlDestHandle = @fopen( $this->mTempPath, "wb" ); |
98 | 85 | if( $this->mCurlDestHandle === false ) { |
99 | 86 | # Could not open temporary file to write in |
100 | | - return 'upload-file-error'; |
| 87 | + return Status::newFatal( 'upload-file-error' ); |
101 | 88 | } |
102 | | - |
103 | | - $ch = curl_init(); |
104 | | - curl_setopt( $ch, CURLOPT_HTTP_VERSION, 1.0); # Probably not needed, but apparently can work around some bug |
105 | | - curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout |
106 | | - curl_setopt( $ch, CURLOPT_LOW_SPEED_LIMIT, 512); # 0.5KB per second minimum transfer speed |
107 | | - curl_setopt( $ch, CURLOPT_URL, $this->mUrl); |
108 | | - curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) ); |
109 | | - curl_exec( $ch ); |
110 | | - $error = curl_errno( $ch ); |
111 | | - curl_close( $ch ); |
112 | | - |
| 89 | + |
| 90 | + $options = array( |
| 91 | + 'method' => 'GET', |
| 92 | + 'timeout' => 10, |
| 93 | + ); |
| 94 | + $req = HttpRequest::factory( $this->mUrl, $options ); |
| 95 | + $req->setCallback( array( $this, 'uploadCurlCallback' ) ); |
| 96 | + $status = $req->execute(); |
113 | 97 | fclose( $this->mCurlDestHandle ); |
114 | 98 | unset( $this->mCurlDestHandle ); |
115 | 99 | |
116 | | - if( $error ) |
117 | | - return "upload-curl-error$errornum"; |
118 | | - |
119 | | - return true; |
| 100 | + return $status; |
120 | 101 | } |
121 | 102 | |
122 | 103 | /** |
Index: trunk/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -390,7 +390,7 @@ |
391 | 391 | // Fetch the file if required |
392 | 392 | $status = $this->mUpload->fetchFile(); |
393 | 393 | if( !$status->isOK() ) { |
394 | | - $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) ); |
| 394 | + $this->showUploadError( $wgOut->parse( $status->getWikiText() ) ); |
395 | 395 | return; |
396 | 396 | } |
397 | 397 | |