Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | var $body = ''; |
15 | 15 | |
16 | 16 | public static function request( $method, $url, $opts = array() ) { |
17 | | - $opts['method'] = ( strtoupper( $method ) == 'GET' || strtoupper( $method ) == 'POST' ) |
| 17 | + $opts['method'] = ( strtoupper( $method ) == 'GET' || strtoupper( $method ) == 'POST' ) |
18 | 18 | ? strtoupper( $method ) : null; |
19 | 19 | $req = HttpRequest::newRequest( $url, $opts ); |
20 | 20 | $status = $req->doRequest(); |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | return Http::request( 'POST', $url, $opts ); |
44 | 44 | } |
45 | 45 | |
46 | | - public static function doDownload( $url, $target_file_path, $dl_mode = self::SYNC_DOWNLOAD, |
| 46 | + public static function doDownload( $url, $target_file_path, $dl_mode = self::SYNC_DOWNLOAD, |
47 | 47 | $redirectCount = 0 ) |
48 | 48 | { |
49 | 49 | global $wgPhpCli, $wgMaxUploadSize, $wgMaxRedirects; |
— | — | @@ -56,9 +56,9 @@ |
57 | 57 | |
58 | 58 | // check for redirects: |
59 | 59 | if( isset( $head['Location'] ) && strrpos( $head[0], '302' ) !== false ) { |
60 | | - if( $redirectCount < $wgMaxRedirects ) { |
| 60 | + if( $redirectCount < $wgMaxRedirects ) { |
61 | 61 | if( self::isValidURI( $head['Location'] ) ) { |
62 | | - return self::doDownload( $head['Location'], $target_file_path, |
| 62 | + return self::doDownload( $head['Location'], $target_file_path, |
63 | 63 | $dl_mode, $redirectCount++ ); |
64 | 64 | } else { |
65 | 65 | return Status::newFatal( 'upload-proto-error' ); |
— | — | @@ -75,12 +75,12 @@ |
76 | 76 | $content_length = ( isset( $head['Content-Length'] ) ) ? $head['Content-Length'] : null; |
77 | 77 | if( $content_length ) { |
78 | 78 | if( $content_length > $wgMaxUploadSize ) { |
79 | | - return Status::newFatal( 'requested file length ' . $content_length . |
| 79 | + return Status::newFatal( 'requested file length ' . $content_length . |
80 | 80 | ' is greater than $wgMaxUploadSize: ' . $wgMaxUploadSize ); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | | - // check if we can find phpCliPath (for doing a background shell request to |
| 84 | + // check if we can find phpCliPath (for doing a background shell request to |
85 | 85 | // php to do the download: |
86 | 86 | if( $wgPhpCli && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD ) { |
87 | 87 | wfDebug( __METHOD__ . "\nASYNC_DOWNLOAD\n" ); |
— | — | @@ -101,8 +101,8 @@ |
102 | 102 | * should write to a file location and give updates |
103 | 103 | * |
104 | 104 | */ |
105 | | - private static function initBackgroundDownload( $url, $target_file_path, |
106 | | - $content_length = null ) |
| 105 | + private static function initBackgroundDownload( $url, $target_file_path, |
| 106 | + $content_length = null ) |
107 | 107 | { |
108 | 108 | global $wgMaxUploadSize, $IP, $wgPhpCli, $wgServer; |
109 | 109 | $status = Status::newGood(); |
— | — | @@ -124,14 +124,14 @@ |
125 | 125 | $_SESSION['wsDownload'][$upload_session_key]['loaded'] = 0; |
126 | 126 | |
127 | 127 | // run the background download request: |
128 | | - $cmd = $wgPhpCli . ' ' . $IP . "/maintenance/http_session_download.php " . |
129 | | - "--sid {$session_id} --usk {$upload_session_key}"; |
| 128 | + $cmd = $wgPhpCli . ' ' . $IP . "/maintenance/http_session_download.php " . |
| 129 | + "--sid {$session_id} --usk {$upload_session_key} --wiki " . wfWikiId(); |
130 | 130 | $pid = wfShellBackgroundExec( $cmd ); |
131 | 131 | // the pid is not of much use since we won't be visiting this same apache any-time soon. |
132 | 132 | if( !$pid ) |
133 | 133 | return Status::newFatal( 'could not run background shell exec' ); |
134 | 134 | |
135 | | - // update the status value with the $upload_session_key (for the user to |
| 135 | + // update the status value with the $upload_session_key (for the user to |
136 | 136 | // check on the status of the upload) |
137 | 137 | $status->value = $upload_session_key; |
138 | 138 | |
— | — | @@ -176,12 +176,12 @@ |
177 | 177 | // grab the session data to setup the request: |
178 | 178 | $sd =& $_SESSION['wsDownload'][$upload_session_key]; |
179 | 179 | |
180 | | - // update the wgServer var ( since cmd line thinks we are localhost |
| 180 | + // update the wgServer var ( since cmd line thinks we are localhost |
181 | 181 | // when we are really orgServer) |
182 | 182 | if( isset( $sd['orgServer'] ) && $sd['orgServer'] ) { |
183 | 183 | $wgServer = $sd['orgServer']; |
184 | 184 | } |
185 | | - // close down the session so we can other http queries can get session |
| 185 | + // close down the session so we can other http queries can get session |
186 | 186 | // updates: (if not $wgSessionsInMemcached) |
187 | 187 | if( !$wgSessionsInMemcached ) |
188 | 188 | session_write_close(); |
— | — | @@ -193,7 +193,7 @@ |
194 | 194 | 'do_close_session_update' => true |
195 | 195 | ) ); |
196 | 196 | // run the actual request .. (this can take some time) |
197 | | - wfDebug( __METHOD__ . 'do Session Download :: ' . $sd['url'] . ' tf: ' . |
| 197 | + wfDebug( __METHOD__ . 'do Session Download :: ' . $sd['url'] . ' tf: ' . |
198 | 198 | $sd['target_file_path'] . "\n\n"); |
199 | 199 | $status = $req->doRequest(); |
200 | 200 | //wfDebug("done with req status is: ". $status->isOK(). ' '.$status->getWikiText(). "\n"); |
— | — | @@ -285,7 +285,7 @@ |
286 | 286 | global $wgVersion; |
287 | 287 | return "MediaWiki/$wgVersion"; |
288 | 288 | } |
289 | | - |
| 289 | + |
290 | 290 | /** |
291 | 291 | * Checks that the given URI is a valid one |
292 | 292 | * @param $uri Mixed: URI to check for validity |
— | — | @@ -303,9 +303,9 @@ |
304 | 304 | var $target_file_path; |
305 | 305 | var $upload_session_key; |
306 | 306 | function __construct( $url, $opt ){ |
307 | | - |
| 307 | + |
308 | 308 | global $wgSyncHTTPTimeout; |
309 | | - $this->url = $url; |
| 309 | + $this->url = $url; |
310 | 310 | // set the timeout to default sync timeout (unless the timeout option is provided) |
311 | 311 | $this->timeout = ( isset( $opt['timeout'] ) ) ? $opt['timeout'] : $wgSyncHTTPTimeout; |
312 | 312 | //check special key default |
— | — | @@ -314,27 +314,27 @@ |
315 | 315 | } |
316 | 316 | |
317 | 317 | $this->method = ( isset( $opt['method'] ) ) ? $opt['method'] : 'GET'; |
318 | | - $this->target_file_path = ( isset( $opt['target_file_path'] ) ) |
| 318 | + $this->target_file_path = ( isset( $opt['target_file_path'] ) ) |
319 | 319 | ? $opt['target_file_path'] : false; |
320 | | - $this->upload_session_key = ( isset( $opt['upload_session_key'] ) ) |
| 320 | + $this->upload_session_key = ( isset( $opt['upload_session_key'] ) ) |
321 | 321 | ? $opt['upload_session_key'] : false; |
322 | 322 | $this->headers_only = ( isset( $opt['headers_only'] ) ) ? $opt['headers_only'] : false; |
323 | 323 | $this->do_close_session_update = isset( $opt['do_close_session_update'] ); |
324 | 324 | $this->postData = isset( $opt['postdata'] ) ? $opt['postdata'] : ''; |
325 | 325 | |
326 | 326 | $this->ssl_verifyhost = (isset( $opt['ssl_verifyhost'] ))? $opt['ssl_verifyhost']: false; |
327 | | - |
328 | | - $this->cainfo = (isset( $opt['cainfo'] ))? $op['cainfo']: false; |
329 | | - |
| 327 | + |
| 328 | + $this->cainfo = (isset( $opt['cainfo'] ))? $op['cainfo']: false; |
| 329 | + |
330 | 330 | } |
331 | | - |
| 331 | + |
332 | 332 | public static function newRequest($url, $opt){ |
333 | 333 | # select the handler (use curl if available) |
334 | 334 | if ( function_exists( 'curl_init' ) ) { |
335 | 335 | return new curlHttpRequest($url, $opt); |
336 | 336 | } else { |
337 | 337 | return new phpHttpRequest($url, $opt); |
338 | | - } |
| 338 | + } |
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
— | — | @@ -349,12 +349,12 @@ |
350 | 350 | # Make sure we have a valid url |
351 | 351 | if( !Http::isValidURI( $this->url ) ) |
352 | 352 | return Status::newFatal('bad-url'); |
353 | | - //do the actual request: |
| 353 | + //do the actual request: |
354 | 354 | return $this->doReq(); |
355 | 355 | } |
356 | 356 | } |
357 | 357 | class curlHttpRequest extends HttpRequest { |
358 | | - public function doReq(){ |
| 358 | + public function doReq(){ |
359 | 359 | global $wgHTTPProxy, $wgTitle; |
360 | 360 | |
361 | 361 | $status = Status::newGood(); |
— | — | @@ -372,7 +372,7 @@ |
373 | 373 | |
374 | 374 | if($this->ssl_verifyhost) |
375 | 375 | curl_setopt( $c, CURLOPT_SSL_VERIFYHOST, $this->ssl_verifyhost); |
376 | | - |
| 376 | + |
377 | 377 | if($this->cainfo) |
378 | 378 | curl_setopt( $c, CURLOPT_CAINFO, $this->cainfo); |
379 | 379 | |
— | — | @@ -471,7 +471,7 @@ |
472 | 472 | } |
473 | 473 | } |
474 | 474 | |
475 | | - curl_close( $c ); |
| 475 | + curl_close( $c ); |
476 | 476 | // return the result obj |
477 | 477 | return $status; |
478 | 478 | } |
— | — | @@ -513,7 +513,7 @@ |
514 | 514 | |
515 | 515 | // set the write back function (if we are writing to a file) |
516 | 516 | if( $this->target_file_path ) { |
517 | | - $cwrite = new simpleFileWriter( $this->target_file_path, |
| 517 | + $cwrite = new simpleFileWriter( $this->target_file_path, |
518 | 518 | $this->upload_session_key, $this->do_close_session_update ); |
519 | 519 | if( !$cwrite->status->isOK() ) { |
520 | 520 | wfDebug( __METHOD__ . "ERROR in setting up simpleFileWriter\n" ); |
— | — | @@ -521,7 +521,7 @@ |
522 | 522 | return $status; |
523 | 523 | } |
524 | 524 | |
525 | | - // read $fh into the simpleFileWriter (grab in 64K chunks since |
| 525 | + // read $fh into the simpleFileWriter (grab in 64K chunks since |
526 | 526 | // it's likely a ~large~ media file) |
527 | 527 | while ( !feof( $fh ) ) { |
528 | 528 | $contents = fread( $fh, 65536 ); |
— | — | @@ -557,8 +557,8 @@ |
558 | 558 | var $session_id = null; |
559 | 559 | var $session_update_interval = 0; // how often to update the session while downloading |
560 | 560 | |
561 | | - function simpleFileWriter( $target_file_path, $upload_session_key, |
562 | | - $do_close_session_update = false ) |
| 561 | + function simpleFileWriter( $target_file_path, $upload_session_key, |
| 562 | + $do_close_session_update = false ) |
563 | 563 | { |
564 | 564 | $this->target_file_path = $target_file_path; |
565 | 565 | $this->upload_session_key = $upload_session_key; |
— | — | @@ -589,7 +589,7 @@ |
590 | 590 | |
591 | 591 | if( $this->current_fsize > $wgMaxUploadSize ) { |
592 | 592 | wfDebug( __METHOD__ . " ::http download too large\n" ); |
593 | | - $this->status = Status::newFatal( 'HTTP::file-has-grown-beyond-upload-limit-killing: ' . |
| 593 | + $this->status = Status::newFatal( 'HTTP::file-has-grown-beyond-upload-limit-killing: ' . |
594 | 594 | 'downloaded more than ' . |
595 | 595 | $wgLang->formatSize( $wgMaxUploadSize ) . ' ' ); |
596 | 596 | return 0; |