Merge "Language: s/error_log/wfWarn/"
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index 5e6c962..657181b 100644 (file)
@@ -28,7 +28,7 @@
  * @ingroup API
  */
 class ApiUpload extends ApiBase {
-       /** @var UploadBase */
+       /** @var UploadBase|UploadFromChunks */
        protected $mUpload = null;
 
        protected $mParams;
@@ -52,6 +52,7 @@ class ApiUpload extends ApiBase {
 
                // Copy the session key to the file key, for backward compatibility.
                if ( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
+                       $this->logFeatureUsage( 'action=upload&sessionkey' );
                        $this->mParams['filekey'] = $this->mParams['sessionkey'];
                }
 
@@ -210,7 +211,6 @@ class ApiUpload extends ApiBase {
                        }
                } else {
                        $filekey = $this->mParams['filekey'];
-                       /** @var $status Status */
                        $status = $this->mUpload->addChunk(
                                $chunkPath, $chunkSize, $this->mParams['offset'] );
                        if ( !$status->isGood() ) {
@@ -241,6 +241,7 @@ class ApiUpload extends ApiBase {
                                        )
                                ) );
                                $result['result'] = 'Poll';
+                               $result['stage'] = 'queued';
                        } else {
                                $status = $this->mUpload->concatenateChunks();
                                if ( !$status->isGood() ) {
@@ -467,6 +468,7 @@ class ApiUpload extends ApiBase {
 
        /**
         * Performs file verification, dies on error.
+        * @param array $verification
         */
        protected function checkVerification( array $verification ) {
                // @todo Move them to ApiBase's message map
@@ -551,6 +553,7 @@ class ApiUpload extends ApiBase {
 
                        if ( isset( $warnings['duplicate'] ) ) {
                                $dupes = array();
+                               /** @var File $dupe */
                                foreach ( $warnings['duplicate'] as $dupe ) {
                                        $dupes[] = $dupe->getName();
                                }
@@ -561,6 +564,7 @@ class ApiUpload extends ApiBase {
                        if ( isset( $warnings['exists'] ) ) {
                                $warning = $warnings['exists'];
                                unset( $warnings['exists'] );
+                               /** @var LocalFile $localFile */
                                $localFile = isset( $warning['normalizedFile'] )
                                        ? $warning['normalizedFile']
                                        : $warning['file'];
@@ -602,6 +606,7 @@ class ApiUpload extends ApiBase {
 
                // Deprecated parameters
                if ( $this->mParams['watch'] ) {
+                       $this->logFeatureUsage( 'action=upload&watch' );
                        $watch = true;
                }
 
@@ -627,6 +632,7 @@ class ApiUpload extends ApiBase {
                                )
                        ) );
                        $result['result'] = 'Poll';
+                       $result['stage'] = 'queued';
                } else {
                        /** @var $status Status */
                        $status = $this->mUpload->performUpload( $this->mParams['comment'],
@@ -684,10 +690,6 @@ class ApiUpload extends ApiBase {
                                ApiBase::PARAM_DFLT => ''
                        ),
                        'text' => null,
-                       'token' => array(
-                               ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true
-                       ),
                        'watch' => array(
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_DEPRECATED => true,
@@ -731,7 +733,6 @@ class ApiUpload extends ApiBase {
        public function getParamDescription() {
                $params = array(
                        'filename' => 'Target filename',
-                       'token' => 'Edit token. You can get one of these through prop=info',
                        'comment' => 'Upload comment. Also used as the initial page text for new ' .
                                'files if "text" is not specified',
                        'text' => 'Initial page text for new files',
@@ -760,41 +761,6 @@ class ApiUpload extends ApiBase {
                return $params;
        }
 
-       public function getResultProperties() {
-               return array(
-                       '' => array(
-                               'result' => array(
-                                       ApiBase::PROP_TYPE => array(
-                                               'Success',
-                                               'Warning',
-                                               'Continue',
-                                               'Queued'
-                                       ),
-                               ),
-                               'filekey' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'sessionkey' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'offset' => array(
-                                       ApiBase::PROP_TYPE => 'integer',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'statuskey' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'filename' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               )
-                       )
-               );
-       }
-
        public function getDescription() {
                return array(
                        'Upload a file, or get the status of pending uploads. Several methods are available:',
@@ -802,50 +768,20 @@ class ApiUpload extends ApiBase {
                        ' * Have the MediaWiki server fetch a file from a URL, using the "url" parameter',
                        ' * Complete an earlier upload that failed due to warnings, using the "filekey" parameter',
                        'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when',
-                       'sending the "file". Also you must get and send an edit token before doing any upload stuff.'
-               );
-       }
-
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(),
-                       $this->getRequireOnlyOneParameterErrorMessages( array( 'filekey', 'file', 'url', 'statuskey' ) ),
-                       array(
-                               array( 'uploaddisabled' ),
-                               array( 'invalid-file-key' ),
-                               array( 'uploaddisabled' ),
-                               array( 'mustbeloggedin', 'upload' ),
-                               array( 'badaccess-groups' ),
-                               array( 'code' => 'fetchfileerror', 'info' => '' ),
-                               array( 'code' => 'nomodule', 'info' => 'No upload module set' ),
-                               array( 'code' => 'empty-file', 'info' => 'The file you submitted was empty' ),
-                               array( 'code' => 'filetype-missing', 'info' => 'The file is missing an extension' ),
-                               array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ),
-                               array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ),
-                               array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ),
-                               array( 'code' => 'publishfailed', 'info' => 'Publishing of stashed file failed' ),
-                               array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ),
-                               array( 'code' => 'asynccopyuploaddisabled', 'info' => 'Asynchronous copy uploads disabled' ),
-                               array( 'code' => 'stasherror', 'info' => 'An upload stash error occurred' ),
-                               array( 'fileexists-forbidden' ),
-                               array( 'fileexists-shared-forbidden' ),
-                       )
+                       'sending the "file".',
                );
        }
 
        public function needsToken() {
-               return true;
-       }
-
-       public function getTokenSalt() {
-               return '';
+               return 'csrf';
        }
 
        public function getExamples() {
                return array(
                        'api.php?action=upload&filename=Wiki.png' .
-                       '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
+                       '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&token=123ABC'
                                => 'Upload from a URL',
-                       'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1'
+                       'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1&token=123ABC'
                                => 'Complete an upload that failed due to warnings',
                );
        }