r61407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61406‎ | r61407 | r61408 >
Date:05:20, 23 January 2010
Author:mah
Status:deferred (Comments)
Tags:
Comment:
follow up r61355
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromChunks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromChunks.php
@@ -42,13 +42,10 @@
4343 throw new MWException( 'not implemented' );
4444 }
4545
46 - public function initialize( &$request ) {
47 - $done = $request->getText( 'done' );
48 - $filename = $request->getText( 'filename' );
49 - $sessionKey = $request->getText( 'chunksessionkey' );
 46+ public function initialize( $done, $filename, $sessionKey, $path,
 47+ $fileSize, $sessionData ) {
 48+ $this->initFromSessionKey( $sessionKey, $sessionData );
5049
51 - $this->initFromSessionKey( $sessionKey, $request );
52 -
5350 if ( !$this->sessionKey && !$done ) {
5451 // session key not set, init the chunk upload system:
5552 $this->chunkMode = self::INIT;
@@ -60,8 +57,8 @@
6158 }
6259
6360 if ( $this->chunkMode == self::CHUNK || $this->chunkMode == self::DONE ) {
64 - $this->mTempPath = $request->getFileTempName( 'chunk' );
65 - $this->fileSize += $request->getFileSize( 'chunk' );
 61+ $this->mTempPath = $path;
 62+ $this->fileSize += $fileSize;
6663 }
6764 }
6865
@@ -94,14 +91,12 @@
9592 *
9693 * @returns void
9794 */
98 - protected function initFromSessionKey( $sessionKey, $request ) {
 95+ protected function initFromSessionKey( $sessionKey, $sessionData ) {
9996 if ( !$sessionKey || empty( $sessionKey ) ) {
10097 $this->status = Status::newFromFatal( 'Missing session data.' );
10198 return;
10299 }
103100 $this->sessionKey = $sessionKey;
104 - // load the sessionData array:
105 - $sessionData = $request->getSessionData( 'wsUploadData' );
106101
107102 if ( isset( $sessionData[$this->sessionKey]['version'] )
108103 && $sessionData[$this->sessionKey]['version'] == self::SESSION_VERSION ) {
@@ -124,7 +119,7 @@
125120 */
126121 public function performUpload( $comment, $pageText, $watch, $user ) {
127122 wfDebug( "\n\n\performUpload(chunked): sum:" . $comment . ' c: ' . $pageText . ' w:' . $watch );
128 - global $wgUser;
 123+ global $wgUser, $wgOut;
129124
130125 if ( $this->chunkMode == self::INIT ) {
131126 // firefogg expects a specific result per:
@@ -140,7 +135,7 @@
141136 'uploadUrl' => wfExpandUrl( wfScript( 'api' ) ) . "?action=upload&" .
142137 "token={$token}&format=json&enablechunks=true&chunksessionkey=" .
143138 $this->setupChunkSession( $comment, $pageText, $watch ) ) );
144 - exit( 0 );
 139+ $wgOut->disable();
145140 } else if ( $this->chunkMode == self::CHUNK ) {
146141 $status = $this->appendChunk();
147142 if ( !$status->isOK() ) {
@@ -153,7 +148,7 @@
154149 echo FormatJson::encode(
155150 array( 'result' => 1, 'filesize' => $this->fileSize )
156151 );
157 - exit( 0 );
 152+ $wgOut->disable();
158153 } else if ( $this->chunkMode == self::DONE ) {
159154 if ( $comment == '' )
160155 $comment = $this->comment;
@@ -178,7 +173,7 @@
179174 'done' => 1,
180175 'resultUrl' => $file->getDescriptionUrl() )
181176 );
182 - exit( 0 );
 177+ $wgOut->disable();
183178 }
184179 }
185180
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -84,7 +84,13 @@
8585 // Initialize $this->mUpload
8686 if ( $this->mParams['enablechunks'] ) {
8787 $this->mUpload = new UploadFromChunks();
88 - $this->mUpload->initialize( $request );
 88+ $this->mUpload->initialize
 89+ ( $request->getText( 'done' ),
 90+ $request->getText( 'filename' ),
 91+ $request->getText( 'chunksessionkey' ),
 92+ $request->getFileTempName( 'chunk' ),
 93+ $request->getFileSize( 'chunk' ),
 94+ $request->getSessionData( 'wsUploadData' ) );
8995
9096 if ( !$this->mUpload->status->isOK() ) {
9197 return $this->dieUsageMsg( $this->mUpload->status->getWikiText(),
@@ -278,7 +284,7 @@
279285 'watch' => false,
280286 'ignorewarnings' => false,
281287 'file' => null,
282 - 'enablechunks' => null,
 288+ 'enablechunks' => false,
283289 'chunksessionkey' => null,
284290 'chunk' => null,
285291 'done' => false,
@@ -302,6 +308,9 @@
303309 'ignorewarnings' => 'Ignore any warnings',
304310 'file' => 'File contents',
305311 'enablechunks' => 'Set to use chunk mode; see http://firefogg.org/dev/chunk_post.html for protocol',
 312+ 'chunksessionkey' => 'The session key, established on the first contact during the chunked upload',
 313+ 'chunk' => 'The data in this chunk of a chunked upload',
 314+ 'done' => 'Set to 1 on the last chunk of a chunked upload',
306315 'url' => 'Url to fetch the file from',
307316 'sessionkey' => array(
308317 'Session key returned by a previous upload that failed due to warnings',

Follow-up revisions

RevisionCommit summaryAuthorDate
r61415Fix indentation in r61407. PLEASE don't use spaces for indentation, always us...catrope15:09, 23 January 2010
r62164follow up r61407...mah03:54, 9 February 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61355UploadChunks added from js2 branch. Refactored. Still needs to be...mah04:37, 22 January 2010

Comments

#Comment by Platonides (talk | contribs)   20:42, 1 February 2010

UploadFromChunks extends UploadBase

UploadBase::initialize( $name, $tempPath, $fileSize, $removeTempFile = false )

UploadFromChunks::initialize( $done, $filename, $sessionKey, $path, $fileSize, $sessionData )


We shouldn't have a completely different prototype in the child class (the original initialize which took a &$request was equally wrong, it should have been initializeFromRequest instead of the throwing one, or have a completely different name).


#Comment by Tim Starling (talk | contribs)   23:38, 2 February 2010

Review is at r61355.

Status & tagging log