Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index f821374..93e432b 100644 (file)
@@ -1,9 +1,5 @@
 <?php
 /**
- *
- *
- * Created on Aug 21, 2008
- *
  * Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -71,7 +67,7 @@ class ApiUpload extends ApiBase {
                $this->checkPermissions( $user );
 
                // Fetch the file (usually a no-op)
-               /** @var $status Status */
+               /** @var Status $status */
                $status = $this->mUpload->fetchFile();
                if ( !$status->isGood() ) {
                        $this->dieStatus( $status );
@@ -494,6 +490,13 @@ class ApiUpload extends ApiBase {
                                $this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async']
                        );
                } elseif ( isset( $this->mParams['file'] ) ) {
+                       // Can't async upload directly from a POSTed file, we'd have to
+                       // stash the file and then queue the publish job. The user should
+                       // just submit the two API queries to perform those two steps.
+                       if ( $this->mParams['async'] ) {
+                               $this->dieWithError( 'apierror-cannot-async-upload-file' );
+                       }
+
                        $this->mUpload = new UploadFromFile();
                        $this->mUpload->initialize(
                                $this->mParams['filename'],
@@ -637,7 +640,8 @@ class ApiUpload extends ApiBase {
                                break;
 
                        case UploadBase::HOOK_ABORTED:
-                               $this->dieWithError( $params, 'hookaborted', [ 'details' => $verification['error'] ] );
+                               $msg = $verification['error'] === '' ? 'hookaborted' : $verification['error'];
+                               $this->dieWithError( $msg, 'hookaborted', [ 'details' => $verification['error'] ] );
                                break;
                        default:
                                $this->dieWithError( 'apierror-unknownerror-nocode', 'unknown-error',
@@ -720,26 +724,26 @@ class ApiUpload extends ApiBase {
         */
        protected function handleStashException( $e ) {
                switch ( get_class( $e ) ) {
-                       case 'UploadStashFileNotFoundException':
+                       case UploadStashFileNotFoundException::class:
                                $wrap = 'apierror-stashedfilenotfound';
                                break;
-                       case 'UploadStashBadPathException':
+                       case UploadStashBadPathException::class:
                                $wrap = 'apierror-stashpathinvalid';
                                break;
-                       case 'UploadStashFileException':
+                       case UploadStashFileException::class:
                                $wrap = 'apierror-stashfilestorage';
                                break;
-                       case 'UploadStashZeroLengthFileException':
+                       case UploadStashZeroLengthFileException::class:
                                $wrap = 'apierror-stashzerolength';
                                break;
-                       case 'UploadStashNotLoggedInException':
+                       case UploadStashNotLoggedInException::class:
                                return StatusValue::newFatal( ApiMessage::create(
                                        [ 'apierror-mustbeloggedin', $this->msg( 'action-upload' ) ], 'stashnotloggedin'
                                ) );
-                       case 'UploadStashWrongOwnerException':
+                       case UploadStashWrongOwnerException::class:
                                $wrap = 'apierror-stashwrongowner';
                                break;
-                       case 'UploadStashNoSuchKeyException':
+                       case UploadStashNoSuchKeyException::class:
                                $wrap = 'apierror-stashnosuchfilekey';
                                break;
                        default:
@@ -764,7 +768,7 @@ class ApiUpload extends ApiBase {
                        $this->mParams['text'] = $this->mParams['comment'];
                }
 
-               /** @var $file LocalFile */
+               /** @var LocalFile $file */
                $file = $this->mUpload->getLocalFile();
 
                // For preferences mode, we want to watch if 'watchdefault' is set,
@@ -821,7 +825,7 @@ class ApiUpload extends ApiBase {
                        $result['result'] = 'Poll';
                        $result['stage'] = 'queued';
                } else {
-                       /** @var $status Status */
+                       /** @var Status $status */
                        $status = $this->mUpload->performUpload( $this->mParams['comment'],
                                $this->mParams['text'], $watch, $this->getUser(), $this->mParams['tags'] );
 
@@ -920,6 +924,6 @@ class ApiUpload extends ApiBase {
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Upload';
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Upload';
        }
 }