Merge "Deprecate and replace usages of User:isAllowed{All,Any}"
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index f0d271c..b15b998 100644 (file)
@@ -74,8 +74,20 @@ class ApiUpload extends ApiBase {
                }
 
                // Check if the uploaded file is sane
-               wfDebug( __METHOD__ . " about to verify\n" );
-               $this->verifyUpload();
+               if ( $this->mParams['chunk'] ) {
+                       $maxSize = UploadBase::getMaxUploadSize();
+                       if ( $this->mParams['filesize'] > $maxSize ) {
+                               $this->dieWithError( 'file-too-large' );
+                       }
+                       if ( !$this->mUpload->getTitle() ) {
+                               $this->dieWithError( 'illegal-filename' );
+                       }
+               } elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
+                       // defer verification to background process
+               } else {
+                       wfDebug( __METHOD__ . " about to verify\n" );
+                       $this->verifyUpload();
+               }
 
                // Check if the user has the rights to modify or overwrite the requested title
                // (This check is irrelevant if stashing is already requested, since the errors
@@ -646,7 +658,7 @@ class ApiUpload extends ApiBase {
         * @return array
         */
        protected function getApiWarnings() {
-               $warnings = $this->mUpload->checkWarnings();
+               $warnings = UploadBase::makeWarningsSerializable( $this->mUpload->checkWarnings() );
 
                return $this->transformWarnings( $warnings );
        }
@@ -658,9 +670,8 @@ class ApiUpload extends ApiBase {
 
                        if ( isset( $warnings['duplicate'] ) ) {
                                $dupes = [];
-                               /** @var File $dupe */
                                foreach ( $warnings['duplicate'] as $dupe ) {
-                                       $dupes[] = $dupe->getName();
+                                       $dupes[] = $dupe['fileName'];
                                }
                                ApiResult::setIndexedTagName( $dupes, 'duplicate' );
                                $warnings['duplicate'] = $dupes;
@@ -669,27 +680,24 @@ class ApiUpload extends ApiBase {
                        if ( isset( $warnings['exists'] ) ) {
                                $warning = $warnings['exists'];
                                unset( $warnings['exists'] );
-                               /** @var LocalFile $localFile */
                                $localFile = $warning['normalizedFile'] ?? $warning['file'];
-                               $warnings[$warning['warning']] = $localFile->getName();
+                               $warnings[$warning['warning']] = $localFile['fileName'];
                        }
 
                        if ( isset( $warnings['no-change'] ) ) {
-                               /** @var File $file */
                                $file = $warnings['no-change'];
                                unset( $warnings['no-change'] );
 
                                $warnings['nochange'] = [
-                                       'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() )
+                                       'timestamp' => wfTimestamp( TS_ISO_8601, $file['timestamp'] )
                                ];
                        }
 
                        if ( isset( $warnings['duplicate-version'] ) ) {
                                $dupes = [];
-                               /** @var File $dupe */
                                foreach ( $warnings['duplicate-version'] as $dupe ) {
                                        $dupes[] = [
-                                               'timestamp' => wfTimestamp( TS_ISO_8601, $dupe->getTimestamp() )
+                                               'timestamp' => wfTimestamp( TS_ISO_8601, $dupe['timestamp'] )
                                        ];
                                }
                                unset( $warnings['duplicate-version'] );