From 5b5d7ef6f7f53aa5f70f765e7fd07554eaa572ac Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Mon, 1 Feb 2010 07:05:23 +0000 Subject: [PATCH] follow up r61355, initial, incomplete dealing with TimStarlings CR --- includes/api/ApiUpload.php | 21 +++---------- includes/upload/UploadBase.php | 6 ++++ includes/upload/UploadFromChunks.php | 47 ++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 8bebedb7a0..c5df5e5163 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -84,9 +84,9 @@ class ApiUpload extends ApiBase { if ( $this->mParams['enablechunks'] ) { $this->mUpload = new UploadFromChunks(); $this->mUpload->initialize( - $request->getText( 'done' ), - $request->getText( 'filename' ), - $request->getText( 'chunksessionkey' ), + $request->getVal( 'done', null ), + $request->getVal( 'filename', null ), + $request->getVal( 'chunksessionkey', null ), $request->getFileTempName( 'chunk' ), $request->getFileSize( 'chunk' ), $request->getSessionData( 'wsUploadData' ) @@ -126,13 +126,6 @@ class ApiUpload extends ApiBase { if ( !isset( $this->mUpload ) ) $this->dieUsage( 'No upload module set', 'nomodule' ); - - // Finish up the exec command: - $this->doExecUpload(); - } - - protected function doExecUpload() { - global $wgUser; // Check whether the user has the appropriate permissions to upload anyway $permission = $this->mUpload->isAllowed( $wgUser ); @@ -144,8 +137,8 @@ class ApiUpload extends ApiBase { } // Perform the upload $result = $this->performUpload(); + // Cleanup any temporary mess - // FIXME: This should be in a try .. finally block with performUpload $this->mUpload->cleanupTempFile(); $this->getResult()->addValue( null, $this->getModuleName(), $result ); } @@ -255,11 +248,7 @@ class ApiUpload extends ApiBase { $file = $this->mUpload->getLocalFile(); $result['result'] = 'Success'; $result['filename'] = $file->getName(); - - // Append imageinfo to the result - $imParam = ApiQueryImageInfo::getPropertyNames(); - $result['imageinfo'] = ApiQueryImageInfo::getInfo( $file, - array_flip( $imParam ), $this->getResult() ); + $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); return $result; } diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 067b94fdd5..e55e7faa8e 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1019,4 +1019,10 @@ abstract class UploadBase { return $blacklist; } + public function getImageInfo($result) { + $file = $this->getLocalFile(); + $imParam = ApiQueryImageInfo::getPropertyNames(); + return ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result ); + } + } diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 10651a48af..22926ef786 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -88,8 +88,10 @@ class UploadFromChunks extends UploadBase { * @returns void */ protected function initFromSessionKey( $sessionKey, $sessionData ) { - if ( !$sessionKey || empty( $sessionKey ) ) { - $this->status = Status::newFromFatal( 'Missing session data.' ); + // testing against null because we don't want to cause obscure + // bugs when $sessionKey is full of "0" + if ( !$sessionKey === null ) { + $this->status = Status::newFromFatal( 'import-token-mismatch' ); return; } $this->sessionKey = $sessionKey; @@ -115,7 +117,7 @@ class UploadFromChunks extends UploadBase { * @see UploadBase::performUpload */ public function performUpload( $comment, $pageText, $watch, $user ) { - wfDebug( "\n\n\performUpload(chunked): sum:" . $comment . ' c: ' . $pageText . ' w:' . $watch ); + wfDebug( "\n\n\performUpload(chunked): comment:" . $comment . ' pageText: ' . $pageText . ' watch:' . $watch ); global $wgUser, $wgOut; if ( $this->chunkMode == self::INIT ) { @@ -147,13 +149,13 @@ class UploadFromChunks extends UploadBase { ); $wgOut->disable(); } else if ( $this->chunkMode == self::DONE ) { - if ( $comment == '' ) + if ( !$comment ) $comment = $this->comment; - if ( $pageText == '' ) + if ( !$pageText ) $pageText = $this->pageText; - if ( $watch == '' ) + if ( !$watch ) $watch = $this->watch; $status = parent::performUpload( $comment, $pageText, $watch, $user ); @@ -203,15 +205,34 @@ class UploadFromChunks extends UploadBase { $_SESSION['wsUploadData'][$this->sessionKey]['repoPath'] = $this->repoPath; } return $status; + } + if ( $this->getRealPath( $this->repoPath ) ) { + $this->status = $this->appendToUploadFile( $this->repoPath, $this->mTempPath ); } else { - if ( $this->getRealPath( $this->repoPath ) ) { - $this->status = $this->appendToUploadFile( $this->repoPath, $this->mTempPath ); - } else { - $this->status = Status::newFatal( 'filenotfound', $this->repoPath ); - } + $this->status = Status::newFatal( 'filenotfound', $this->repoPath ); + } + if ( $this->fileSize > $wgMaxUploadSize ) + $this->status = Status::newFatal( 'largefileserver' ); + } + + public function verifyUpload() { + if ( $this->chunkMode != self::DONE ) { + return Status::newGood(); + } + return parent::verifyUpload(); + } + + public function checkWarnings() { + if ( $this->chunkMode != self::DONE ) { + return null; + } + return parent::checkWarnings(); + } - if ( $this->fileSize > $wgMaxUploadSize ) - $this->status = Status::newFatal( 'largefileserver' ); + public function getImageInfo( $result ) { + if ( $this->chunkMode != self::DONE ) { + return null; } + return parent::getImageInfo( $result ); } } -- 2.20.1