mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Use StatusValue::getMessages() instead of deprecated methods
Added in MediaWiki in Ibc4ce11594cf36ce7b2495d2636ee080d3443b04. Change-Id: I0b51f1210b9501961586fa25bf1f49bc68bab3d1
This commit is contained in:
parent
90cbdd834f
commit
94251ca97e
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue