r57938 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57937‎ | r57938 | r57939 >
Date:00:25, 20 October 2009
Author:dale
Status:deferred
Tags:
Comment:
* set the --wiki to wfWikiId
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HttpFunctions.php
@@ -13,7 +13,7 @@
1414 var $body = '';
1515
1616 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' )
1818 ? strtoupper( $method ) : null;
1919 $req = HttpRequest::newRequest( $url, $opts );
2020 $status = $req->doRequest();
@@ -42,7 +42,7 @@
4343 return Http::request( 'POST', $url, $opts );
4444 }
4545
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,
4747 $redirectCount = 0 )
4848 {
4949 global $wgPhpCli, $wgMaxUploadSize, $wgMaxRedirects;
@@ -56,9 +56,9 @@
5757
5858 // check for redirects:
5959 if( isset( $head['Location'] ) && strrpos( $head[0], '302' ) !== false ) {
60 - if( $redirectCount < $wgMaxRedirects ) {
 60+ if( $redirectCount < $wgMaxRedirects ) {
6161 if( self::isValidURI( $head['Location'] ) ) {
62 - return self::doDownload( $head['Location'], $target_file_path,
 62+ return self::doDownload( $head['Location'], $target_file_path,
6363 $dl_mode, $redirectCount++ );
6464 } else {
6565 return Status::newFatal( 'upload-proto-error' );
@@ -75,12 +75,12 @@
7676 $content_length = ( isset( $head['Content-Length'] ) ) ? $head['Content-Length'] : null;
7777 if( $content_length ) {
7878 if( $content_length > $wgMaxUploadSize ) {
79 - return Status::newFatal( 'requested file length ' . $content_length .
 79+ return Status::newFatal( 'requested file length ' . $content_length .
8080 ' is greater than $wgMaxUploadSize: ' . $wgMaxUploadSize );
8181 }
8282 }
8383
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
8585 // php to do the download:
8686 if( $wgPhpCli && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD ) {
8787 wfDebug( __METHOD__ . "\nASYNC_DOWNLOAD\n" );
@@ -101,8 +101,8 @@
102102 * should write to a file location and give updates
103103 *
104104 */
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 )
107107 {
108108 global $wgMaxUploadSize, $IP, $wgPhpCli, $wgServer;
109109 $status = Status::newGood();
@@ -124,14 +124,14 @@
125125 $_SESSION['wsDownload'][$upload_session_key]['loaded'] = 0;
126126
127127 // 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();
130130 $pid = wfShellBackgroundExec( $cmd );
131131 // the pid is not of much use since we won't be visiting this same apache any-time soon.
132132 if( !$pid )
133133 return Status::newFatal( 'could not run background shell exec' );
134134
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
136136 // check on the status of the upload)
137137 $status->value = $upload_session_key;
138138
@@ -176,12 +176,12 @@
177177 // grab the session data to setup the request:
178178 $sd =& $_SESSION['wsDownload'][$upload_session_key];
179179
180 - // update the wgServer var ( since cmd line thinks we are localhost
 180+ // update the wgServer var ( since cmd line thinks we are localhost
181181 // when we are really orgServer)
182182 if( isset( $sd['orgServer'] ) && $sd['orgServer'] ) {
183183 $wgServer = $sd['orgServer'];
184184 }
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
186186 // updates: (if not $wgSessionsInMemcached)
187187 if( !$wgSessionsInMemcached )
188188 session_write_close();
@@ -193,7 +193,7 @@
194194 'do_close_session_update' => true
195195 ) );
196196 // 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: ' .
198198 $sd['target_file_path'] . "\n\n");
199199 $status = $req->doRequest();
200200 //wfDebug("done with req status is: ". $status->isOK(). ' '.$status->getWikiText(). "\n");
@@ -285,7 +285,7 @@
286286 global $wgVersion;
287287 return "MediaWiki/$wgVersion";
288288 }
289 -
 289+
290290 /**
291291 * Checks that the given URI is a valid one
292292 * @param $uri Mixed: URI to check for validity
@@ -303,9 +303,9 @@
304304 var $target_file_path;
305305 var $upload_session_key;
306306 function __construct( $url, $opt ){
307 -
 307+
308308 global $wgSyncHTTPTimeout;
309 - $this->url = $url;
 309+ $this->url = $url;
310310 // set the timeout to default sync timeout (unless the timeout option is provided)
311311 $this->timeout = ( isset( $opt['timeout'] ) ) ? $opt['timeout'] : $wgSyncHTTPTimeout;
312312 //check special key default
@@ -314,27 +314,27 @@
315315 }
316316
317317 $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'] ) )
319319 ? $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'] ) )
321321 ? $opt['upload_session_key'] : false;
322322 $this->headers_only = ( isset( $opt['headers_only'] ) ) ? $opt['headers_only'] : false;
323323 $this->do_close_session_update = isset( $opt['do_close_session_update'] );
324324 $this->postData = isset( $opt['postdata'] ) ? $opt['postdata'] : '';
325325
326326 $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+
330330 }
331 -
 331+
332332 public static function newRequest($url, $opt){
333333 # select the handler (use curl if available)
334334 if ( function_exists( 'curl_init' ) ) {
335335 return new curlHttpRequest($url, $opt);
336336 } else {
337337 return new phpHttpRequest($url, $opt);
338 - }
 338+ }
339339 }
340340
341341 /**
@@ -349,12 +349,12 @@
350350 # Make sure we have a valid url
351351 if( !Http::isValidURI( $this->url ) )
352352 return Status::newFatal('bad-url');
353 - //do the actual request:
 353+ //do the actual request:
354354 return $this->doReq();
355355 }
356356 }
357357 class curlHttpRequest extends HttpRequest {
358 - public function doReq(){
 358+ public function doReq(){
359359 global $wgHTTPProxy, $wgTitle;
360360
361361 $status = Status::newGood();
@@ -372,7 +372,7 @@
373373
374374 if($this->ssl_verifyhost)
375375 curl_setopt( $c, CURLOPT_SSL_VERIFYHOST, $this->ssl_verifyhost);
376 -
 376+
377377 if($this->cainfo)
378378 curl_setopt( $c, CURLOPT_CAINFO, $this->cainfo);
379379
@@ -471,7 +471,7 @@
472472 }
473473 }
474474
475 - curl_close( $c );
 475+ curl_close( $c );
476476 // return the result obj
477477 return $status;
478478 }
@@ -513,7 +513,7 @@
514514
515515 // set the write back function (if we are writing to a file)
516516 if( $this->target_file_path ) {
517 - $cwrite = new simpleFileWriter( $this->target_file_path,
 517+ $cwrite = new simpleFileWriter( $this->target_file_path,
518518 $this->upload_session_key, $this->do_close_session_update );
519519 if( !$cwrite->status->isOK() ) {
520520 wfDebug( __METHOD__ . "ERROR in setting up simpleFileWriter\n" );
@@ -521,7 +521,7 @@
522522 return $status;
523523 }
524524
525 - // read $fh into the simpleFileWriter (grab in 64K chunks since
 525+ // read $fh into the simpleFileWriter (grab in 64K chunks since
526526 // it's likely a ~large~ media file)
527527 while ( !feof( $fh ) ) {
528528 $contents = fread( $fh, 65536 );
@@ -557,8 +557,8 @@
558558 var $session_id = null;
559559 var $session_update_interval = 0; // how often to update the session while downloading
560560
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 )
563563 {
564564 $this->target_file_path = $target_file_path;
565565 $this->upload_session_key = $upload_session_key;
@@ -589,7 +589,7 @@
590590
591591 if( $this->current_fsize > $wgMaxUploadSize ) {
592592 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: ' .
594594 'downloaded more than ' .
595595 $wgLang->formatSize( $wgMaxUploadSize ) . ' ' );
596596 return 0;

Status & tagging log