r58291 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58290‎ | r58291 | r58292 >
Date:22:23, 28 October 2009
Author:btongminh
Status:ok
Tags:
Comment:
* Validate sessionkey for stashed uploads
* (bug 21235) Switch around fetchfileerror to the proper order
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiUpload.php
@@ -73,11 +73,13 @@
7474 if( isset( $status['error'] ) )
7575 $this->dieUsageMsg( $status['error'] );
7676
77 - } elseif ( isset( $this->mParams['internalhttpsession'] ) && $this->mParams['internalhttpsession'] ) {
 77+ } elseif ( !empty( $this->mParams['internalhttpsession'] ) ) {
 78+ /**
 79+ * Internal http mode
 80+ */
 81+
7882 $sd = & $_SESSION['wsDownload'][ $this->mParams['internalhttpsession'] ];
7983
80 - //wfDebug("InternalHTTP:: " . print_r($this->mParams, true));
81 - // get the params from the init session:
8284 $this->mUpload = new UploadFromFile();
8385
8486 $this->mUpload->initialize( $this->mParams['filename'],
@@ -113,6 +115,10 @@
114116 /**
115117 * Upload stashed in a previous request
116118 */
 119+ // Check the session key
 120+ if( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) )
 121+ return $this->dieUsageMsg( array( 'invalid-session-key' ) );
 122+
117123 $this->mUpload = new UploadFromStash();
118124 $this->mUpload->initialize( $this->mParams['filename'],
119125 $_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
@@ -148,7 +154,7 @@
149155
150156 $status = $this->mUpload->fetchFile();
151157 if( !$status->isOK() ) {
152 - return $this->dieUsage( 'fetchfileerror', $status->getWikiText() );
 158+ return $this->dieUsage( $status->getWikiText(), 'fetchfileerror' );
153159 }
154160
155161 // check if we doing a async request set session info and return the upload_session_key)
@@ -164,8 +170,8 @@
165171 $sd['mParams'] = $this->mParams;
166172
167173 return $this->getResult()->addValue( null, $this->getModuleName(),
168 - array( 'upload_session_key' => $upload_session_key
169 - ));
 174+ array( 'upload_session_key' => $upload_session_key )
 175+ );
170176 }
171177 }
172178 }
@@ -193,6 +199,7 @@
194200 // Perform the upload
195201 $result = $this->performUpload();
196202 // Cleanup any temporary mess
 203+ // FIXME: This should be in a try .. finally block with performUpload
197204 $this->mUpload->cleanupTempFile();
198205 $this->getResult()->addValue( null, $this->getModuleName(), $result );
199206 }

Status & tagging log