Merge "Fixes to Special:BookSources form"
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index e2e53f8..9d30729 100644 (file)
@@ -71,6 +71,7 @@ class ApiUpload extends ApiBase {
                $this->checkPermissions( $user );
 
                // Fetch the file (usually a no-op)
+               /** @var $status Status */
                $status = $this->mUpload->fetchFile();
                if ( !$status->isGood() ) {
                        $errors = $status->getErrorsArray();
@@ -80,7 +81,7 @@ class ApiUpload extends ApiBase {
 
                // Check if the uploaded file is sane
                if ( $this->mParams['chunk'] ) {
-                       $maxSize = $this->mUpload->getMaxUploadSize( );
+                       $maxSize = $this->mUpload->getMaxUploadSize();
                        if( $this->mParams['filesize'] > $maxSize ) {
                                $this->dieUsage( 'The file you submitted was too large', 'file-too-large' );
                        }
@@ -116,13 +117,13 @@ class ApiUpload extends ApiBase {
        }
 
        /**
-        * Get an uplaod result based on upload context
+        * Get an upload result based on upload context
         * @return array
         */
        private function getContextResult() {
                $warnings = $this->getApiWarnings();
                if ( $warnings && !$this->mParams['ignorewarnings'] ) {
-                       // Get warnings formated in result array format
+                       // Get warnings formatted in result array format
                        return $this->getWarningsResult( $warnings );
                } elseif ( $this->mParams['chunk'] ) {
                        // Add chunk, and get result
@@ -137,12 +138,12 @@ class ApiUpload extends ApiBase {
        }
 
        /**
-        * Get Stash Result, throws an expetion if the file could not be stashed.
-        * @param $warnings array Array of Api upload warnings
+        * Get Stash Result, throws an exception if the file could not be stashed.
+        * @param array $warnings Array of Api upload warnings
         * @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 {
@@ -160,7 +161,7 @@ class ApiUpload extends ApiBase {
 
        /**
         * Get Warnings Result
-        * @param $warnings array Array of Api upload warnings
+        * @param array $warnings Array of Api upload warnings
         * @return array
         */
        private function getWarningsResult( $warnings ) {
@@ -180,7 +181,7 @@ class ApiUpload extends ApiBase {
 
        /**
         * Get the result of a chunk upload.
-        * @param $warnings array Array of Api upload warnings
+        * @param array $warnings Array of Api upload warnings
         * @return array
         */
        private function getChunkResult( $warnings ) {
@@ -197,6 +198,7 @@ class ApiUpload extends ApiBase {
                        $filekey = $this->performStash();
                } else {
                        $filekey = $this->mParams['filekey'];
+                       /** @var $status Status */
                        $status = $this->mUpload->addChunk(
                                $chunkPath, $chunkSize, $this->mParams['offset'] );
                        if ( !$status->isGood() ) {
@@ -220,10 +222,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->getRequest()->exportUserSession(),
-                                               'userid'    => $this->getUser()->getId()
+                                               'filename' => $this->mParams['filename'],
+                                               'filekey' => $this->mParams['filekey'],
+                                               'session' => $this->getContext()->exportSession()
                                        )
                                ) );
                                if ( $ok ) {
@@ -279,9 +280,9 @@ class ApiUpload extends ApiBase {
         * Throw an error that the user can recover from by providing a better
         * value for $parameter
         *
-        * @param $error array Error array suitable for passing to dieUsageMsg()
-        * @param $parameter string Parameter that needs revising
-        * @param $data array Optional extra data to pass to the user
+        * @param array $error Error array suitable for passing to dieUsageMsg()
+        * @param string $parameter Parameter that needs revising
+        * @param array $data Optional extra data to pass to the user
         * @throws UsageException
         */
        private function dieRecoverableError( $error, $parameter, $data = array() ) {
@@ -439,13 +440,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 );
        }
 
        /**
@@ -454,7 +455,7 @@ class ApiUpload extends ApiBase {
        protected function checkVerification( array $verification ) {
                global $wgFileExtensions;
 
-               // TODO: Move them to ApiBase's message map
+               // @todo Move them to ApiBase's message map
                switch( $verification['status'] ) {
                        // Recoverable errors
                        case UploadBase::MIN_LENGTH_PARTNAME:
@@ -556,7 +557,7 @@ class ApiUpload extends ApiBase {
         * Perform the actual upload. Returns a suitable result array on success;
         * dies on failure.
         *
-        * @param $warnings array Array of Api upload warnings
+        * @param array $warnings Array of Api upload warnings
         * @return array
         */
        protected function performUpload( $warnings ) {
@@ -565,6 +566,7 @@ class ApiUpload extends ApiBase {
                        $this->mParams['text'] = $this->mParams['comment'];
                }
 
+               /** @var $file File */
                $file = $this->mUpload->getLocalFile();
                $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() );
 
@@ -586,13 +588,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->getRequest()->exportUserSession(),
-                                       'userid'    => $this->getUser()->getId()
+                                       'filename' => $this->mParams['filename'],
+                                       'filekey' => $this->mParams['filekey'],
+                                       'comment' => $this->mParams['comment'],
+                                       'text' => $this->mParams['text'],
+                                       'watch' => $watch,
+                                       'session' => $this->getContext()->exportSession()
                                )
                        ) );
                        if ( $ok ) {
@@ -603,6 +604,7 @@ class ApiUpload extends ApiBase {
                                        "Failed to start PublishStashedFile.php", 'publishfailed' );
                        }
                } else {
+                       /** @var $status Status */
                        $status = $this->mUpload->performUpload( $this->mParams['comment'],
                                $this->mParams['text'], $watch, $this->getUser() );