aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/GitInfo.php2
-rw-r--r--includes/Maintenance/ForkController.php12
-rw-r--r--includes/api/SearchApi.php2
-rw-r--r--includes/block/BlockActionInfo.php4
-rw-r--r--includes/historyblob/ConcatenatedGzipHistoryBlob.php2
-rw-r--r--includes/media/BitmapHandler.php2
-rw-r--r--includes/media/TiffHandler.php2
-rw-r--r--includes/poolcounter/PoolCounterWorkViaCallback.php4
-rw-r--r--includes/revisiondelete/RevDelRevisionList.php2
-rw-r--r--includes/session/SessionManager.php5
-rw-r--r--includes/site/Site.php34
-rw-r--r--includes/specialpage/RedirectSpecialPage.php2
-rw-r--r--includes/title/NamespaceImportTitleFactory.php2
-rw-r--r--includes/title/SubpageImportTitleFactory.php2
-rw-r--r--tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php17
15 files changed, 34 insertions, 60 deletions
diff --git a/includes/GitInfo.php b/includes/GitInfo.php
index 6b8dd7438afe..5469759a3bc2 100644
--- a/includes/GitInfo.php
+++ b/includes/GitInfo.php
@@ -422,7 +422,7 @@ class GitInfo {
if ( !file_exists( $cacheDir ) &&
!wfMkdirParents( $cacheDir, null, __METHOD__ )
) {
- throw new MWException( "Unable to create GitInfo cache \"{$cacheDir}\"" );
+ throw new RuntimeException( "Unable to create GitInfo cache \"{$cacheDir}\"" );
}
file_put_contents( $this->cacheFile, FormatJson::encode( $this->cache ) );
diff --git a/includes/Maintenance/ForkController.php b/includes/Maintenance/ForkController.php
index 4024c32ce571..d84b9959bcb3 100644
--- a/includes/Maintenance/ForkController.php
+++ b/includes/Maintenance/ForkController.php
@@ -21,9 +21,9 @@
namespace MediaWiki\Maintenance;
use MediaWiki\MediaWikiServices;
-use MWException;
use ObjectCache;
use RedisConnectionPool;
+use RuntimeException;
/**
* Manage forking inside CLI maintenance scripts.
@@ -65,11 +65,15 @@ class ForkController {
*/
public function __construct( $numProcs, $flags = 0 ) {
if ( !wfIsCLI() ) {
- throw new MWException( "MediaWiki\Maintenance\ForkController cannot be used from the web." );
+ throw new RuntimeException( "MediaWiki\Maintenance\ForkController cannot be used from the web." );
} elseif ( !extension_loaded( 'pcntl' ) ) {
- throw new MWException( 'MediaWiki\Maintenance\ForkController requires pcntl extension to be installed.' );
+ throw new RuntimeException(
+ 'MediaWiki\Maintenance\ForkController requires pcntl extension to be installed.'
+ );
} elseif ( !extension_loaded( 'posix' ) ) {
- throw new MWException( 'MediaWiki\Maintenance\ForkController requires posix extension to be installed.' );
+ throw new RuntimeException(
+ 'MediaWiki\Maintenance\ForkController requires posix extension to be installed.'
+ );
}
$this->procsToStart = $numProcs;
$this->flags = $flags;
diff --git a/includes/api/SearchApi.php b/includes/api/SearchApi.php
index fe1a3cc31128..533d957eff0d 100644
--- a/includes/api/SearchApi.php
+++ b/includes/api/SearchApi.php
@@ -41,7 +41,7 @@ trait SearchApi {
// are responsible for setting them (since api modules *can* have services
// injected). Double check that the api module did indeed set them
if ( !$this->searchEngineConfig || !$this->searchEngineFactory ) {
- throw new MWException(
+ throw new LogicException(
'SearchApi requires both a SearchEngineConfig and SearchEngineFactory to be set'
);
}
diff --git a/includes/block/BlockActionInfo.php b/includes/block/BlockActionInfo.php
index d4bcc59b686b..8eb8193a949f 100644
--- a/includes/block/BlockActionInfo.php
+++ b/includes/block/BlockActionInfo.php
@@ -22,7 +22,7 @@ namespace MediaWiki\Block;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\HookContainer\HookRunner;
-use MWException;
+use UnexpectedValueException;
/**
* Defines the actions that can be blocked by a partial block. They are
@@ -94,7 +94,7 @@ class BlockActionInfo {
$this->hookRunner->onGetAllBlockActions( $this->allBlockActions );
}
if ( count( $this->allBlockActions ) !== count( array_unique( $this->allBlockActions ) ) ) {
- throw new MWException( 'Blockable action IDs not unique' );
+ throw new UnexpectedValueException( 'Blockable action IDs not unique' );
}
return $this->allBlockActions;
}
diff --git a/includes/historyblob/ConcatenatedGzipHistoryBlob.php b/includes/historyblob/ConcatenatedGzipHistoryBlob.php
index 823c8ff6f35a..d9a29da655ea 100644
--- a/includes/historyblob/ConcatenatedGzipHistoryBlob.php
+++ b/includes/historyblob/ConcatenatedGzipHistoryBlob.php
@@ -45,7 +45,7 @@ class ConcatenatedGzipHistoryBlob implements HistoryBlob {
public function __construct() {
if ( !function_exists( 'gzdeflate' ) ) {
- throw new MWException( "Need zlib support to read or write this "
+ throw new RuntimeException( "Need zlib support to read or write this "
. "kind of history object (ConcatenatedGzipHistoryBlob)\n" );
}
}
diff --git a/includes/media/BitmapHandler.php b/includes/media/BitmapHandler.php
index 604c4616eb03..057464be58b7 100644
--- a/includes/media/BitmapHandler.php
+++ b/includes/media/BitmapHandler.php
@@ -141,7 +141,7 @@ class BitmapHandler extends TransformationalImageHandler {
case 'yuv420':
return [ '2x2', '1x1', '1x1' ];
default:
- throw new MWException( 'Invalid pixel format for JPEG output' );
+ throw new UnexpectedValueException( 'Invalid pixel format for JPEG output' );
}
}
diff --git a/includes/media/TiffHandler.php b/includes/media/TiffHandler.php
index 08afa6872897..72ec9298cf7a 100644
--- a/includes/media/TiffHandler.php
+++ b/includes/media/TiffHandler.php
@@ -86,7 +86,7 @@ class TiffHandler extends ExifBitmapHandler {
$meta = BitmapMetadataHandler::Tiff( $filename );
if ( !is_array( $meta ) ) {
// This should never happen, but doesn't hurt to be paranoid.
- throw new MWException( 'Metadata array is not an array' );
+ throw new UnexpectedValueException( 'Metadata array is not an array' );
}
$info = [
'width' => $meta['ImageWidth'] ?? 0,
diff --git a/includes/poolcounter/PoolCounterWorkViaCallback.php b/includes/poolcounter/PoolCounterWorkViaCallback.php
index 991b02bc3eef..72aa5949efa2 100644
--- a/includes/poolcounter/PoolCounterWorkViaCallback.php
+++ b/includes/poolcounter/PoolCounterWorkViaCallback.php
@@ -54,13 +54,13 @@ class PoolCounterWorkViaCallback extends PoolCounterWork {
foreach ( [ 'doWork', 'doCachedWork', 'fallback', 'error' ] as $name ) {
if ( isset( $callbacks[$name] ) ) {
if ( !is_callable( $callbacks[$name] ) ) {
- throw new MWException( "Invalid callback provided for '$name' function." );
+ throw new InvalidArgumentException( "Invalid callback provided for '$name' function." );
}
$this->$name = $callbacks[$name];
}
}
if ( !isset( $this->doWork ) ) {
- throw new MWException( "No callback provided for 'doWork' function." );
+ throw new InvalidArgumentException( "No callback provided for 'doWork' function." );
}
$this->cacheable = isset( $this->doCachedWork );
}
diff --git a/includes/revisiondelete/RevDelRevisionList.php b/includes/revisiondelete/RevDelRevisionList.php
index 985024862ed1..7110a1f4fe62 100644
--- a/includes/revisiondelete/RevDelRevisionList.php
+++ b/includes/revisiondelete/RevDelRevisionList.php
@@ -204,7 +204,7 @@ class RevDelRevisionList extends RevDelList {
return new RevDelArchivedRevisionItem( $this, $row );
} else {
// This shouldn't happen. :)
- throw new MWException( 'Invalid row type in RevDelRevisionList' );
+ throw new InvalidArgumentException( 'Invalid row type in RevDelRevisionList' );
}
}
diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php
index 32adf05e2596..ff2f87135171 100644
--- a/includes/session/SessionManager.php
+++ b/includes/session/SessionManager.php
@@ -23,6 +23,7 @@
namespace MediaWiki\Session;
+use BadMethodCallException;
use BagOStuff;
use CachedBagOStuff;
use Config;
@@ -1009,7 +1010,7 @@ class SessionManager implements SessionManagerInterface {
public static function resetCache() {
if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
// @codeCoverageIgnoreStart
- throw new MWException( __METHOD__ . ' may only be called from unit tests!' );
+ throw new BadMethodCallException( __METHOD__ . ' may only be called from unit tests!' );
// @codeCoverageIgnoreEnd
}
@@ -1059,7 +1060,7 @@ class SessionManager implements SessionManagerInterface {
}
try {
$ip = $session->getRequest()->getIP();
- } catch ( \MWException $e ) {
+ } catch ( MWException $e ) {
return;
}
if ( $ip === '127.0.0.1' || $proxyLookup->isConfiguredProxy( $ip ) ) {
diff --git a/includes/site/Site.php b/includes/site/Site.php
index c9169ecfcda1..844e73bbe015 100644
--- a/includes/site/Site.php
+++ b/includes/site/Site.php
@@ -150,11 +150,7 @@ class Site {
* @since 1.21
* @param string|null $globalId
*/
- public function setGlobalId( $globalId ) {
- if ( $globalId !== null && !is_string( $globalId ) ) {
- throw new MWException( '$globalId needs to be string or null' );
- }
-
+ public function setGlobalId( ?string $globalId ) {
$this->globalId = $globalId;
}
@@ -186,11 +182,7 @@ class Site {
* @since 1.21
* @param string $group
*/
- public function setGroup( $group ) {
- if ( !is_string( $group ) ) {
- throw new MWException( '$group needs to be a string' );
- }
-
+ public function setGroup( string $group ) {
$this->group = $group;
}
@@ -211,11 +203,7 @@ class Site {
* @since 1.21
* @param string $source
*/
- public function setSource( $source ) {
- if ( !is_string( $source ) ) {
- throw new MWException( '$source needs to be a string' );
- }
-
+ public function setSource( string $source ) {
$this->source = $source;
}
@@ -238,11 +226,7 @@ class Site {
* @since 1.21
* @param bool $shouldForward
*/
- public function setForward( $shouldForward ) {
- if ( !is_bool( $shouldForward ) ) {
- throw new MWException( '$shouldForward needs to be a boolean' );
- }
-
+ public function setForward( bool $shouldForward ) {
$this->forward = $shouldForward;
}
@@ -287,7 +271,7 @@ class Site {
// Malformed URL
if ( $protocol === false ) {
- throw new MWException( "failed to parse URL '$path'" );
+ throw new UnexpectedValueException( "failed to parse URL '$path'" );
}
// No schema
@@ -311,7 +295,7 @@ class Site {
$type = $this->getLinkPathType();
if ( $type === null ) {
- throw new MWException( "This Site does not support link paths." );
+ throw new RuntimeException( "This Site does not support link paths." );
}
$this->setPath( $type, $fullUrl );
@@ -582,11 +566,7 @@ class Site {
* @param string $pathType
* @param string $fullUrl
*/
- public function setPath( $pathType, $fullUrl ) {
- if ( !is_string( $fullUrl ) ) {
- throw new MWException( '$fullUrl needs to be a string' );
- }
-
+ public function setPath( $pathType, string $fullUrl ) {
if ( !array_key_exists( 'paths', $this->extraData ) ) {
$this->extraData['paths'] = [];
}
diff --git a/includes/specialpage/RedirectSpecialPage.php b/includes/specialpage/RedirectSpecialPage.php
index 608323f7cd15..c1554013e23f 100644
--- a/includes/specialpage/RedirectSpecialPage.php
+++ b/includes/specialpage/RedirectSpecialPage.php
@@ -114,6 +114,6 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
*/
protected function showNoRedirectPage() {
$class = static::class;
- throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
+ throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" );
}
}
diff --git a/includes/title/NamespaceImportTitleFactory.php b/includes/title/NamespaceImportTitleFactory.php
index 51072f6f7e00..ae7b1d03c97a 100644
--- a/includes/title/NamespaceImportTitleFactory.php
+++ b/includes/title/NamespaceImportTitleFactory.php
@@ -43,7 +43,7 @@ class NamespaceImportTitleFactory implements ImportTitleFactory {
int $ns
) {
if ( !$namespaceInfo->exists( $ns ) ) {
- throw new MWException( "Namespace $ns doesn't exist on this wiki" );
+ throw new InvalidArgumentException( "Namespace $ns doesn't exist on this wiki" );
}
$this->titleFactory = $titleFactory;
$this->ns = $ns;
diff --git a/includes/title/SubpageImportTitleFactory.php b/includes/title/SubpageImportTitleFactory.php
index 57b8ac152c9d..e94f9646682b 100644
--- a/includes/title/SubpageImportTitleFactory.php
+++ b/includes/title/SubpageImportTitleFactory.php
@@ -43,7 +43,7 @@ class SubpageImportTitleFactory implements ImportTitleFactory {
Title $rootPage
) {
if ( !$namespaceInfo->hasSubpages( $rootPage->getNamespace() ) ) {
- throw new MWException( "The root page you specified, $rootPage, is in a " .
+ throw new InvalidArgumentException( "The root page you specified, $rootPage, is in a " .
"namespace where subpages are not allowed" );
}
$this->titleFactory = $titleFactory;
diff --git a/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php b/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php
index 3a3413096edf..70835fdff11f 100644
--- a/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php
+++ b/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php
@@ -79,19 +79,8 @@ class SubpageImportTitleFactoryTest extends MediaWikiIntegrationTestCase {
$this->assertTrue( $testTitle->equals( $title ) );
}
- public function failureProvider() {
- return [
- [
- Title::newFromText( 'Graham' ),
- ],
- ];
- }
-
- /**
- * @dataProvider failureProvider
- */
- public function testFailures( Title $rootPage ) {
- $this->expectException( MWException::class );
- $this->newSubpageImportTitleFactory( $rootPage );
+ public function testInvalidNamespace() {
+ $this->expectException( InvalidArgumentException::class );
+ $this->newSubpageImportTitleFactory( Title::newFromText( 'Graham' ) );
}
}