Merge "Rename $usableSkins to $allowedSkins"
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index deeb1c1..e04c762 100644 (file)
@@ -56,7 +56,7 @@ class ApiUpload extends ApiBase {
                $this->mParams['chunk'] = $request->getFileName( 'chunk' );
 
                // Copy the session key to the file key, for backward compatibility.
-               if( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
+               if ( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
                        $this->mParams['filekey'] = $this->mParams['sessionkey'];
                }
 
@@ -81,16 +81,17 @@ class ApiUpload extends ApiBase {
 
                // Check if the uploaded file is sane
                if ( $this->mParams['chunk'] ) {
-                       $maxSize = $this->mUpload->getMaxUploadSize( );
-                       if( $this->mParams['filesize'] > $maxSize ) {
+                       $maxSize = $this->mUpload->getMaxUploadSize();
+                       if ( $this->mParams['filesize'] > $maxSize ) {
                                $this->dieUsage( 'The file you submitted was too large', 'file-too-large' );
                        }
                        if ( !$this->mUpload->getTitle() ) {
                                $this->dieUsage( 'Invalid file title supplied', 'internal-error' );
                        }
-               } elseif ( $this->mParams['async'] ) {
+               } elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
                        // defer verification to background process
                } else {
+                       wfDebug( __METHOD__ . 'about to verify' );
                        $this->verifyUpload();
                }
 
@@ -143,7 +144,7 @@ class ApiUpload extends ApiBase {
         * @return array
         */
        private function getStashResult( $warnings ) {
-               $result = array ();
+               $result = array();
                // Some uploads can request they be stashed, so as not to publish them immediately.
                // In this case, a failure to stash ought to be fatal
                try {
@@ -195,7 +196,12 @@ class ApiUpload extends ApiBase {
                $chunkPath = $request->getFileTempname( 'chunk' );
                $chunkSize = $request->getUpload( 'chunk' )->getSize();
                if ( $this->mParams['offset'] == 0 ) {
-                       $filekey = $this->performStash();
+                       try {
+                               $filekey = $this->performStash();
+                       } catch ( MWException $e ) {
+                               // FIXME: Error handling here is wrong/different from rest of this
+                               $this->dieUsage( $e->getMessage(), 'stashfailed' );
+                       }
                } else {
                        $filekey = $this->mParams['filekey'];
                        /** @var $status Status */
@@ -222,9 +228,9 @@ class ApiUpload extends ApiBase {
                                $ok = JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
                                        Title::makeTitle( NS_FILE, $this->mParams['filekey'] ),
                                        array(
-                                               'filename'  => $this->mParams['filename'],
-                                               'filekey'   => $this->mParams['filekey'],
-                                               'session'   => $this->getContext()->exportSession()
+                                               'filename' => $this->mParams['filename'],
+                                               'filekey' => $this->mParams['filekey'],
+                                               'session' => $this->getContext()->exportSession()
                                        )
                                ) );
                                if ( $ok ) {
@@ -354,7 +360,7 @@ class ApiUpload extends ApiBase {
                if ( $this->mParams['chunk'] ) {
                        // Chunk upload
                        $this->mUpload = new UploadFromChunks();
-                       if( isset( $this->mParams['filekey'] ) ) {
+                       if ( isset( $this->mParams['filekey'] ) ) {
                                // handle new chunk
                                $this->mUpload->continueChunks(
                                        $this->mParams['filename'],
@@ -440,13 +446,13 @@ class ApiUpload extends ApiBase {
        /**
         * Performs file verification, dies on error.
         */
-       protected function verifyUpload( ) {
-               $verification = $this->mUpload->verifyUpload( );
+       protected function verifyUpload() {
+               $verification = $this->mUpload->verifyUpload();
                if ( $verification['status'] === UploadBase::OK ) {
                        return;
-               } else {
-                       return $this->checkVerification( $verification );
                }
+
+               $this->checkVerification( $verification );
        }
 
        /**
@@ -455,8 +461,8 @@ class ApiUpload extends ApiBase {
        protected function checkVerification( array $verification ) {
                global $wgFileExtensions;
 
-               // TODO: Move them to ApiBase's message map
-               switch( $verification['status'] ) {
+               // @todo Move them to ApiBase's message map
+               switch ( $verification['status'] ) {
                        // Recoverable errors
                        case UploadBase::MIN_LENGTH_PARTNAME:
                                $this->dieRecoverableError( 'filename-tooshort', 'filename' );
@@ -588,12 +594,12 @@ class ApiUpload extends ApiBase {
                        $ok = JobQueueGroup::singleton()->push( new PublishStashedFileJob(
                                Title::makeTitle( NS_FILE, $this->mParams['filename'] ),
                                array(
-                                       'filename'  => $this->mParams['filename'],
-                                       'filekey'   => $this->mParams['filekey'],
-                                       'comment'   => $this->mParams['comment'],
-                                       'text'      => $this->mParams['text'],
-                                       'watch'     => $watch,
-                                       'session'   => $this->getContext()->exportSession()
+                                       'filename' => $this->mParams['filename'],
+                                       'filekey' => $this->mParams['filekey'],
+                                       'comment' => $this->mParams['comment'],
+                                       'text' => $this->mParams['text'],
+                                       'watch' => $watch,
+                                       'session' => $this->getContext()->exportSession()
                                )
                        ) );
                        if ( $ok ) {