Replace a few more uses of deprecated Status / StatusValue methods
Change-Id: I017bcaffe6945d633d7387f9391803845369bfed
This commit is contained in:
parent
f794e7d382
commit
d46fdf645b
7 changed files with 18 additions and 22 deletions
|
|
@ -114,8 +114,8 @@ abstract class ActionModuleBasedHandler extends Handler {
|
|||
$apiMain->execute();
|
||||
} catch ( ApiUsageException $ex ) {
|
||||
// use a fake loop to throw the first error
|
||||
foreach ( $ex->getStatusValue()->getErrorsByType( 'error' ) as $error ) {
|
||||
$msg = ApiMessage::create( $error );
|
||||
foreach ( $ex->getStatusValue()->getMessages( 'error' ) as $msg ) {
|
||||
$msg = ApiMessage::create( $msg );
|
||||
$this->throwHttpExceptionForActionModuleError( $msg, $ex->getCode() ?: 400 );
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ abstract class ActionModuleBasedHandler extends Handler {
|
|||
* @stable to override
|
||||
*
|
||||
* @param IApiMessage $msg A message object representing an error in an action module,
|
||||
* typically from calling getStatusValue()->getErrorsByType( 'error' ) on
|
||||
* typically from calling getStatusValue()->getMessages( 'error' ) on
|
||||
* an ApiUsageException.
|
||||
* @param int $statusCode The HTTP status indicated by the original exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -138,8 +138,7 @@ class SearchHandler extends Handler {
|
|||
if ( $results instanceof StatusValue ) {
|
||||
$status = $results;
|
||||
if ( !$status->isOK() ) {
|
||||
[ $error ] = $status->splitByErrorType();
|
||||
if ( $error->getErrors() ) { // Only throw for errors, suppress warnings (for now)
|
||||
if ( $status->getMessages( 'error' ) ) { // Only throw for errors, suppress warnings (for now)
|
||||
$this->throwExceptionForStatus( $status, 'rest-search-error', 500 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -590,12 +590,14 @@ if ( !defined( 'MW_NO_SESSION' ) && MW_ENTRY_POINT !== 'cli' ) {
|
|||
true,
|
||||
$sessionUser
|
||||
);
|
||||
$firstMessage = $res->getMessages( 'error' )[0] ?? $res->getMessages( 'warning' )[0] ?? null;
|
||||
\MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autocreation attempt', [
|
||||
'event' => 'autocreate',
|
||||
'successful' => $res->isGood(),
|
||||
'status' => ( $res->getErrorsArray() ?: $res->getWarningsArray() )[0][0] ?? '-',
|
||||
'status' => $firstMessage ? $firstMessage->getKey() : '-',
|
||||
] );
|
||||
unset( $res );
|
||||
unset( $firstMessage );
|
||||
}
|
||||
unset( $sessionUser );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
namespace MediaWiki\EditPage\Constraint;
|
||||
|
||||
use ApiMessage;
|
||||
use MediaWiki\Content\Content;
|
||||
use MediaWiki\Context\IContextSource;
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
|
|
@ -97,7 +96,7 @@ class EditFilterMergedContentHookConstraint implements IEditConstraint {
|
|||
// being set. This is used by ConfirmEdit to display a captcha
|
||||
// without any error message cruft.
|
||||
} else {
|
||||
if ( !$this->status->getErrors() ) {
|
||||
if ( !$this->status->getMessages() ) {
|
||||
// Provide a fallback error message if none was set
|
||||
$this->status->fatal( 'hookaborted' );
|
||||
}
|
||||
|
|
@ -114,7 +113,7 @@ class EditFilterMergedContentHookConstraint implements IEditConstraint {
|
|||
if ( !$this->status->isOK() ) {
|
||||
// ...or the hook could be expecting us to produce an error
|
||||
// FIXME this sucks, we should just use the Status object throughout
|
||||
if ( !$this->status->getErrors() ) {
|
||||
if ( !$this->status->getMessages() ) {
|
||||
// Provide a fallback error message if none was set
|
||||
$this->status->fatal( 'hookaborted' );
|
||||
}
|
||||
|
|
@ -152,10 +151,8 @@ class EditFilterMergedContentHookConstraint implements IEditConstraint {
|
|||
*/
|
||||
private function formatStatusErrors( Status $status ): string {
|
||||
$ret = '';
|
||||
foreach ( $status->getErrors() as $rawError ) {
|
||||
// XXX: This interface is ugly, but it seems to be the only convenient way to convert a message specifier
|
||||
// as used in Status to a Message without all the cruft that Status::getMessage & friends add.
|
||||
$msg = Message::newFromSpecifier( ApiMessage::create( $rawError ) );
|
||||
foreach ( $status->getMessages() as $msg ) {
|
||||
$msg = Message::newFromSpecifier( $msg );
|
||||
$ret .= Html::errorBox( "\n" . $msg->inLanguage( $this->language )->plain() . "\n" );
|
||||
}
|
||||
return $ret;
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ class HttpRequestFactory {
|
|||
if ( $status->isOK() ) {
|
||||
return $req->getContent();
|
||||
} else {
|
||||
$errors = $status->getErrorsByType( 'error' );
|
||||
$errors = array_map( fn ( $msg ) => $msg->getKey(), $status->getMessages( 'error' ) );
|
||||
$logger->warning( Status::wrap( $status )->getWikiText( false, false, 'en' ),
|
||||
[ 'error' => $errors, 'caller' => $caller, 'content' => $req->getContent() ] );
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -3136,13 +3136,11 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertEquals( $page->getTitle()->getDBkey(),
|
||||
$records[$revRecord1->getId()]->getPageAsLinkTarget()->getDBkey() );
|
||||
$this->assertNull( $records[$invalidRow->rev_id] );
|
||||
$this->assertSame( [ [
|
||||
'type' => 'warning',
|
||||
'message' => 'internalerror_info',
|
||||
'params' => [
|
||||
"Couldn't find slots for rev 100500"
|
||||
]
|
||||
] ], $result->getErrors() );
|
||||
$this->assertStatusMessagesExactly(
|
||||
StatusValue::newGood()
|
||||
->warning( 'internalerror_info', "Couldn't find slots for rev 100500" ),
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class MWRestrictionsTest extends MediaWikiUnitTestCase {
|
|||
FormatJson::encode( $restrictions, true, FormatJson::ALL_OK ),
|
||||
$ret->toJson( true )
|
||||
);
|
||||
$this->assertSame( $expect->getErrors(), $ret->validity->getErrors() );
|
||||
$this->assertStatusMessagesExactly( $expect, $ret->validity );
|
||||
} else {
|
||||
try {
|
||||
MWRestrictions::newFromJson( $json );
|
||||
|
|
|
|||
Loading…
Reference in a new issue