X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiUpload.php;h=54d3c3c30b8a33087975d8eadf68ae0370aafb80;hb=13d2035cbbf3ee74fe2b301148eae993c86cd7e3;hp=fc2fd590560db6fe79aa9bcda30738290afe86a9;hpb=9b95e76c6c45e263baf29486eca615000d440418;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index fc2fd59056..54d3c3c30b 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -109,16 +109,19 @@ class ApiUpload extends ApiBase { // Get the result based on the current upload context: try { $result = $this->getContextResult(); - if ( $result['result'] === 'Success' ) { - $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); - } } catch ( UploadStashException $e ) { // XXX: don't spam exception log list( $msg, $code ) = $this->handleStashException( get_class( $e ), $e->getMessage() ); $this->dieUsage( $msg, $code ); } - $this->getResult()->addValue( null, $this->getModuleName(), $result ); + // Add 'imageinfo' in a separate addValue() call. File metadata can be unreasonably large, + // so otherwise when it exceeded $wgAPIMaxResultSize, no result would be returned (T143993). + if ( $result['result'] === 'Success' ) { + $imageinfo = $this->mUpload->getImageInfo( $this->getResult() ); + $this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo ); + } + // Cleanup any temporary mess $this->mUpload->cleanupTempFile(); } @@ -274,11 +277,17 @@ class ApiUpload extends ApiBase { $this->dieStatusWithCode( $status, 'stashfailed' ); } + // We can only get warnings like 'duplicate' after concatenating the chunks + $warnings = $this->getApiWarnings(); + if ( $warnings ) { + $result['warnings'] = $warnings; + } + // The fully concatenated file has a new filekey. So remove // the old filekey and fetch the new one. UploadBase::setSessionStatus( $this->getUser(), $filekey, false ); $this->mUpload->stash->removeFile( $filekey ); - $filekey = $this->mUpload->getLocalFile()->getFileKey(); + $filekey = $this->mUpload->getStashFile()->getFileKey(); $result['result'] = 'Success'; } @@ -399,6 +408,7 @@ class ApiUpload extends ApiBase { $code = $overrideCode; } if ( $moreExtraData ) { + $extraData = $extraData ?: []; $extraData += $moreExtraData; } $this->dieUsage( $msg, $code, 0, $extraData ); @@ -431,8 +441,25 @@ class ApiUpload extends ApiBase { if ( isset( $progress['status']->value['verification'] ) ) { $this->checkVerification( $progress['status']->value['verification'] ); } + if ( isset( $progress['status']->value['warnings'] ) ) { + $warnings = $this->transformWarnings( $progress['status']->value['warnings'] ); + if ( $warnings ) { + $progress['warnings'] = $warnings; + } + } unset( $progress['status'] ); // remove Status object + $imageinfo = null; + if ( isset( $progress['imageinfo'] ) ) { + $imageinfo = $progress['imageinfo']; + unset( $progress['imageinfo'] ); + } + $this->getResult()->addValue( null, $this->getModuleName(), $progress ); + // Add 'imageinfo' in a separate addValue() call. File metadata can be unreasonably large, + // so otherwise when it exceeded $wgAPIMaxResultSize, no result would be returned (T143993). + if ( $imageinfo ) { + $this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo ); + } return false; } @@ -735,7 +762,7 @@ class ApiUpload extends ApiBase { $this->mParams['text'] = $this->mParams['comment']; } - /** @var $file File */ + /** @var $file LocalFile */ $file = $this->mUpload->getLocalFile(); // For preferences mode, we want to watch if 'watchdefault' is set,