r53761 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53760‎ | r53761 | r53762 >
Date:20:05, 25 July 2009
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromChunks.php (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -34,10 +34,10 @@
3535
3636 if (!window.onloadFuncts) {
3737 var onloadFuncts = [];
38 -}
39 -
40 -//code that is dependent on js2 functions should use js2AddOnloadHook
41 -function addOnloadHook(hookFunct) {
 38+}
 39+
 40+// code that is dependent on js2 functions should use js2AddOnloadHook
 41+function addOnloadHook(hookFunct) {
4242 // Allows add-on scripts to add onload functions
4343 if(!doneOnloadHook) {
4444 onloadFuncts[onloadFuncts.length] = hookFunct;
Index: trunk/phase3/includes/upload/UploadFromChunks.php
@@ -10,7 +10,7 @@
1111 */
1212 class UploadFromChunks extends UploadBase {
1313
14 - var $chunk_mode; //init, chunk, done
 14+ var $chunk_mode; // init, chunk, done
1515 var $mSessionKey = false;
1616 var $status = array();
1717
@@ -112,7 +112,7 @@
113113 $this->mSessionKey = $this->getSessionKey();
114114 $_SESSION['wsUploadData'][$this->mSessionKey] = array(
115115 'mComment' => $comment,
116 - 'mSummary' => $summary,
 116+ 'mSummary' => $summary,
117117 'mWatch' => $watch,
118118 'mIgnorewarnings' => true, //ignore warning on chunk uploads (for now)
119119 'mFilteredName' => $this->mFilteredName,
@@ -164,7 +164,7 @@
165165 echo ApiFormatJson::getJsonEncode( array(
166166 'uploadUrl' => "{$wgServer}{$wgScriptPath}/api.php?action=upload&".
167167 "token={$token}&format=json&enablechunks=true&chunksessionkey=".
168 - $this->setupChunkSession($summary, $comment, $watch ) ) );
 168+ $this->setupChunkSession( $summary, $comment, $watch ) ) );
169169 exit( 0 );
170170 } else if( $this->chunk_mode == UploadFromChunks::CHUNK ){
171171 $status = $this->doChunkAppend();
Index: trunk/phase3/includes/HttpFunctions.php
@@ -11,7 +11,8 @@
1212 const ASYNC_DOWNLOAD = 2; // asynchronous upload we should spawn out another process and monitor progress if possible)
1313
1414 var $body = '';
15 - public static function request($method, $url, $opts = Array() ){
 15+
 16+ public static function request( $method, $url, $opts = array() ){
1617 $opts['method'] = ( strtoupper( $method ) == 'GET' || strtoupper( $method ) == 'POST' ) ? strtoupper( $method ) : null;
1718 $req = new HttpRequest( $url, $opts );
1819 $status = $req->doRequest();
@@ -22,11 +23,12 @@
2324 return false;
2425 }
2526 }
 27+
2628 /**
2729 * Simple wrapper for Http::request( 'GET' )
2830 */
2931 public static function get( $url, $timeout = false ) {
30 - $opts = Array();
 32+ $opts = array();
3133 if( $timeout )
3234 $opts['timeout'] = $timeout;
3335 return Http::request( 'GET', $url, $opts );
@@ -39,7 +41,7 @@
4042 return Http::request( 'POST', $url, $opts );
4143 }
4244
43 - public static function doDownload( $url, $target_file_path , $dl_mode = self::SYNC_DOWNLOAD , $redirectCount = 0 ){
 45+ public static function doDownload( $url, $target_file_path, $dl_mode = self::SYNC_DOWNLOAD, $redirectCount = 0 ){
4446 global $wgPhpCli, $wgMaxUploadSize, $wgMaxRedirects;
4547 // do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize
4648 $headRequest = new HttpRequest( $url, array( 'headers_only' => true ) );
@@ -53,7 +55,7 @@
5456 if( isset( $head['Location'] ) && strrpos( $head[0], '302' ) !== false ){
5557 if( $redirectCount < $wgMaxRedirects ){
5658 if( UploadFromUrl::isValidURI( $head['Location'] ) ){
57 - return self::doDownload( $head['Location'], $target_file_path , $dl_mode, $redirectCount++ );
 59+ return self::doDownload( $head['Location'], $target_file_path, $dl_mode, $redirectCount++ );
5860 } else {
5961 return Status::newFatal( 'upload-proto-error' );
6062 }
@@ -104,7 +106,7 @@
105107 // store the url and target path:
106108 $_SESSION['wsDownload'][$upload_session_key]['url'] = $url;
107109 $_SESSION['wsDownload'][$upload_session_key]['target_file_path'] = $target_file_path;
108 - //since we request from the cmd line we lose the original host name pass in the session:
 110+ // since we request from the cmd line we lose the original host name pass in the session:
109111 $_SESSION['wsDownload'][$upload_session_key]['orgServer'] = $wgServer;
110112
111113 if( $content_length )
@@ -136,32 +138,33 @@
137139 /**
138140 * used to run a session based download. Is initiated via the shell.
139141 *
140 - * @param $session_id String: the session id to grab download details from
 142+ * @param $session_id String: the session id to grab download details from
141143 * @param $upload_session_key String: the key of the given upload session
142144 * (a given client could have started a few http uploads at once)
143145 */
144146 public static function doSessionIdDownload( $session_id, $upload_session_key ){
145147 global $wgUser, $wgEnableWriteAPI, $wgAsyncHTTPTimeout, $wgServer;
146148 wfDebug( __METHOD__ . "\n\ndoSessionIdDownload:\n\n" );
 149+
147150 // set session to the provided key:
148151 session_id( $session_id );
149152 // start the session
150153 if( session_start() === false ){
151154 wfDebug( __METHOD__ . ' could not start session' );
152155 }
153 - //get all the vars we need from session_id
154 - if(!isset($_SESSION[ 'wsDownload' ][$upload_session_key])){
155 - wfDebug( __METHOD__ .' Error:could not find upload session');
 156+ // get all the vars we need from session_id
 157+ if( !isset( $_SESSION[ 'wsDownload' ][$upload_session_key] ) ){
 158+ wfDebug( __METHOD__ . ' Error:could not find upload session');
156159 exit();
157160 }
158161 // setup the global user from the session key we just inherited
159162 $wgUser = User::newFromSession();
160163
161164 // grab the session data to setup the request:
162 - $sd =& $_SESSION['wsDownload'][$upload_session_key];
163 -
164 - //update the wgServer var ( since cmd line thinks we are localhost when we are really orgServer)
165 - if(isset($sd['orgServer']) && $sd['orgServer']){
 165+ $sd =& $_SESSION['wsDownload'][$upload_session_key];
 166+
 167+ // update the wgServer var ( since cmd line thinks we are localhost when we are really orgServer)
 168+ if( isset( $sd['orgServer'] ) && $sd['orgServer'] ){
166169 $wgServer = $sd['orgServer'];
167170 }
168171 // close down the session so we can other http queries can get session updates:
@@ -173,7 +176,7 @@
174177 'timeout' => $wgAsyncHTTPTimeout
175178 ) );
176179 // run the actual request .. (this can take some time)
177 - wfDebug( __METHOD__ . "do Request: " . $sd['url'] . ' tf: ' . $sd['target_file_path'] );
 180+ wfDebug( __METHOD__ . 'do Request: ' . $sd['url'] . ' tf: ' . $sd['target_file_path'] );
178181 $status = $req->doRequest();
179182 //wfDebug("done with req status is: ". $status->isOK(). ' '.$status->getWikiText(). "\n");
180183
@@ -260,13 +263,14 @@
261264 return "MediaWiki/$wgVersion";
262265 }
263266 }
 267+
264268 class HttpRequest {
265269 var $target_file_path;
266270 var $upload_session_key;
267271
268272 function __construct( $url, $opt ){
269273 global $wgSyncHTTPTimeout;
270 - //double check its a valid url:
 274+ // double check that it's a valid url:
271275 $this->url = $url;
272276
273277 // set the timeout to default sync timeout (unless the timeout option is provided)
@@ -286,8 +290,7 @@
287291 * 'adapter' => 'curl', 'soket'
288292 */
289293 public function doRequest() {
290 -
291 - #make sure we have a valid url
 294+ # Make sure we have a valid url
292295 if( !UploadFromUrl::isValidURI( $this->url ) )
293296 return Status::newFatal('bad-url');
294297
@@ -412,12 +415,12 @@
413416 public function doPhpReq(){
414417 global $wgTitle, $wgHTTPProxy;
415418
416 - #check for php.ini allow_url_fopen
 419+ # Check for php.ini allow_url_fopen
417420 if( !ini_get( 'allow_url_fopen' ) ){
418421 return Status::newFatal( 'allow_url_fopen needs to be enabled for http copy to work' );
419422 }
420423
421 - //start with good status:
 424+ // start with good status:
422425 $status = Status::newGood();
423426
424427 if ( $this->headers_only ) {
@@ -425,8 +428,8 @@
426429 return $status;
427430 }
428431
429 - //setup the headers
430 - $headers = array( "User-Agent: " . Http :: userAgent() );
 432+ // setup the headers
 433+ $headers = array( "User-Agent: " . Http::userAgent() );
431434 if ( is_object( $wgTitle ) ) {
432435 $headers[] = "Referer: ". $wgTitle->getFullURL();
433436 }
@@ -453,25 +456,26 @@
454457 $status = $cwrite->status;
455458 return $status;
456459 }
457 - //read $fh into the simpleFileWriter (grab in 64K chunks since its likely a media file)
458 - while ( !feof( $fh )) {
459 - $contents = fread($fh, 65536);
460 - $cwrite->callbackWriteBody($fh, $contents );
 460+
 461+ // read $fh into the simpleFileWriter (grab in 64K chunks since its likely a media file)
 462+ while ( !feof( $fh ) ) {
 463+ $contents = fread( $fh, 65536 );
 464+ $cwrite->callbackWriteBody( $fh, $contents );
461465 }
462466
463467 $cwrite->close();
464 - //check for simpleFileWriter error:
 468+ // check for simpleFileWriter error:
465469 if( !$cwrite->status->isOK() ){
466470 return $cwrite->status;
467471 }
468472 } else {
469 - //read $fh into status->value
 473+ // read $fh into status->value
470474 $status->value = @stream_get_contents( $fh );
471475 }
472476 //close the url file wrapper
473477 fclose( $fh );
474478
475 - //check for "false"
 479+ // check for "false"
476480 if( $status->value === false ){
477481 $status->error( 'file_get_contents-failed' );
478482 }
@@ -502,7 +506,7 @@
503507 $this->prevTime = time();
504508 }
505509
506 - public function callbackWriteBody($ch, $data_packet){
 510+ public function callbackWriteBody( $ch, $data_packet ){
507511 global $wgMaxUploadSize;
508512
509513 // write out the content

Status & tagging log