X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fapi%2FApiUpload.php;h=7b44f409932c476f626334e3d4472da448253c77;hb=12e2154a6bbe3ae65c40ce2230dba9027b6fbb76;hp=ac817ba3c98dd5ade9bd1812b44ed1de8878a500;hpb=cb2f2633919bcd24ad071844549a3a78e200e0c8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index ac817ba3c9..7b44f40993 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(); } @@ -405,6 +408,7 @@ class ApiUpload extends ApiBase { $code = $overrideCode; } if ( $moreExtraData ) { + $extraData = $extraData ?: []; $extraData += $moreExtraData; } $this->dieUsage( $msg, $code, 0, $extraData ); @@ -444,7 +448,18 @@ class ApiUpload extends ApiBase { } } 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; } @@ -689,6 +704,30 @@ class ApiUpload extends ApiBase { : $warning['file']; $warnings[$warning['warning']] = $localFile->getName(); } + + 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() ) + ]; + } + + if ( isset( $warnings['duplicate-version'] ) ) { + $dupes = []; + /** @var File $dupe */ + foreach ( $warnings['duplicate-version'] as $dupe ) { + $dupes[] = [ + 'timestamp' => wfTimestamp( TS_ISO_8601, $dupe->getTimestamp() ) + ]; + } + unset( $warnings['duplicate-version'] ); + + ApiResult::setIndexedTagName( $dupes, 'ver' ); + $warnings['duplicateversions'] = $dupes; + } } return $warnings;