mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 15:36:58 +00:00
Replace remaining usages of deprecated MWException
Bug: T328220 Change-Id: I97ea68525392e921b970d15b5d5ffd9c89bae452
This commit is contained in:
parent
c323fa2e8e
commit
baf711c3c5
|
@ -7,7 +7,6 @@ use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
|||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MWEchoNotifUser;
|
||||
use MWException;
|
||||
use User;
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,6 @@ class ModerationController {
|
|||
*
|
||||
* @param int[] $eventIds
|
||||
* @param bool $moderate Whether to moderate or unmoderate the events
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function moderate( array $eventIds, $moderate ) {
|
||||
if ( !$eventIds ) {
|
||||
|
|
|
@ -9,6 +9,7 @@ use EchoContainmentList;
|
|||
use EchoContainmentSet;
|
||||
use EchoOnWikiList;
|
||||
use EchoServices;
|
||||
use InvalidArgumentException;
|
||||
use Iterator;
|
||||
use MapCacheLRU;
|
||||
use MediaWiki\Extension\Notifications\Iterator\FilteredSequentialIterator;
|
||||
|
@ -20,7 +21,6 @@ use MediaWiki\MediaWikiServices;
|
|||
use MediaWiki\Revision\RevisionStore;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MWEchoNotifUser;
|
||||
use MWException;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
|
@ -426,18 +426,17 @@ class NotificationController {
|
|||
* @param Event $event
|
||||
* @param User $user The user to be notified.
|
||||
* @param string $type The type of notification delivery to process, e.g. 'email'.
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function doNotification( $event, $user, $type ) {
|
||||
global $wgEchoNotifiers;
|
||||
|
||||
if ( !isset( $wgEchoNotifiers[$type] ) ) {
|
||||
throw new MWException( "Invalid notification type $type" );
|
||||
throw new InvalidArgumentException( "Invalid notification type $type" );
|
||||
}
|
||||
|
||||
// Don't send any notifications to anonymous users
|
||||
if ( !$user->isRegistered() ) {
|
||||
throw new MWException( "Cannot notify anonymous user: {$user->getName()}" );
|
||||
throw new InvalidArgumentException( "Cannot notify anonymous user: {$user->getName()}" );
|
||||
}
|
||||
|
||||
( $wgEchoNotifiers[$type] )( $user, $event );
|
||||
|
|
|
@ -974,7 +974,6 @@ abstract class EchoDiscussionParser {
|
|||
*
|
||||
* @param string $oldText The "left hand side" of the diff.
|
||||
* @param string $newText The "right hand side" of the diff.
|
||||
* @throws MWException
|
||||
* @return array[] Array of changes.
|
||||
* Each change consists of:
|
||||
* * An 'action', one of:
|
||||
|
@ -1200,7 +1199,6 @@ abstract class EchoDiscussionParser {
|
|||
* Gets a regular expression that will match this wiki's
|
||||
* timestamps as given by ~~~~.
|
||||
*
|
||||
* @throws MWException
|
||||
* @return string regular expression fragment.
|
||||
*/
|
||||
public static function getTimestampRegex() {
|
||||
|
@ -1234,7 +1232,7 @@ abstract class EchoDiscussionParser {
|
|||
}
|
||||
|
||||
if ( !preg_match( "/$output/u", $exemplarTimestamp ) ) {
|
||||
throw new MWException( "Timestamp regex does not match exemplar" );
|
||||
throw new RuntimeException( "Timestamp regex does not match exemplar" );
|
||||
}
|
||||
|
||||
self::$timestampRegex = $output;
|
||||
|
|
|
@ -50,7 +50,7 @@ class EchoCachedList implements EchoContainmentList {
|
|||
function () {
|
||||
$result = $this->nestedList->getValues();
|
||||
if ( !is_array( $result ) ) {
|
||||
throw new MWException( sprintf(
|
||||
throw new UnexpectedValueException( sprintf(
|
||||
"Expected array but received '%s' from '%s::getValues'",
|
||||
is_object( $result ) ? get_class( $result ) : gettype( $result ),
|
||||
get_class( $this->nestedList )
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use BadMethodCallException;
|
||||
use EchoDiscussionParser;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MWException;
|
||||
use Parser;
|
||||
use Title;
|
||||
use User;
|
||||
|
@ -119,7 +119,7 @@ class EchoPresentationModelSection {
|
|||
public function getTitleWithSection() {
|
||||
$title = $this->event->getTitle();
|
||||
if ( $title === null ) {
|
||||
throw new MWException( 'Event #' . $this->event->getId() . ' with no title' );
|
||||
throw new BadMethodCallException( 'Event #' . $this->event->getId() . ' with no title' );
|
||||
}
|
||||
$section = $this->getParsedSectionTitle();
|
||||
if ( $section ) {
|
||||
|
|
|
@ -5,9 +5,9 @@ namespace MediaWiki\Extension\Notifications\Iterator;
|
|||
use ArrayIterator;
|
||||
use CallbackFilterIterator;
|
||||
use EmptyIterator;
|
||||
use InvalidArgumentException;
|
||||
use Iterator;
|
||||
use IteratorAggregate;
|
||||
use MWException;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,6 @@ class FilteredSequentialIterator implements IteratorAggregate {
|
|||
|
||||
/**
|
||||
* @param Iterator|IteratorAggregate|array $users
|
||||
* @throws MWException
|
||||
*/
|
||||
public function add( $users ) {
|
||||
if ( is_array( $users ) ) {
|
||||
|
@ -65,7 +64,7 @@ class FilteredSequentialIterator implements IteratorAggregate {
|
|||
} elseif ( $users instanceof IteratorAggregate ) {
|
||||
$it = $users->getIterator();
|
||||
} else {
|
||||
throw new MWException( 'Expected array, Iterator or IteratorAggregate but received:' .
|
||||
throw new InvalidArgumentException( 'Expected array, Iterator or IteratorAggregate but received:' .
|
||||
( is_object( $users ) ? get_class( $users ) : gettype( $users ) )
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Mapper;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use MWEchoDbFactory;
|
||||
use MWException;
|
||||
|
||||
/**
|
||||
* Abstract mapper for model
|
||||
|
@ -35,11 +35,10 @@ abstract class AbstractMapper {
|
|||
* @param string $method Method name
|
||||
* @param string $key Identification of the callable
|
||||
* @param callable $callable
|
||||
* @throws MWException
|
||||
*/
|
||||
public function attachListener( $method, $key, $callable ) {
|
||||
if ( !method_exists( $this, $method ) ) {
|
||||
throw new MWException( $method . ' does not exist in ' . get_class( $this ) );
|
||||
throw new InvalidArgumentException( $method . ' does not exist in ' . get_class( $this ) );
|
||||
}
|
||||
if ( !isset( $this->listeners[$method] ) ) {
|
||||
$this->listeners[$method] = [];
|
||||
|
@ -65,11 +64,10 @@ abstract class AbstractMapper {
|
|||
*
|
||||
* @param string $method
|
||||
* @return callable[]
|
||||
* @throws MWException
|
||||
*/
|
||||
public function getMethodListeners( $method ) {
|
||||
if ( !method_exists( $this, $method ) ) {
|
||||
throw new MWException( $method . ' does not exist in ' . get_class( $this ) );
|
||||
throw new InvalidArgumentException( $method . ' does not exist in ' . get_class( $this ) );
|
||||
}
|
||||
|
||||
return $this->listeners[$method] ?? [];
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Mapper;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MWException;
|
||||
use User;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,6 @@ class EventMapper extends AbstractMapper {
|
|||
* @param int $id
|
||||
* @param bool $fromPrimary
|
||||
* @return Event|false False if it wouldn't load/unserialize
|
||||
* @throws MWException
|
||||
*/
|
||||
public function fetchById( $id, $fromPrimary = false ) {
|
||||
$db = $fromPrimary ? $this->dbFactory->getEchoDb( DB_PRIMARY ) : $this->dbFactory->getEchoDb( DB_REPLICA );
|
||||
|
@ -52,7 +51,7 @@ class EventMapper extends AbstractMapper {
|
|||
if ( !$row && !$fromPrimary && $this->dbFactory->canRetryPrimary() ) {
|
||||
return $this->fetchById( $id, true );
|
||||
} elseif ( !$row ) {
|
||||
throw new MWException( "No Event found with ID: $id" );
|
||||
throw new InvalidArgumentException( "No Event found with ID: $id" );
|
||||
}
|
||||
|
||||
return Event::newFromRow( $row );
|
||||
|
|
|
@ -6,10 +6,10 @@ use AtomicSectionUpdate;
|
|||
use BatchRowIterator;
|
||||
use DeferredUpdates;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MWException;
|
||||
use MWExceptionHandler;
|
||||
use Title;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
@ -48,7 +48,6 @@ class NotificationMapper extends AbstractMapper {
|
|||
/**
|
||||
* Extract the offset used for notification list
|
||||
* @param string|null $continue String Used for offset
|
||||
* @throws MWException
|
||||
* @return int[]
|
||||
*/
|
||||
protected function extractQueryOffset( $continue ) {
|
||||
|
@ -59,7 +58,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
if ( $continue ) {
|
||||
$values = explode( '|', $continue, 3 );
|
||||
if ( count( $values ) !== 2 ) {
|
||||
throw new MWException( 'Invalid continue param: ' . $continue );
|
||||
throw new InvalidArgumentException( 'Invalid continue param: ' . $continue );
|
||||
}
|
||||
$offset['timestamp'] = (int)$values[0];
|
||||
$offset['offset'] = (int)$values[1];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Model;
|
||||
|
||||
use MWException;
|
||||
use InvalidArgumentException;
|
||||
use stdClass;
|
||||
use Title;
|
||||
|
||||
|
@ -71,7 +71,6 @@ class TargetPage extends AbstractEntity {
|
|||
*
|
||||
* @param stdClass $row
|
||||
* @return TargetPage
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function newFromRow( $row ) {
|
||||
$requiredFields = [
|
||||
|
@ -80,7 +79,7 @@ class TargetPage extends AbstractEntity {
|
|||
];
|
||||
foreach ( $requiredFields as $field ) {
|
||||
if ( !isset( $row->$field ) || !$row->$field ) {
|
||||
throw new MWException( $field . ' is not set in the row!' );
|
||||
throw new InvalidArgumentException( $field . ' is not set in the row!' );
|
||||
}
|
||||
}
|
||||
$obj = new self();
|
||||
|
|
|
@ -122,14 +122,13 @@ class MWEchoNotifUser {
|
|||
}
|
||||
|
||||
/**
|
||||
* Factory method
|
||||
* Factory method. The caller should make sure that the user is registered.
|
||||
* @param UserIdentity $user
|
||||
* @throws MWException
|
||||
* @return MWEchoNotifUser
|
||||
*/
|
||||
public static function newFromUser( UserIdentity $user ) {
|
||||
if ( !$user->isRegistered() ) {
|
||||
throw new MWException( 'User must be logged in to view notification!' );
|
||||
throw new InvalidArgumentException( 'User must be logged in to view notification!' );
|
||||
}
|
||||
$services = MediaWikiServices::getInstance();
|
||||
return new MWEchoNotifUser(
|
||||
|
|
|
@ -73,7 +73,7 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
]
|
||||
)
|
||||
);
|
||||
$this->expectException( MWException::class );
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
$eventMapper->fetchById( 1 );
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class NotificationTest extends MediaWikiIntegrationTestCase {
|
|||
$row = $this->mockNotificationRow();
|
||||
// Provide an invalid event id
|
||||
$row['notification_event'] = -1;
|
||||
$this->expectException( MWException::class );
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
Notification::newFromRow( (object)$row );
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class AbstractMapperTest extends MediaWikiUnitTestCase {
|
|||
|
||||
public function testAttachListenerWithException() {
|
||||
$mapper = new EchoAbstractMapperStub();
|
||||
$this->expectException( MWException::class );
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
$mapper->attachListener( 'nonExistingMethod', 'key_a', static function () {
|
||||
} );
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class AbstractMapperTest extends MediaWikiUnitTestCase {
|
|||
/** @var AbstractMapper $mapper */
|
||||
$mapper = $data['mapper'];
|
||||
|
||||
$this->expectException( MWException::class );
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
$mapper->getMethodListeners( 'nonExistingMethod' );
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class TargetPageTest extends MediaWikiUnitTestCase {
|
|||
$row = (object)[
|
||||
'etp_event' => 3
|
||||
];
|
||||
$this->expectException( MWException::class );
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
TargetPage::newFromRow( $row );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue