Bartosz Dziewoński has uploaded a new change for review. https://gerrit.wikimedia.org/r/295315
Change subject: Better handle ApiMessage errors from UploadVerifyFile hook ...................................................................... Better handle ApiMessage errors from UploadVerifyFile hook The extra data is actually understood and output now. Bug: T137961 Change-Id: Ifac8995a4d16d11840cee814177fc2808bc2072c --- M docs/hooks.txt M includes/api/ApiUpload.php 2 files changed, 25 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/15/295315/1 diff --git a/docs/hooks.txt b/docs/hooks.txt index d667ea1..16d0680 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -3283,7 +3283,9 @@ Handlers will typically only apply for specific MIME types. &$error: (object) output: true if the file is valid. Otherwise, an indexed array representing the problem with the file, where the first element is the message - key and the remaining elements are used as parameters to the message. + key or MessageSpecifier instance (you might want to use ApiMessage to provide + machine-readable details for the API) and the remaining elements are used as + parameters to the message. 'UploadVerifyUpload': Upload verification, based on both file properties like MIME type (same as UploadVerifyFile) and the information entered by the user diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 3af0dff..4d4dfdb 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -567,12 +567,28 @@ $this->dieUsage( $msg, 'filetype-banned', 0, $extradata ); break; case UploadBase::VERIFICATION_ERROR: - $params = $verification['details']; - $key = array_shift( $params ); - $msg = $this->msg( $key, $params )->inLanguage( 'en' )->useDatabase( false )->text(); - ApiResult::setIndexedTagName( $verification['details'], 'detail' ); - $this->dieUsage( "This file did not pass file verification: $msg", 'verification-error', - 0, [ 'details' => $verification['details'] ] ); + $parsed = $this->parseMsg( $verification['details'] ); + $info = "This file did not pass file verification: {$parsed['info']}"; + if ( $verification['details'][0] instanceof MessageSpecifier ) { + $code = $parsed['code']; + } else { + // For backwards-compatibility, all of the errors from UploadBase::verifyFile() are + // reported as 'verification-error', and the real error code is reported in 'details'. + $code = 'verification-error'; + } + if ( $verification['details'][0] instanceof MessageSpecifier ) { + $msg = $verification['details'][0]; + $details = array_merge_recursive( [ $msg->getKey() ], $msg->getParams() ); + } else { + $details = $verification['details']; + } + ApiResult::setIndexedTagName( $details, 'detail' ); + $data = [ 'details' => $details ]; + if ( isset( $parsed['data'] ) ) { + $data = array_merge( $data, $parsed['data'] ); + } + + $this->dieUsage( $info, $code, 0, $data ); break; case UploadBase::HOOK_ABORTED: if ( is_array( $verification['error'] ) ) { -- To view, visit https://gerrit.wikimedia.org/r/295315 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifac8995a4d16d11840cee814177fc2808bc2072c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits