follow up r61355, initial, incomplete dealing with TimStarlings CR
authorMark A. Hershberger <mah@users.mediawiki.org>
Mon, 1 Feb 2010 07:05:23 +0000 (07:05 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Mon, 1 Feb 2010 07:05:23 +0000 (07:05 +0000)
includes/api/ApiUpload.php
includes/upload/UploadBase.php
includes/upload/UploadFromChunks.php

index 8bebedb..c5df5e5 100644 (file)
@@ -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;
        }
index 067b94f..e55e7fa 100644 (file)
@@ -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 );
+       }
+
 }
index 10651a4..22926ef 100644 (file)
@@ -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 );
        }
 }