From: Mark A. Hershberger Date: Sat, 23 Jan 2010 05:20:31 +0000 (+0000) Subject: follow up r61355 X-Git-Tag: 1.31.0-rc.0~38149 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=eecb86354a9f95ceec565cfda7e248f6073a3ddc;p=lhc%2Fweb%2Fwiklou.git follow up r61355 --- diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 8a9c7c0c99..0e0e714791 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -84,7 +84,13 @@ class ApiUpload extends ApiBase { // Initialize $this->mUpload if ( $this->mParams['enablechunks'] ) { $this->mUpload = new UploadFromChunks(); - $this->mUpload->initialize( $request ); + $this->mUpload->initialize + ( $request->getText( 'done' ), + $request->getText( 'filename' ), + $request->getText( 'chunksessionkey' ), + $request->getFileTempName( 'chunk' ), + $request->getFileSize( 'chunk' ), + $request->getSessionData( 'wsUploadData' ) ); if ( !$this->mUpload->status->isOK() ) { return $this->dieUsageMsg( $this->mUpload->status->getWikiText(), @@ -278,7 +284,7 @@ class ApiUpload extends ApiBase { 'watch' => false, 'ignorewarnings' => false, 'file' => null, - 'enablechunks' => null, + 'enablechunks' => false, 'chunksessionkey' => null, 'chunk' => null, 'done' => false, @@ -302,6 +308,9 @@ class ApiUpload extends ApiBase { 'ignorewarnings' => 'Ignore any warnings', 'file' => 'File contents', 'enablechunks' => 'Set to use chunk mode; see http://firefogg.org/dev/chunk_post.html for protocol', + 'chunksessionkey' => 'The session key, established on the first contact during the chunked upload', + 'chunk' => 'The data in this chunk of a chunked upload', + 'done' => 'Set to 1 on the last chunk of a chunked upload', 'url' => 'Url to fetch the file from', 'sessionkey' => array( 'Session key returned by a previous upload that failed due to warnings', diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 945764d1c8..0520a8d053 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -42,12 +42,9 @@ class UploadFromChunks extends UploadBase { throw new MWException( 'not implemented' ); } - public function initialize( &$request ) { - $done = $request->getText( 'done' ); - $filename = $request->getText( 'filename' ); - $sessionKey = $request->getText( 'chunksessionkey' ); - - $this->initFromSessionKey( $sessionKey, $request ); + public function initialize( $done, $filename, $sessionKey, $path, + $fileSize, $sessionData ) { + $this->initFromSessionKey( $sessionKey, $sessionData ); if ( !$this->sessionKey && !$done ) { // session key not set, init the chunk upload system: @@ -60,8 +57,8 @@ class UploadFromChunks extends UploadBase { } if ( $this->chunkMode == self::CHUNK || $this->chunkMode == self::DONE ) { - $this->mTempPath = $request->getFileTempName( 'chunk' ); - $this->fileSize += $request->getFileSize( 'chunk' ); + $this->mTempPath = $path; + $this->fileSize += $fileSize; } } @@ -94,14 +91,12 @@ class UploadFromChunks extends UploadBase { * * @returns void */ - protected function initFromSessionKey( $sessionKey, $request ) { + protected function initFromSessionKey( $sessionKey, $sessionData ) { if ( !$sessionKey || empty( $sessionKey ) ) { $this->status = Status::newFromFatal( 'Missing session data.' ); return; } $this->sessionKey = $sessionKey; - // load the sessionData array: - $sessionData = $request->getSessionData( 'wsUploadData' ); if ( isset( $sessionData[$this->sessionKey]['version'] ) && $sessionData[$this->sessionKey]['version'] == self::SESSION_VERSION ) { @@ -124,7 +119,7 @@ class UploadFromChunks extends UploadBase { */ public function performUpload( $comment, $pageText, $watch, $user ) { wfDebug( "\n\n\performUpload(chunked): sum:" . $comment . ' c: ' . $pageText . ' w:' . $watch ); - global $wgUser; + global $wgUser, $wgOut; if ( $this->chunkMode == self::INIT ) { // firefogg expects a specific result per: @@ -140,7 +135,7 @@ class UploadFromChunks extends UploadBase { 'uploadUrl' => wfExpandUrl( wfScript( 'api' ) ) . "?action=upload&" . "token={$token}&format=json&enablechunks=true&chunksessionkey=" . $this->setupChunkSession( $comment, $pageText, $watch ) ) ); - exit( 0 ); + $wgOut->disable(); } else if ( $this->chunkMode == self::CHUNK ) { $status = $this->appendChunk(); if ( !$status->isOK() ) { @@ -153,7 +148,7 @@ class UploadFromChunks extends UploadBase { echo FormatJson::encode( array( 'result' => 1, 'filesize' => $this->fileSize ) ); - exit( 0 ); + $wgOut->disable(); } else if ( $this->chunkMode == self::DONE ) { if ( $comment == '' ) $comment = $this->comment; @@ -178,7 +173,7 @@ class UploadFromChunks extends UploadBase { 'done' => 1, 'resultUrl' => $file->getDescriptionUrl() ) ); - exit( 0 ); + $wgOut->disable(); } }