diff --git a/includes/Api/EvalExpression.php b/includes/Api/EvalExpression.php index 889b31bf9..2a642273a 100644 --- a/includes/Api/EvalExpression.php +++ b/includes/Api/EvalExpression.php @@ -56,7 +56,7 @@ class EvalExpression extends ApiBase { $status = $this->evaluateExpression( $params['expression'] ); if ( !$status->isGood() ) { - $this->dieWithError( $status->getErrors()[0] ); + $this->dieStatus( $status ); } else { $res = $status->getValue(); $res = $params['prettyprint'] ? VariablesFormatter::formatVar( $res ) : $res; diff --git a/includes/Consequences/ConsequencesExecutor.php b/includes/Consequences/ConsequencesExecutor.php index fe2b6e830..6058fc777 100644 --- a/includes/Consequences/ConsequencesExecutor.php +++ b/includes/Consequences/ConsequencesExecutor.php @@ -83,7 +83,7 @@ class ConsequencesExecutor { * @param string[] $filters * @return Status returns the operation's status. $status->isOK() will return true if * there were no actions taken, false otherwise. $status->getValue() will return - * an array listing the actions taken. $status->getErrors() etc. will provide + * an array listing the actions taken. $status->getMessages() will provide * the errors and warnings to be shown to the user to explain the actions. */ public function executeFilterActions( array $filters ): Status { diff --git a/includes/Hooks/Handlers/FilteredActionsHandler.php b/includes/Hooks/Handlers/FilteredActionsHandler.php index 67436b9ba..302f6e3e6 100644 --- a/includes/Hooks/Handlers/FilteredActionsHandler.php +++ b/includes/Hooks/Handlers/FilteredActionsHandler.php @@ -288,7 +288,7 @@ class FilteredActionsHandler implements // Produce a useful error message for API edits $filterResultApi = self::getApiStatus( $filterResult ); // @todo Return all errors instead of only the first one - $error = $filterResultApi->getErrors()[0]['message']; + $error = $filterResultApi->getMessages()[0]; } else { if ( $this->permissionManager->userHasRight( $user, 'abusefilter-bypass-blocked-external-domains' ) ) { return true; diff --git a/includes/Special/SpecialAbuseLog.php b/includes/Special/SpecialAbuseLog.php index a4338db95..05b3b1301 100644 --- a/includes/Special/SpecialAbuseLog.php +++ b/includes/Special/SpecialAbuseLog.php @@ -1047,8 +1047,7 @@ class SpecialAbuseLog extends AbuseFilterSpecialPage { $status = self::getPrivateDetailsRow( $user, $id ); if ( !$status->isGood() ) { - $errArray = $status->getErrors()[0]; - $out->addWikiMsgArray( $errArray['message'], $errArray['params'] ); + $out->addWikiMsg( $status->getMessages()[0] ); return; } $row = $status->getValue(); diff --git a/includes/View/AbuseFilterViewEdit.php b/includes/View/AbuseFilterViewEdit.php index 90809c627..135dd1285 100644 --- a/includes/View/AbuseFilterViewEdit.php +++ b/includes/View/AbuseFilterViewEdit.php @@ -213,11 +213,10 @@ class AbuseFilterViewEdit extends AbuseFilterView { $status = $this->filterStore->saveFilter( $user, $filter, $newFilter, $origFilter ); if ( !$status->isGood() ) { - $errors = $status->getErrors(); - [ 'message' => $msg, 'params' => $params ] = $errors[0]; + $msg = $status->getMessages()[0]; if ( $status->isOK() ) { // Fixable error, show the editing interface - $error = Html::errorBox( $this->msg( $msg, $params )->parseAsBlock() ); + $error = Html::errorBox( $this->msg( $msg )->parseAsBlock() ); $this->buildFilterEditor( $error, $newFilter, $filter, $history_id ); } else { $this->showUnrecoverableError( $msg ); @@ -241,12 +240,12 @@ class AbuseFilterViewEdit extends AbuseFilterView { } /** - * @param string $msgKey + * @param string|\MessageSpecifier $msg */ - private function showUnrecoverableError( string $msgKey ): void { + private function showUnrecoverableError( $msg ): void { $out = $this->getOutput(); - $out->addHTML( Html::errorBox( $this->msg( $msgKey )->parseAsBlock() ) ); + $out->addHTML( Html::errorBox( $this->msg( $msg )->parseAsBlock() ) ); $href = $this->getTitle()->getFullURL(); $btn = new OOUI\ButtonWidget( [ 'label' => $this->msg( 'abusefilter-return' )->text(), diff --git a/tests/phpunit/AbuseFilterConsequencesTest.php b/tests/phpunit/AbuseFilterConsequencesTest.php index 1069cc1ff..13067a337 100644 --- a/tests/phpunit/AbuseFilterConsequencesTest.php +++ b/tests/phpunit/AbuseFilterConsequencesTest.php @@ -697,15 +697,10 @@ class AbuseFilterConsequencesTest extends MediaWikiIntegrationTestCase { } } - $errors = $result->getErrors(); - $actual = []; - foreach ( $errors as $error ) { - // We don't use any of the "API" stuff in ApiMessage here, but this is the most - // convenient way to get a Message from a StatusValue error structure. - $msg = ApiMessage::create( $error )->getKey(); - if ( strpos( $msg, 'abusefilter' ) !== false ) { - $actual[] = $msg; + foreach ( $result->getMessages() as $msg ) { + if ( strpos( $msg->getKey(), 'abusefilter' ) !== false ) { + $actual[] = $msg->getKey(); } } diff --git a/tests/phpunit/integration/ChangeTags/ChangeTagValidatorTest.php b/tests/phpunit/integration/ChangeTags/ChangeTagValidatorTest.php index 44662fa11..cdb2a6c07 100644 --- a/tests/phpunit/integration/ChangeTags/ChangeTagValidatorTest.php +++ b/tests/phpunit/integration/ChangeTags/ChangeTagValidatorTest.php @@ -23,7 +23,7 @@ class ChangeTagValidatorTest extends MediaWikiIntegrationTestCase { public function testValidateTag( string $tag, ?string $expectedError ) { $validator = AbuseFilterServices::getChangeTagValidator(); $status = $validator->validateTag( $tag ); - $actualError = $status->isGood() ? null : $status->getErrors()[0]['message']; + $actualError = $status->isGood() ? null : $status->getMessages()[0]->getKey(); $this->assertSame( $expectedError, $actualError ); } diff --git a/tests/phpunit/integration/FilterValidatorTest.php b/tests/phpunit/integration/FilterValidatorTest.php index f6b6420d9..7ffc32d6c 100644 --- a/tests/phpunit/integration/FilterValidatorTest.php +++ b/tests/phpunit/integration/FilterValidatorTest.php @@ -37,7 +37,7 @@ class FilterValidatorTest extends MediaWikiIntegrationTestCase { ); $status = $validator->checkAllTags( $tags ); - $actualError = $status->isGood() ? null : $status->getErrors()[0]['message']; + $actualError = $status->isGood() ? null : $status->getMessages()[0]->getKey(); $this->assertSame( $expected, $actualError ); } diff --git a/tests/phpunit/integration/FilteredActionsHandlerTest.php b/tests/phpunit/integration/FilteredActionsHandlerTest.php index 8890a53de..b6b94c98d 100644 --- a/tests/phpunit/integration/FilteredActionsHandlerTest.php +++ b/tests/phpunit/integration/FilteredActionsHandlerTest.php @@ -59,7 +59,7 @@ class FilteredActionsHandlerTest extends \MediaWikiIntegrationTestCase { // If it's failing, it should report the URL somewhere $this->assertStringContainsString( 'foo.com', - $status->getErrors()[0]['message']->toString( Message::FORMAT_PLAIN ) + wfMessage( $status->getMessages()[0] )->toString( Message::FORMAT_PLAIN ) ); } } diff --git a/tests/phpunit/unit/FilterValidatorTest.php b/tests/phpunit/unit/FilterValidatorTest.php index d34aa79ed..f18cb9c85 100644 --- a/tests/phpunit/unit/FilterValidatorTest.php +++ b/tests/phpunit/unit/FilterValidatorTest.php @@ -85,10 +85,10 @@ class FilterValidatorTest extends MediaWikiUnitTestCase { * @param array|null $params */ private function assertStatusMessageParams( ?string $expected, Status $actual, array $params = null ): void { - $actualError = $actual->isGood() ? null : $actual->getErrors()[0]['message']; + $actualError = $actual->isGood() ? null : $actual->getMessages()[0]->getKey(); $this->assertSame( $expected, $actualError, 'status message' ); if ( $params !== null ) { - $this->assertSame( $params, $actual->getErrors()[0]['params'] ); + $this->assertSame( $params, $actual->getMessages()[0]->getParams() ); } } @@ -371,7 +371,7 @@ class FilterValidatorTest extends MediaWikiUnitTestCase { $origFilter = $this->createMock( AbstractFilter::class ); $status = $validator->checkAll( $newFilter, $origFilter, $this->createMock( Authority::class ) ); - $actualError = $status->isGood() ? null : $status->getErrors()[0]['message']; + $actualError = $status->isGood() ? null : $status->getMessages()[0]->getKey(); $this->assertSame( $expected, $actualError ); }