Use StatusValue::getMessages() instead of deprecated methods

Added in MediaWiki in Ibc4ce11594cf36ce7b2495d2636ee080d3443b04.

Change-Id: I0b51f1210b9501961586fa25bf1f49bc68bab3d1
This commit is contained in:
Bartosz Dziewoński 2024-04-12 22:48:59 +02:00
parent 90cbdd834f
commit 94251ca97e
10 changed files with 18 additions and 25 deletions

View file

@ -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;

View file

@ -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 {

View file

@ -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;

View file

@ -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();

View file

@ -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(),

View file

@ -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();
}
}

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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 )
);
}
}

View file

@ -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 );
}