[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add ILocalizedException interface
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/325984 ) Change subject: Add ILocalizedException interface .. Add ILocalizedException interface We already throw around some exceptions that are localized (ErrorPageError and its subclasses, MalformedTitleException), but there's no standard way to recognize them. Let's change that. Then let's use them in the API to be able to have internationalized errors when such exceptions are caught, instead of wrapping the English-language version. Change-Id: Iac7c90f92a889f8de9dae373547c07b884addaea --- M RELEASE-NOTES-1.29 M autoload.php M includes/api/ApiBase.php M includes/api/ApiEditPage.php M includes/api/ApiErrorFormatter.php M includes/api/ApiImport.php M includes/api/ApiMain.php M includes/api/ApiPageSet.php M includes/api/ApiParse.php M includes/api/ApiQueryStashImageInfo.php M includes/api/ApiUpload.php M includes/api/ApiUsageException.php M includes/api/i18n/en.json M includes/api/i18n/qqq.json M includes/exception/ErrorPageError.php A includes/exception/LocalizedException.php M includes/exception/PermissionsError.php M includes/libs/rdbms/exception/DBExpectedError.php M includes/title/MalformedTitleException.php 19 files changed, 241 insertions(+), 37 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified Nikerabbit: Looks good to me, but someone else must approve diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index 986ecd8..e51dacf 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -26,6 +26,8 @@ === New features in 1.29 === * (T5233) A cookie can now be set when a user is autoblocked, to track that user if they move to a new IP address. This is disabled by default. +* Added ILocalizedException interface to standardize the use of localized + exceptions, largely so the API can handle them more sensibly. === External library changes in 1.29 === @@ -49,6 +51,8 @@ using the new 'errorformat', 'errorlang', and 'errorsuselocal' parameters. * API error codes may have changed. Most notably, errors from modules using parameter prefixes (e.g. all query submodules) will no longer be prefixed. +* ApiPageSet-using modules will report the 'invalidreason' using the specified + 'errorformat'. * action=emailuser may return a "Warnings" status, and now returns 'warnings' and 'errors' subelements (as applicable) instead of 'message'. * action=imagerotate returns an 'errors' subelement rather than 'errormessage'. diff --git a/autoload.php b/autoload.php index e079686..60ce8f6 100644 --- a/autoload.php +++ b/autoload.php @@ -598,6 +598,7 @@ 'ILBFactory' => __DIR__ . '/includes/libs/rdbms/lbfactory/ILBFactory.php', 'ILoadBalancer' => __DIR__ . '/includes/libs/rdbms/loadbalancer/ILoadBalancer.php', 'ILoadMonitor' => __DIR__ . '/includes/libs/rdbms/loadmonitor/ILoadMonitor.php', + 'ILocalizedException' => __DIR__ . '/includes/exception/LocalizedException.php', 'IMaintainableDatabase' => __DIR__ . '/includes/libs/rdbms/database/IMaintainableDatabase.php', 'IP' => __DIR__ . '/includes/libs/IP.php', 'IPSet' => __DIR__ . '/includes/compat/IPSetCompat.php', @@ -759,6 +760,7 @@ 'LocalSettingsGenerator' => __DIR__ . '/includes/installer/LocalSettingsGenerator.php', 'LocalisationCache' => __DIR__ . '/includes/cache/localisation/LocalisationCache.php', 'LocalisationCacheBulkLoad' => __DIR__ . '/includes/cache/localisation/LocalisationCacheBulkLoad.php', + 'LocalizedException' => __DIR__ . '/includes/exception/LocalizedException.php', 'LockManager' => __DIR__ . '/includes/libs/lockmanager/LockManager.php', 'LockManagerGroup' => __DIR__ . '/includes/filebackend/lockmanager/LockManagerGroup.php', 'LogEntry' => __DIR__ . '/includes/logging/LogEntry.php', diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index a40593f..65fcb99 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1724,6 +1724,20 @@ } /** +* Abort execution with an error derived from an exception +* +* @since 1.29 +* @param Exception|Throwable $exception See ApiErrorFormatter::getMessageFromException() +* @param array $options See ApiErrorFormatter::getMessageFromException() +* @throws ApiUsageException always +*/ + public function dieWithException( $exception, array $options = [] ) { + $this->dieWithError( + $this->getErrorFormatter()->getMessageFromException( $exception, $options ) + ); + } + + /** * Adds a warning to the output, else dies * * @param ApiMessage $msg Message to show as a warning, or error message if dying diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 6b56870..e5c73b3
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add ILocalizedException interface
Anomie has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/325984 ) Change subject: Add ILocalizedException interface .. Add ILocalizedException interface We already throw around some exceptions that are localized (ErrorPageError and its subclasses, MalformedTitleException), but there's no standard way to recognize them. Let's change that. Then let's use them in the API to be able to have internationalized errors when such exceptions are caught, instead of wrapping the English-language version. Change-Id: Iac7c90f92a889f8de9dae373547c07b884addaea --- M RELEASE-NOTES-1.29 M autoload.php M includes/api/ApiBase.php M includes/api/ApiEditPage.php M includes/api/ApiErrorFormatter.php M includes/api/ApiImport.php M includes/api/ApiMain.php M includes/api/ApiPageSet.php M includes/api/ApiParse.php M includes/api/ApiQueryStashImageInfo.php M includes/api/ApiUpload.php M includes/api/ApiUsageException.php M includes/api/i18n/en.json M includes/api/i18n/qqq.json M includes/exception/ErrorPageError.php A includes/exception/LocalizedException.php M includes/exception/PermissionsError.php M includes/libs/rdbms/exception/DBExpectedError.php M includes/title/MalformedTitleException.php 19 files changed, 241 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/84/325984/1 diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index 986ecd8..e51dacf 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -26,6 +26,8 @@ === New features in 1.29 === * (T5233) A cookie can now be set when a user is autoblocked, to track that user if they move to a new IP address. This is disabled by default. +* Added ILocalizedException interface to standardize the use of localized + exceptions, largely so the API can handle them more sensibly. === External library changes in 1.29 === @@ -49,6 +51,8 @@ using the new 'errorformat', 'errorlang', and 'errorsuselocal' parameters. * API error codes may have changed. Most notably, errors from modules using parameter prefixes (e.g. all query submodules) will no longer be prefixed. +* ApiPageSet-using modules will report the 'invalidreason' using the specified + 'errorformat'. * action=emailuser may return a "Warnings" status, and now returns 'warnings' and 'errors' subelements (as applicable) instead of 'message'. * action=imagerotate returns an 'errors' subelement rather than 'errormessage'. diff --git a/autoload.php b/autoload.php index e079686..60ce8f6 100644 --- a/autoload.php +++ b/autoload.php @@ -598,6 +598,7 @@ 'ILBFactory' => __DIR__ . '/includes/libs/rdbms/lbfactory/ILBFactory.php', 'ILoadBalancer' => __DIR__ . '/includes/libs/rdbms/loadbalancer/ILoadBalancer.php', 'ILoadMonitor' => __DIR__ . '/includes/libs/rdbms/loadmonitor/ILoadMonitor.php', + 'ILocalizedException' => __DIR__ . '/includes/exception/LocalizedException.php', 'IMaintainableDatabase' => __DIR__ . '/includes/libs/rdbms/database/IMaintainableDatabase.php', 'IP' => __DIR__ . '/includes/libs/IP.php', 'IPSet' => __DIR__ . '/includes/compat/IPSetCompat.php', @@ -759,6 +760,7 @@ 'LocalSettingsGenerator' => __DIR__ . '/includes/installer/LocalSettingsGenerator.php', 'LocalisationCache' => __DIR__ . '/includes/cache/localisation/LocalisationCache.php', 'LocalisationCacheBulkLoad' => __DIR__ . '/includes/cache/localisation/LocalisationCacheBulkLoad.php', + 'LocalizedException' => __DIR__ . '/includes/exception/LocalizedException.php', 'LockManager' => __DIR__ . '/includes/libs/lockmanager/LockManager.php', 'LockManagerGroup' => __DIR__ . '/includes/filebackend/lockmanager/LockManagerGroup.php', 'LogEntry' => __DIR__ . '/includes/logging/LogEntry.php', diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index a40593f..65fcb99 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1724,6 +1724,20 @@ } /** +* Abort execution with an error derived from an exception +* +* @since 1.29 +* @param Exception|Throwable $exception See ApiErrorFormatter::getMessageFromException() +* @param array $options See ApiErrorFormatter::getMessageFromException() +* @throws ApiUsageException always +*/ + public function dieWithException( $exception, array $options = [] ) { + $this->dieWithError( + $this->getErrorFormatter()->getMessageFromException( $exception, $options ) + ); + } + + /** * Adds a warning to the output, else dies * * @param ApiMessage $msg Message to show as a warning, or error message if dying diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 6b56870..e5c73b3 100644 --- a/includes/api/ApiEditPage.php +++