Index: branches/new-upload/phase3/maintenance/findhooks.php |
— | — | @@ -49,8 +49,9 @@ |
50 | 50 | global $doc, $options; |
51 | 51 | $m = array(); |
52 | 52 | if( isset( $options['online'] ) ){ |
53 | | - $content = Http::get( 'http://www.mediawiki.org/w/index.php?title=Manual:Hooks&action=raw' ); |
54 | | - preg_match_all( '/\[\[\/([a-zA-Z0-9-_:]+)\|/', $content, $m ); |
| 53 | + $status = Http::get( 'http://www.mediawiki.org/w/index.php?title=Manual:Hooks&action=raw' ); |
| 54 | + if( $status->isOK() ) |
| 55 | + preg_match_all( '/\[\[\/([a-zA-Z0-9-_:]+)\|/', $status->value, $m ); |
55 | 56 | } else { |
56 | 57 | $content = file_get_contents( $doc ); |
57 | 58 | preg_match_all( "/\n'(.*?)'/", $content, $m ); |
Index: branches/new-upload/phase3/includes/GlobalFunctions.php |
— | — | @@ -2147,23 +2147,8 @@ |
2148 | 2148 | */ |
2149 | 2149 | function wfShellExec( $cmd, &$retval=null ) { |
2150 | 2150 | global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime; |
2151 | | - |
2152 | | - static $disabled; |
2153 | | - if ( is_null( $disabled ) ) { |
2154 | | - $disabled = false; |
2155 | | - if( wfIniGetBool( 'safe_mode' ) ) { |
2156 | | - wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" ); |
2157 | | - $disabled = true; |
2158 | | - } |
2159 | | - $functions = explode( ',', ini_get( 'disable_functions' ) ); |
2160 | | - $functions = array_map( 'trim', $functions ); |
2161 | | - $functions = array_map( 'strtolower', $functions ); |
2162 | | - if ( in_array( 'passthru', $functions ) ) { |
2163 | | - wfDebug( "passthru is in disabled_functions\n" ); |
2164 | | - $disabled = true; |
2165 | | - } |
2166 | | - } |
2167 | | - if ( $disabled ) { |
| 2151 | + |
| 2152 | + if ( ! wfShellExecEnabled() ) { |
2168 | 2153 | $retval = 1; |
2169 | 2154 | return "Unable to run external programs in safe mode."; |
2170 | 2155 | } |
— | — | @@ -2199,8 +2184,25 @@ |
2200 | 2185 | } |
2201 | 2186 | return $output; |
2202 | 2187 | } |
2203 | | - |
2204 | 2188 | /** |
| 2189 | + * Checks if the current instance can execute a shell command |
| 2190 | + * |
| 2191 | + */ |
| 2192 | +function wfShellExecEnabled(){ |
| 2193 | + if( wfIniGetBool( 'safe_mode' ) ) { |
| 2194 | + wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" ); |
| 2195 | + return false; |
| 2196 | + } |
| 2197 | + $functions = explode( ',', ini_get( 'disable_functions' ) ); |
| 2198 | + $functions = array_map( 'trim', $functions ); |
| 2199 | + $functions = array_map( 'strtolower', $functions ); |
| 2200 | + if ( in_array( 'passthru', $functions ) ) { |
| 2201 | + wfDebug( "passthru is in disabled_functions\n" ); |
| 2202 | + return false; |
| 2203 | + } |
| 2204 | + return true; |
| 2205 | +} |
| 2206 | +/** |
2205 | 2207 | * Workaround for http://bugs.php.net/bug.php?id=45132 |
2206 | 2208 | * escapeshellarg() destroys non-ASCII characters if LANG is not a UTF-8 locale |
2207 | 2209 | */ |
— | — | @@ -2597,9 +2599,12 @@ |
2598 | 2600 | * Alias for modularized function |
2599 | 2601 | * @deprecated Use Http::get() instead |
2600 | 2602 | */ |
2601 | | -function wfGetHTTP( $url, $timeout = 'default' ) { |
| 2603 | +function wfGetHTTP( $url ) { |
2602 | 2604 | wfDeprecated(__FUNCTION__); |
2603 | | - return Http::get( $url, $timeout ); |
| 2605 | + $status = Http::get( $url ); |
| 2606 | + if( $status->isOK() ) |
| 2607 | + return $status->value; |
| 2608 | + return null; |
2604 | 2609 | } |
2605 | 2610 | |
2606 | 2611 | /** |
Index: branches/new-upload/phase3/includes/parser/Parser.php |
— | — | @@ -3117,16 +3117,16 @@ |
3118 | 3118 | } |
3119 | 3119 | } |
3120 | 3120 | |
3121 | | - $text = Http::get($url); |
3122 | | - if (!$text) |
| 3121 | + $status = Http::get($url); |
| 3122 | + if ( !$status->isOK() ) |
3123 | 3123 | return wfMsg('scarytranscludefailed', $url); |
3124 | | - |
| 3124 | + |
3125 | 3125 | $dbw = wfGetDB(DB_MASTER); |
3126 | 3126 | $dbw->replace('transcache', array('tc_url'), array( |
3127 | 3127 | 'tc_url' => $url, |
3128 | 3128 | 'tc_time' => time(), |
3129 | | - 'tc_contents' => $text)); |
3130 | | - return $text; |
| 3129 | + 'tc_contents' => $status->value)); |
| 3130 | + return $status->value; |
3131 | 3131 | } |
3132 | 3132 | |
3133 | 3133 | |
Index: branches/new-upload/phase3/includes/filerepo/ForeignAPIRepo.php |
— | — | @@ -89,11 +89,13 @@ |
90 | 90 | $key = wfMemcKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) ); |
91 | 91 | $data = $wgMemc->get( $key ); |
92 | 92 | if( !$data ) { |
93 | | - $data = Http::get( $url ); |
94 | | - if ( !$data ) { |
| 93 | + $status = Http::get( $url ); |
| 94 | + if ( $status->isOK() ) { |
| 95 | + $wgMemc->set( $key, $data, 3600 ); |
| 96 | + }else{ |
| 97 | + //FIXME maybe return status? |
95 | 98 | return null; |
96 | | - } |
97 | | - $wgMemc->set( $key, $data, 3600 ); |
| 99 | + } |
98 | 100 | } |
99 | 101 | |
100 | 102 | if( count( $this->mQueryCache ) > 100 ) { |
— | — | @@ -167,9 +169,12 @@ |
168 | 170 | return $foreignUrl; |
169 | 171 | } |
170 | 172 | $localUrl = $wgServer . $wgUploadPath . '/' . $path . $fileName; |
171 | | - $thumb = Http::get( $foreignUrl ); |
172 | | - # FIXME: Delete old thumbs that aren't being used. Maintenance script? |
173 | | - file_put_contents($wgUploadDirectory . '/' . $path . $fileName, $thumb ); |
| 173 | + //FIXME could use the download to file:: |
| 174 | + $status = Http::doDownload( $foreignUrl, |
| 175 | + $wgUploadDirectory . '/' . $path . $fileName, |
| 176 | + Http::SYNC_DOWNLOAD //need to download right away |
| 177 | + ); |
| 178 | + # FIXME: Delete old thumbs that aren't being used. Maintenance script? |
174 | 179 | $wgMemc->set( $key, $localUrl, $this->apiThumbCacheExpiry ); |
175 | 180 | wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" ); |
176 | 181 | return $localUrl; |
Index: branches/new-upload/phase3/includes/filerepo/File.php |
— | — | @@ -1087,11 +1087,15 @@ |
1088 | 1088 | wfDebug("miss\n"); |
1089 | 1089 | } |
1090 | 1090 | wfDebug( "Fetching shared description from $renderUrl\n" ); |
1091 | | - $res = Http::get( $renderUrl ); |
1092 | | - if ( $res && $this->repo->descriptionCacheExpiry > 0 ) { |
1093 | | - $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); |
| 1091 | + $status = Http::get( $renderUrl ); |
| 1092 | + if( $status->isOK() ){ |
| 1093 | + if ( $status->value && $this->repo->descriptionCacheExpiry > 0 ) { |
| 1094 | + $wgMemc->set( $key, $status->value, $this->repo->descriptionCacheExpiry ); |
| 1095 | + } |
| 1096 | + return $res; |
| 1097 | + }else{ |
| 1098 | + //http get error |
1094 | 1099 | } |
1095 | | - return $res; |
1096 | 1100 | } else { |
1097 | 1101 | return false; |
1098 | 1102 | } |
Index: branches/new-upload/phase3/includes/UploadFromUrl.php |
— | — | @@ -2,6 +2,9 @@ |
3 | 3 | class UploadFromUrl extends UploadBase { |
4 | 4 | protected $mTempDownloadPath; |
5 | 5 | |
| 6 | + //by default do a SYNC_DOWNLOAD |
| 7 | + protected $dl_mode = null; |
| 8 | + |
6 | 9 | static function isAllowed( $user ) { |
7 | 10 | if( !$user->isAllowed( 'upload_by_url' ) ) |
8 | 11 | return 'upload_by_url'; |
— | — | @@ -11,16 +14,24 @@ |
12 | 15 | global $wgAllowCopyUploads; |
13 | 16 | return $wgAllowCopyUploads && parent::isEnabled(); |
14 | 17 | } |
15 | | - |
16 | | - function initialize( $name, $url ) { |
| 18 | + /*entry point for Api upload:: ASYNC_DOWNLOAD (if possible) */ |
| 19 | + function initialize( $name, $url ) { |
17 | 20 | global $wgTmpDirectory; |
| 21 | + |
| 22 | + if(!$this->dl_mode) |
| 23 | + $this->dl_mode = Http::ASYNC_DOWNLOAD; |
| 24 | + |
18 | 25 | $local_file = tempnam( $wgTmpDirectory, 'WEBUPLOAD' ); |
19 | 26 | parent::initialize( $name, $local_file, 0, true ); |
20 | 27 | |
21 | 28 | $this->mUrl = trim( $url ); |
22 | 29 | } |
23 | | - |
24 | | - function initializeFromRequest( &$request ) { |
| 30 | + /*entry point for SpecialUpload no ASYNC_DOWNLOAD possible: */ |
| 31 | + function initializeFromRequest( &$request ) { |
| 32 | + //set dl mode if not set: |
| 33 | + if(!$this->dl_mode) |
| 34 | + $this->dl_mode = Http::SYNC_DOWNLOAD; |
| 35 | + |
25 | 36 | $desiredDestName = $request->getText( 'wpDestFile' ); |
26 | 37 | if( !$desiredDestName ) |
27 | 38 | $desiredDestName = $request->getText( 'wpUploadFile' ); |
— | — | @@ -29,30 +40,17 @@ |
30 | 41 | $request->getVal('wpUploadFileURL') |
31 | 42 | ); |
32 | 43 | } |
33 | | - |
34 | 44 | /** |
35 | 45 | * Do the real fetching stuff |
36 | 46 | */ |
37 | | - function fetchFile() { |
| 47 | + function fetchFile( ) { |
| 48 | + //entry point for SpecialUplaod |
38 | 49 | if( stripos($this->mUrl, 'http://') !== 0 && stripos($this->mUrl, 'ftp://') !== 0 ) { |
39 | | - return array( |
40 | | - 'status' => self::BEFORE_PROCESSING, |
41 | | - 'error' => 'upload-proto-error', |
42 | | - ); |
| 50 | + return Status::newFatal('upload-proto-error'); |
43 | 51 | } |
44 | | - //touch the temporary file: |
45 | | - file_put_contents( $this->mTempPath, '' ); |
46 | | - |
47 | | - //move the empty target to the shared repo: |
48 | | - $status = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath ); |
49 | | - if( $status->isOK() ) { |
50 | | - $this->mTempDownloadPath = $status->value; |
51 | | - }else{ |
52 | | - return $status; |
53 | | - } |
54 | | - //now do the actual download to the shared target: |
55 | | - $status = Http::doDownload ( $this->mUrl, $this->mTempDownloadPath); |
56 | | - |
| 52 | + //print "fetchFile:: $this->dl_mode"; |
| 53 | + //now do the actual download to the shared target: |
| 54 | + $status = Http::doDownload ( $this->mUrl, $this->mTempPath, $this->dl_mode); |
57 | 55 | return $status; |
58 | 56 | |
59 | 57 | /* |
— | — | @@ -116,6 +114,7 @@ |
117 | 115 | return $length; |
118 | 116 | } |
119 | 117 | */ |
| 118 | + //this can be deprecated in favor of http_request2 functions |
120 | 119 | static function isValidRequest( $request ){ |
121 | 120 | if( !$request->getVal('wpUploadFileURL') ) |
122 | 121 | return false; |
Index: branches/new-upload/phase3/includes/api/ApiUpload.php |
— | — | @@ -39,7 +39,6 @@ |
40 | 40 | |
41 | 41 | public function execute() { |
42 | 42 | global $wgUser; |
43 | | - |
44 | 43 | |
45 | 44 | $this->getMain()->requestWriteMode(); |
46 | 45 | $this->mParams = $this->extractRequestParams(); |
— | — | @@ -84,7 +83,7 @@ |
85 | 84 | ); |
86 | 85 | } elseif( isset( $this->mParams['url'] ) ) { |
87 | 86 | $this->mUpload = new UploadFromUrl(); |
88 | | - $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url'] ); |
| 87 | + $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url']); |
89 | 88 | } |
90 | 89 | } |
91 | 90 | |
— | — | @@ -233,6 +232,7 @@ |
234 | 233 | return array ( |
235 | 234 | 'filename' => 'Target filename', |
236 | 235 | 'file' => 'File contents', |
| 236 | + 'chunk'=> 'Chunk File Contents', |
237 | 237 | 'url' => 'Url to upload from', |
238 | 238 | 'comment' => 'Upload comment or initial page text', |
239 | 239 | 'watch' => 'Watch the page', |
Index: branches/new-upload/phase3/includes/PEAR/HTTP/Request2/Adapter/Curl.php |
— | — | @@ -44,7 +44,8 @@ |
45 | 45 | /**
|
46 | 46 | * Base class for HTTP_Request2 adapters
|
47 | 47 | */
|
48 | | -require_once 'HTTP/Request2/Adapter.php';
|
| 48 | +require_once 'HTTP/Request2/Adapter.php'; |
| 49 | +require_once 'HTTP/Request2/Response.php';
|
49 | 50 |
|
50 | 51 | /**
|
51 | 52 | * Adapter for HTTP_Request2 wrapping around cURL extension
|
— | — | @@ -167,14 +168,16 @@ |
168 | 169 | * @return resource a cURL handle, as created by curl_init()
|
169 | 170 | * @throws HTTP_Request2_Exception
|
170 | 171 | */
|
171 | | - protected function createCurlHandle()
|
| 172 | + public function createCurlHandle()
|
172 | 173 | {
|
173 | 174 | $ch = curl_init();
|
174 | 175 |
|
175 | 176 | curl_setopt_array($ch, array(
|
176 | 177 | // setup callbacks
|
177 | 178 | CURLOPT_READFUNCTION => array($this, 'callbackReadBody'),
|
178 | | - // CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
|
| 179 | + |
| 180 | + CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'), |
| 181 | +
|
179 | 182 | CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'),
|
180 | 183 | // disallow redirects
|
181 | 184 | CURLOPT_FOLLOWLOCATION => false,
|
— | — | @@ -325,7 +328,8 @@ |
326 | 329 | * @see HTTP_Request2_Response::parseHeaderLine()
|
327 | 330 | */
|
328 | 331 | protected function callbackWriteHeader($ch, $string)
|
329 | | - {
|
| 332 | + { |
| 333 | + print "called callbackWriteHeader";
|
330 | 334 | // we may receive a second set of headers if doing e.g. digest auth
|
331 | 335 | if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
|
332 | 336 | // don't bother with 100-Continue responses (bug #15785)
|
— | — | @@ -342,9 +346,12 @@ |
343 | 347 | $this->eventReceivedHeaders = false;
|
344 | 348 | $this->response = null;
|
345 | 349 | }
|
346 | | - }
|
347 | | - if (empty($this->response)) {
|
348 | | - $this->response = new HTTP_Request2_Response($string, false, $this->request->getConfig('target-file-path'));
|
| 350 | + } |
| 351 | +
|
| 352 | + if (empty($this->response)) { |
| 353 | + print "going to try to get response:";
|
| 354 | + $this->response = new HTTP_Request2_Response($string, false, $this->request->getConfig('target-file-path')); |
| 355 | + print "ok";
|
349 | 356 | } else {
|
350 | 357 | $this->response->parseHeaderLine($string);
|
351 | 358 | if ('' == trim($string)) {
|
— | — | @@ -354,8 +361,9 @@ |
355 | 362 | }
|
356 | 363 | $this->eventReceivedHeaders = true;
|
357 | 364 | }
|
358 | | - }
|
359 | | - return strlen($string);
|
| 365 | + } |
| 366 | +
|
| 367 | + return strlen($string);
|
360 | 368 | }
|
361 | 369 |
|
362 | 370 | /**
|
— | — | @@ -370,12 +378,15 @@ |
371 | 379 | {
|
372 | 380 | // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
|
373 | 381 | // response doesn't start with proper HTTP status line (see bug #15716)
|
374 | | - if (empty($this->response)) {
|
375 | | - throw new HTTP_Request2_Exception("Malformed response: {$string}");
|
376 | | - }
|
| 382 | + //if (empty($this->response)) {
|
| 383 | + // throw new HTTP_Request2_Exception("Malformed response: {$string}");
|
| 384 | + //}
|
377 | 385 | $this->response->appendBody($string);
|
378 | 386 | $this->request->setLastEvent('receivedBodyPart', $string);
|
379 | 387 | return strlen($string);
|
380 | 388 | }
|
| 389 | +} |
| 390 | +function callbackWriteBody($ch, $string){ |
| 391 | + print 'test write test'; |
381 | 392 | }
|
382 | 393 | ?>
|
Index: branches/new-upload/phase3/includes/HttpFunctions.php |
— | — | @@ -1,56 +1,42 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | | -* simple wrapper / helper PEAR HTTP_Request2 |
6 | | -* http://pear.php.net/package/HTTP_Request2/ |
| 4 | + * HTTP handling class |
| 5 | + * |
7 | 6 | */ |
8 | | -//get our Request2 class: |
9 | | -require_once 'HTTP/Request2.php'; |
10 | 7 | |
| 8 | + |
11 | 9 | class Http { |
| 10 | + const SYNC_DOWNLOAD = 1; //syncronys upload (in a single request) |
| 11 | + const ASYNC_DOWNLOAD = 2; //asynchronous upload we should spawn out another process and monitor progress if possible) |
12 | 12 | /** |
13 | 13 | * Simple wrapper for Http::request( 'GET' ) |
14 | 14 | */ |
15 | 15 | public static function get( $url, $opts = array() ) { |
16 | 16 | return self::request($url, 'GET', $opts ); |
17 | 17 | } |
18 | | - public static function request( $url, $method = 'GET' , $opts = array()){ |
19 | | - //FIXME do something with the $opts ; |
20 | | - $req = new HTTP_Request2( $url, $method, array( |
21 | | - 'adapter' => self::getAdapter(), |
22 | | - 'user-agent' => self::userAgent() |
23 | | - )); |
24 | | - return self::doRequest( $req ); |
25 | | - } |
26 | | - /** |
27 | | - * does the actual request |
28 | | - * returns false on errors |
29 | | - */ |
30 | | - public static function doRequest( &$req ){ |
31 | | - try{ |
32 | | - return $req->send(); |
33 | | - } catch ( HTTP_Request2_Exception $e ) { |
34 | | - //http error: |
35 | | - wfDebug( __METHOD__ . $e->getMessage() . "\ncode:" . $e->getCode() ); |
36 | | - return false; |
37 | | - } |
38 | | - } |
39 | | - |
40 | | - public static function doDownload( $url, $target_path ){ |
| 18 | + |
| 19 | + public static function doDownload( $url, $target_path , $dl_mode = self::SYNC_DOWNLOAD ){ |
41 | 20 | global $wgPhpCliPath, $wgMaxUploadSize; |
42 | 21 | |
43 | | - //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize if it is no need to try and download it |
| 22 | + //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize to large no need to download it |
44 | 23 | $head = get_headers($url, 1); |
45 | 24 | if(isset($head['Content-Length']) && $head['Content-Length'] > $wgMaxUploadSize){ |
46 | 25 | return Status::newFatal('requested file length ' .$head['Content-Length'] . ' is greater than $wgMaxUploadSize: ' . $wgMaxUploadSize); |
47 | 26 | } |
48 | 27 | |
49 | 28 | //check if we can find phpCliPath (for doing a background shell request to php to do the download: |
50 | | - if( $wgPhpCliPath ){ |
| 29 | + if( $wgPhpCliPath && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD){ |
| 30 | + //setup session |
| 31 | + die('do shell exec'); |
| 32 | + //do shell exec req |
51 | 33 | |
52 | | - }else{ |
| 34 | + //return success status and download_session_key |
| 35 | + |
| 36 | + //(seperate ajax request can now check on the status of the shell exec)... and even kill or cancel it) |
| 37 | + |
| 38 | + }else if( $dl_mode== self::SYNC_DOWNLOAD ){ |
53 | 39 | //else just download as much as we can in the time we have left: |
54 | | - self::doDownloadtoFile(); |
| 40 | + return self::doDownloadtoFile($url, $target_path); |
55 | 41 | } |
56 | 42 | |
57 | 43 | } |
— | — | @@ -62,9 +48,11 @@ |
63 | 49 | public static function initBackgroundDownload( $url ){ |
64 | 50 | global $wgMaxUploadSize; |
65 | 51 | $status = Status::newGood(); |
66 | | - //generate a session id with all the details for the download |
| 52 | + //generate a session id with all the details for the download (pid, target_file ) |
| 53 | + |
| 54 | + //later add in (destName & description) |
67 | 55 | $session_id = session_id(); |
68 | | - print "should spin out a proccess with id: $session_id\n"; |
| 56 | + print "should spin out a process with id: $session_id\n"; |
69 | 57 | //maintenance/http_download.php passing it a upload session_id |
70 | 58 | |
71 | 59 | //return status |
— | — | @@ -81,23 +69,18 @@ |
82 | 70 | public static function doDownloadtoFile($url, $target_file_path){ |
83 | 71 | global $wgCopyUploadTimeout; |
84 | 72 | |
85 | | - if(is_file($target_file_path)){ |
86 | | - $req = new HTTP_Request2( $url, 'GET', array( |
87 | | - 'adapter' => self::getAdapter(), |
88 | | - 'user-agent' => self::userAgent(), |
89 | | - 'connect_timeout' => $wgCopyUploadTimeout, |
90 | | - 'target_file_path' => $target_file_path |
91 | | - )); |
92 | | - } |
93 | | - self::doRequest( $req ); |
94 | | - print "GOT FILE of size: " . filesize( $target_file_path ) . "\n"; |
95 | | - return true; |
| 73 | + $status = self::request( $url, array( |
| 74 | + 'target_file'=> $target_file_path |
| 75 | + ) ); |
| 76 | + //print "downloading to FILE target: $target_file_path " . filesize( $target_file_path ) . "\n"; |
| 77 | + return Status::newGood('upload-ok'); |
96 | 78 | } |
97 | 79 | /** |
98 | 80 | * Simple wrapper for Http::request( 'POST' ) |
99 | 81 | */ |
100 | | - public static function post( $url, $timeout = 'default', $opts = array() ) { |
101 | | - return Http::request( "POST", $url, $timeout, $opts ); |
| 82 | + public static function post( $url, $opts = array() ) { |
| 83 | + $opts['method']='POST'; |
| 84 | + return Http::request( $url, $opts ); |
102 | 85 | } |
103 | 86 | /* |
104 | 87 | * sets the remote adapter (we prefer curl) could add a config var if we want. |
— | — | @@ -111,38 +94,41 @@ |
112 | 95 | } |
113 | 96 | /** |
114 | 97 | * Get the contents of a file by HTTP |
115 | | - * @param $method string HTTP method. Usually GET/POST |
116 | | - * @param $url string Full URL to act on |
117 | | - * @param $timeout int Seconds to timeout. 'default' falls to $wgHTTPTimeout |
118 | | - * @param $curlOptions array Optional array of extra params to pass |
119 | | - * to curl_setopt() |
| 98 | + * @param $url string Full URL to act on |
| 99 | + * @param $Opt associative array Optional array of options: |
| 100 | + * 'method' => 'GET', 'POST' etc. |
| 101 | + * 'target_file' => if curl should output to a target file |
| 102 | + * 'adapter' => 'curl', 'soket' |
120 | 103 | */ |
121 | | - /*public static function request( $method, $url, $timeout = 'default', $curlOptions = array() ) { |
| 104 | + public static function request( $url, $opt = array() ) { |
122 | 105 | global $wgHTTPTimeout, $wgHTTPProxy, $wgTitle; |
| 106 | + //set defaults: |
| 107 | + $method = (isset($opt['method']))?$opt['method']:'GET'; |
| 108 | + $target_file = (isset($opt['target_file']))?$opt['target_file']:false; |
| 109 | + |
| 110 | + $status = Status::newGood(); |
123 | 111 | |
124 | | - // Go ahead and set the timeout if not otherwise specified |
125 | | - if ( $timeout == 'default' ) { |
126 | | - $timeout = $wgHTTPTimeout; |
127 | | - } |
128 | | - |
129 | 112 | wfDebug( __METHOD__ . ": $method $url\n" ); |
130 | 113 | # Use curl if available |
131 | 114 | if ( function_exists( 'curl_init' ) ) { |
132 | 115 | $c = curl_init( $url ); |
| 116 | + |
| 117 | + //proxy setup: |
133 | 118 | if ( self::isLocalURL( $url ) ) { |
134 | 119 | curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' ); |
135 | 120 | } else if ($wgHTTPProxy) { |
136 | 121 | curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy); |
137 | 122 | } |
138 | 123 | |
139 | | - curl_setopt( $c, CURLOPT_TIMEOUT, $timeout ); |
| 124 | + curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPTimeout ); |
140 | 125 | curl_setopt( $c, CURLOPT_USERAGENT, self :: userAgent() ); |
| 126 | + |
141 | 127 | if ( $method == 'POST' ) { |
142 | 128 | curl_setopt( $c, CURLOPT_POST, true ); |
143 | 129 | curl_setopt( $c, CURLOPT_POSTFIELDS, '' ); |
144 | | - } |
145 | | - else |
| 130 | + }else{ |
146 | 131 | curl_setopt( $c, CURLOPT_CUSTOMREQUEST, $method ); |
| 132 | + } |
147 | 133 | |
148 | 134 | # Set the referer to $wgTitle, even in command-line mode |
149 | 135 | # This is useful for interwiki transclusion, where the foreign |
— | — | @@ -152,12 +138,7 @@ |
153 | 139 | if ( is_object( $wgTitle ) ) { |
154 | 140 | curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() ); |
155 | 141 | } |
156 | | - |
157 | | - if ( is_array( $curlOptions ) ) { |
158 | | - foreach( $curlOptions as $option => $value ) { |
159 | | - curl_setopt( $c, $option, $value ); |
160 | | - } |
161 | | - } |
| 142 | + |
162 | 143 | |
163 | 144 | ob_start(); |
164 | 145 | curl_exec( $c ); |
— | — | @@ -179,7 +160,7 @@ |
180 | 161 | } |
181 | 162 | curl_close( $c ); |
182 | 163 | } else { |
183 | | - # Otherwise use file_get_contents... |
| 164 | + # Otherwise use file_get_contents... |
184 | 165 | # This doesn't have local fetch capabilities... |
185 | 166 | |
186 | 167 | $headers = array( "User-Agent: " . self :: userAgent() ); |
— | — | @@ -194,10 +175,17 @@ |
195 | 176 | 'timeout' => $timeout ) ); |
196 | 177 | $ctx = stream_context_create($opts); |
197 | 178 | |
198 | | - $text = file_get_contents( $url, false, $ctx ); |
| 179 | + $status->value = file_get_contents( $url, false, $ctx ); |
| 180 | + if(!$status->value){ |
| 181 | + $status->error('file_get_contents-failed'); |
| 182 | + } |
199 | 183 | } |
200 | | - return $text; |
201 | | - }*/ |
| 184 | + if(!$target_file){ |
| 185 | + return $status; |
| 186 | + }else{ |
| 187 | + return true; |
| 188 | + } |
| 189 | + } |
202 | 190 | |
203 | 191 | /** |
204 | 192 | * Check if the URL can be served by localhost |
Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -140,6 +140,8 @@ |
141 | 141 | * Do the upload |
142 | 142 | * Checks are made in SpecialUpload::execute() |
143 | 143 | * |
| 144 | + * FIXME this should really use the standard Status class (instead of associative array) |
| 145 | + * |
144 | 146 | * @access private |
145 | 147 | */ |
146 | 148 | function processUpload(){ |
— | — | @@ -152,10 +154,8 @@ |
153 | 155 | break; |
154 | 156 | |
155 | 157 | case UploadBase::BEFORE_PROCESSING: |
156 | | - // Do... nothing? Why? |
157 | | - // In fact we should do something because this is where curl errors and similar live |
| 158 | + $this->uploadError( $details['error'] ); |
158 | 159 | break; |
159 | | - |
160 | 160 | case UploadBase::LARGE_FILE_SERVER: |
161 | 161 | $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) ); |
162 | 162 | break; |
— | — | @@ -252,12 +252,13 @@ |
253 | 253 | if( $permErrors !== true ) { |
254 | 254 | return array( 'status' => UploadBase::PROTECTED_PAGE, 'permissionserrors' => $permErrors ); |
255 | 255 | } |
256 | | - |
| 256 | + |
257 | 257 | // Fetch the file if required |
258 | | - $result = $this->mUpload->fetchFile(); |
259 | | - if( $result != UploadBase::OK ) |
260 | | - return $result; |
261 | | - |
| 258 | + $status = $this->mUpload->fetchFile(); |
| 259 | + if( !$status->isOK() ){ |
| 260 | + return array( 'status' =>UploadBase::BEFORE_PROCESSING, 'error'=>$status->getWikiText() ); |
| 261 | + } |
| 262 | + |
262 | 263 | // Check whether this is a sane upload |
263 | 264 | $result = $this->mUpload->verifyUpload(); |
264 | 265 | if( $result != UploadBase::OK ) |
Index: branches/new-upload/phase3/includes/Import.php |
— | — | @@ -354,15 +354,16 @@ |
355 | 355 | |
356 | 356 | // @fixme! |
357 | 357 | $src = $this->getSrc(); |
358 | | - $data = Http::get( $src ); |
359 | | - if( !$data ) { |
360 | | - wfDebug( "IMPORT: couldn't fetch source $src\n" ); |
361 | | - fclose( $f ); |
362 | | - unlink( $tempo ); |
363 | | - return false; |
| 358 | + $status = Http::get( $src ); |
| 359 | + if( !$status->isOK() ){ |
| 360 | + if( !$data ) { |
| 361 | + wfDebug( "IMPORT: couldn't fetch source $src\n" ); |
| 362 | + fclose( $f ); |
| 363 | + unlink( $tempo ); |
| 364 | + return false; |
| 365 | + } |
364 | 366 | } |
365 | | - |
366 | | - fwrite( $f, $data ); |
| 367 | + fwrite( $f, $status->value ); |
367 | 368 | fclose( $f ); |
368 | 369 | |
369 | 370 | return $tempo; |