aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Rest
diff options
context:
space:
mode:
Diffstat (limited to 'includes/Rest')
-rw-r--r--includes/Rest/Handler/ActionModuleBasedHandler.php13
-rw-r--r--includes/Rest/Handler/EditHandler.php12
-rw-r--r--includes/Rest/Handler/Helper/RestStatusTrait.php28
-rw-r--r--includes/Rest/Handler/UpdateHandler.php2
4 files changed, 9 insertions, 46 deletions
diff --git a/includes/Rest/Handler/ActionModuleBasedHandler.php b/includes/Rest/Handler/ActionModuleBasedHandler.php
index b4b398cb52b5..ed5d798944a1 100644
--- a/includes/Rest/Handler/ActionModuleBasedHandler.php
+++ b/includes/Rest/Handler/ActionModuleBasedHandler.php
@@ -209,7 +209,7 @@ abstract class ActionModuleBasedHandler extends Handler {
// override to supply mappings
throw new LocalizedHttpException(
- $this->makeMessageValue( $msg ),
+ MessageValue::newFromSpecifier( $msg ),
$statusCode,
// Include the original error code in the response.
// This makes it easier to track down the original cause of the error,
@@ -220,15 +220,4 @@ abstract class ActionModuleBasedHandler extends Handler {
);
}
- /**
- * Constructs a MessageValue from an IApiMessage.
- *
- * @param IApiMessage $msg
- *
- * @return MessageValue
- */
- protected function makeMessageValue( IApiMessage $msg ) {
- return $this->getMessageValueConverter()->convertMessage( $msg );
- }
-
}
diff --git a/includes/Rest/Handler/EditHandler.php b/includes/Rest/Handler/EditHandler.php
index 6f73f12ca8f7..933d0c9a8acb 100644
--- a/includes/Rest/Handler/EditHandler.php
+++ b/includes/Rest/Handler/EditHandler.php
@@ -115,27 +115,27 @@ abstract class EditHandler extends ActionModuleBasedHandler {
$code = $msg->getApiCode();
if ( $code === 'protectedpage' ) {
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 403 );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 403 );
}
if ( $code === 'badtoken' ) {
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 403 );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 403 );
}
if ( $code === 'missingtitle' ) {
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 404 );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 404 );
}
if ( $code === 'articleexists' ) {
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 409 );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 409 );
}
if ( $code === 'editconflict' ) {
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 409 );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 409 );
}
if ( $code === 'ratelimited' ) {
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 429 );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 429 );
}
// Fall through to generic handling of the error (status 400).
diff --git a/includes/Rest/Handler/Helper/RestStatusTrait.php b/includes/Rest/Handler/Helper/RestStatusTrait.php
index 3a0cbc1644e0..ec0257920430 100644
--- a/includes/Rest/Handler/Helper/RestStatusTrait.php
+++ b/includes/Rest/Handler/Helper/RestStatusTrait.php
@@ -3,7 +3,6 @@
namespace MediaWiki\Rest\Handler\Helper;
use MediaWiki\Logger\LoggerFactory;
-use MediaWiki\Message\Converter;
use MediaWiki\Rest\LocalizedHttpException;
use StatusValue;
use Wikimedia\Message\MessageValue;
@@ -13,29 +12,6 @@ use Wikimedia\Message\MessageValue;
*/
trait RestStatusTrait {
- private ?Converter $messageValueConverter = null;
-
- private function getMessageValueConverter(): Converter {
- if ( !$this->messageValueConverter ) {
- $this->messageValueConverter = new Converter();
- }
- return $this->messageValueConverter;
- }
-
- /**
- * Extract the error messages from a Status, as MessageValue objects.
- * @param StatusValue $status
- * @return MessageValue[]
- */
- private function convertStatusToMessageValues( StatusValue $status ): array {
- $conv = $this->getMessageValueConverter();
- return array_map( static function ( $msg ) use ( $conv ) {
- // TODO: It should be possible to do this without going through a Message object,
- // but the internal format of parameters is different in MessageValue (T358779)
- return $conv->convertMessage( $msg );
- }, $status->getMessages() );
- }
-
/**
* @param StatusValue $status
* @param string|MessageValue $msg
@@ -55,9 +31,7 @@ trait RestStatusTrait {
if ( is_string( $msg ) ) {
$msg = MessageValue::new( $msg )
- ->semicolonListParams(
- $this->convertStatusToMessageValues( $status )
- );
+ ->semicolonListParams( $status->getMessages() );
}
throw new LocalizedHttpException( $msg, $code, $data );
diff --git a/includes/Rest/Handler/UpdateHandler.php b/includes/Rest/Handler/UpdateHandler.php
index a61f27446117..3053306fd598 100644
--- a/includes/Rest/Handler/UpdateHandler.php
+++ b/includes/Rest/Handler/UpdateHandler.php
@@ -164,7 +164,7 @@ class UpdateHandler extends EditHandler {
if ( $code === 'editconflict' ) {
$data = $this->getConflictData();
- throw new LocalizedHttpException( $this->makeMessageValue( $msg ), 409, $data );
+ throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msg ), 409, $data );
}
parent::throwHttpExceptionForActionModuleError( $msg, $statusCode );