Fix most PHP CodeSniffer warnings in includes/api
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index 54294c9..b621cb0 100644 (file)
@@ -45,7 +45,8 @@ class ApiUpload extends ApiBase {
                $this->mParams = $this->extractRequestParams();
                $request = $this->getMain()->getRequest();
                // Check if async mode is actually supported (jobs done in cli mode)
-               $this->mParams['async'] = ( $this->mParams['async'] && $this->getConfig()->get( 'EnableAsyncUploads' ) );
+               $this->mParams['async'] = ( $this->mParams['async'] &&
+                       $this->getConfig()->get( 'EnableAsyncUploads' ) );
                // Add the uploaded file to the params array
                $this->mParams['file'] = $request->getFileName( 'file' );
                $this->mParams['chunk'] = $request->getFileName( 'chunk' );
@@ -527,17 +528,28 @@ class ApiUpload extends ApiBase {
                                $this->dieUsage( $msg, 'filetype-banned', 0, $extradata );
                                break;
                        case UploadBase::VERIFICATION_ERROR:
+                               $params = $verification['details'];
+                               $key = array_shift( $params );
+                               $msg = $this->msg( $key, $params )->inLanguage( 'en' )->useDatabase( false )->text();
                                ApiResult::setIndexedTagName( $verification['details'], 'detail' );
-                               $this->dieUsage( 'This file did not pass file verification', 'verification-error',
+                               $this->dieUsage( "This file did not pass file verification: $msg", 'verification-error',
                                        0, array( 'details' => $verification['details'] ) );
                                break;
                        case UploadBase::HOOK_ABORTED:
-                               $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
-                                       'hookaborted', 0, array( 'error' => $verification['error'] ) );
+                               if ( is_array( $verification['error'] ) ) {
+                                       $params = $verification['error'];
+                               } elseif ( $verification['error'] !== '' ) {
+                                       $params = array( $verification['error'] );
+                               } else {
+                                       $params = array( 'hookaborted' );
+                               }
+                               $key = array_shift( $params );
+                               $msg = $this->msg( $key, $params )->inLanguage( 'en' )->useDatabase( false )->text();
+                               $this->dieUsage( $msg, 'hookaborted', 0, array( 'details' => $verification['error'] ) );
                                break;
                        default:
                                $this->dieUsage( 'An unknown error occurred', 'unknown-error',
-                                       0, array( 'code' => $verification['status'] ) );
+                                       0, array( 'details' => array( 'code' => $verification['status'] ) ) );
                                break;
                }
        }
@@ -594,16 +606,29 @@ class ApiUpload extends ApiBase {
 
                switch ( $exceptionType ) {
                        case 'UploadStashFileNotFoundException':
-                               $this->dieUsage( 'Could not find the file in the stash: ' . $e->getMessage(), 'stashedfilenotfound' );
+                               $this->dieUsage(
+                                       'Could not find the file in the stash: ' . $e->getMessage(),
+                                       'stashedfilenotfound'
+                               );
                                break;
                        case 'UploadStashBadPathException':
-                               $this->dieUsage( 'File key of improper format or otherwise invalid: ' . $e->getMessage(), 'stashpathinvalid' );
+                               $this->dieUsage(
+                                       'File key of improper format or otherwise invalid: ' . $e->getMessage(),
+                                       'stashpathinvalid'
+                               );
                                break;
                        case 'UploadStashFileException':
-                               $this->dieUsage( 'Could not store upload in the stash: ' . $e->getMessage(), 'stashfilestorage' );
+                               $this->dieUsage(
+                                       'Could not store upload in the stash: ' . $e->getMessage(),
+                                       'stashfilestorage'
+                               );
                                break;
                        case 'UploadStashZeroLengthFileException':
-                               $this->dieUsage( 'File is of zero length, and could not be stored in the stash: ' . $e->getMessage(), 'stashzerolength' );
+                               $this->dieUsage(
+                                       'File is of zero length, and could not be stored in the stash: ' .
+                                               $e->getMessage(),
+                                       'stashzerolength'
+                               );
                                break;
                        case 'UploadStashNotLoggedInException':
                                $this->dieUsage( 'Not logged in: ' . $e->getMessage(), 'stashnotloggedin' );