diff options
28 files changed, 59 insertions, 102 deletions
diff --git a/includes/HookContainer/HookContainer.php b/includes/HookContainer/HookContainer.php index 31636c0a708e..b324a04628f2 100644 --- a/includes/HookContainer/HookContainer.php +++ b/includes/HookContainer/HookContainer.php @@ -30,7 +30,6 @@ use Error; use InvalidArgumentException; use LogicException; use MWDebug; -use MWException; use UnexpectedValueException; use Wikimedia\Assert\Assert; use Wikimedia\NonSerializable\NonSerializableTrait; @@ -107,12 +106,11 @@ class HookContainer implements SalvageableService { * * @param HookContainer|SalvageableService $other The object to salvage state from. $other be * of type HookContainer - * @throws MWException */ public function salvage( SalvageableService $other ) { Assert::parameterType( self::class, $other, '$other' ); if ( $this->handlers || $this->handlerObjects || $this->extraHandlers ) { - throw new MWException( 'salvage() must be called immediately after construction' ); + throw new LogicException( 'salvage() must be called immediately after construction' ); } $this->handlerObjects = $other->handlerObjects; $this->handlers = $other->handlers; diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index af777fa6ca73..7b0ece335f00 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -223,7 +223,6 @@ abstract class ContentHandler { * @param Content $content * * @return ContentHandler - * @throws MWException * @throws MWUnknownContentModelException */ public static function getForContent( Content $content ) { diff --git a/includes/exception/BadRequestError.php b/includes/exception/BadRequestError.php index 3b0bf669c1bd..ce799e969b81 100644 --- a/includes/exception/BadRequestError.php +++ b/includes/exception/BadRequestError.php @@ -30,10 +30,7 @@ class BadRequestError extends ErrorPageError { /** * @stable to override - * @param int $action - * - * @throws FatalError - * @throws MWException + * @inheritDoc */ public function report( $action = self::SEND_OUTPUT ) { global $wgOut; diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index 1041afc40321..74f5a82bb4ee 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -169,7 +169,8 @@ class JobQueueDB extends JobQueue { /** * @see JobQueue::doGetAbandonedCount() * @return int - * @throws MWException on database error + * @throws JobQueueConnectionError + * @throws JobQueueError */ protected function doGetAbandonedCount() { if ( $this->claimTTL <= 0 ) { @@ -514,12 +515,13 @@ class JobQueueDB extends JobQueue { /** * @see JobQueue::doAck() * @param RunnableJob $job - * @throws MWException When the job is invalid or on database error. + * @throws JobQueueConnectionError + * @throws JobQueueError */ protected function doAck( RunnableJob $job ) { $id = $job->getMetadata( 'id' ); if ( $id === null ) { - throw new MWException( "Job of type '{$job->getType()}' has no ID." ); + throw new UnexpectedValueException( "Job of type '{$job->getType()}' has no ID." ); } $dbw = $this->getPrimaryDB(); @@ -541,7 +543,7 @@ class JobQueueDB extends JobQueue { /** * @see JobQueue::doDeduplicateRootJob() * @param IJobSpecification $job - * @throws MWException When a database or job error occurs. + * @throws JobQueueConnectionError * @return bool */ protected function doDeduplicateRootJob( IJobSpecification $job ) { diff --git a/includes/jobqueue/jobs/CategoryMembershipChangeJob.php b/includes/jobqueue/jobs/CategoryMembershipChangeJob.php index f1f537595be2..d72c36e0cc66 100644 --- a/includes/jobqueue/jobs/CategoryMembershipChangeJob.php +++ b/includes/jobqueue/jobs/CategoryMembershipChangeJob.php @@ -174,7 +174,6 @@ class CategoryMembershipChangeJob extends Job { * @param LBFactory $lbFactory * @param WikiPage $page * @param RevisionRecord $newRev - * @throws MWException */ protected function notifyUpdatesForRevision( LBFactory $lbFactory, WikiPage $page, RevisionRecord $newRev diff --git a/includes/language/LCStoreCDB.php b/includes/language/LCStoreCDB.php index c6554ffa19a0..d56f057a069e 100644 --- a/includes/language/LCStoreCDB.php +++ b/includes/language/LCStoreCDB.php @@ -85,7 +85,7 @@ class LCStoreCDB implements LCStore { public function startWrite( $code ) { if ( !is_dir( $this->directory ) && !wfMkdirParents( $this->directory, null, __METHOD__ ) ) { - throw new MWException( "Unable to create the localisation store " . + throw new RuntimeException( "Unable to create the localisation store " . "directory \"{$this->directory}\"" ); } @@ -94,21 +94,12 @@ class LCStoreCDB implements LCStore { $this->readers[$code]->close(); } - try { - $this->writer = Writer::open( $this->getFileName( $code ) ); - } catch ( CdbException $e ) { - throw new MWException( $e->getMessage() ); - } + $this->writer = Writer::open( $this->getFileName( $code ) ); $this->currentLang = $code; } public function finishWrite() { - // Close the writer - try { - $this->writer->close(); - } catch ( CdbException $e ) { - throw new MWException( $e->getMessage() ); - } + $this->writer->close(); $this->writer = null; unset( $this->readers[$this->currentLang] ); $this->currentLang = null; @@ -116,18 +107,14 @@ class LCStoreCDB implements LCStore { public function set( $key, $value ) { if ( $this->writer === null ) { - throw new MWException( __CLASS__ . ': must call startWrite() before calling set()' ); - } - try { - $this->writer->set( $key, serialize( $value ) ); - } catch ( CdbException $e ) { - throw new MWException( $e->getMessage() ); + throw new LogicException( __CLASS__ . ': must call startWrite() before calling set()' ); } + $this->writer->set( $key, serialize( $value ) ); } protected function getFileName( $code ) { if ( strval( $code ) === '' || strpos( $code, '/' ) !== false ) { - throw new MWException( __METHOD__ . ": Invalid language \"$code\"" ); + throw new InvalidArgumentException( __METHOD__ . ": Invalid language \"$code\"" ); } return "{$this->directory}/l10n_cache-$code.cdb"; diff --git a/includes/language/LCStoreDB.php b/includes/language/LCStoreDB.php index d9b1ab063f4d..4da99383ffce 100644 --- a/includes/language/LCStoreDB.php +++ b/includes/language/LCStoreDB.php @@ -71,7 +71,7 @@ class LCStoreDB implements LCStore { if ( $this->readOnly ) { return; } elseif ( !$code ) { - throw new MWException( __METHOD__ . ": Invalid language \"$code\"" ); + throw new InvalidArgumentException( __METHOD__ . ": Invalid language \"$code\"" ); } $dbw = $this->getWriteConnection(); @@ -85,7 +85,7 @@ class LCStoreDB implements LCStore { if ( $this->readOnly ) { return; } elseif ( $this->code === null ) { - throw new MWException( __CLASS__ . ': must call startWrite() before finishWrite()' ); + throw new LogicException( __CLASS__ . ': must call startWrite() before finishWrite()' ); } $scope = Profiler::instance()->getTransactionProfiler()->silenceForScope(); @@ -121,7 +121,7 @@ class LCStoreDB implements LCStore { if ( $this->readOnly ) { return; } elseif ( $this->code === null ) { - throw new MWException( __CLASS__ . ': must call startWrite() before set()' ); + throw new LogicException( __CLASS__ . ': must call startWrite() before set()' ); } $dbw = $this->getWriteConnection(); @@ -142,7 +142,7 @@ class LCStoreDB implements LCStore { $dbFactory = MediaWikiServices::getInstance()->getDatabaseFactory(); $this->dbw = $dbFactory->create( $this->server['type'], $this->server ); if ( !$this->dbw ) { - throw new MWException( __CLASS__ . ': failed to obtain a DB connection' ); + throw new RuntimeException( __CLASS__ . ': failed to obtain a DB connection' ); } } else { $this->dbw = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getPrimaryDatabase(); diff --git a/includes/language/LanguageNameUtils.php b/includes/language/LanguageNameUtils.php index 2ac076474318..313b3df019f0 100644 --- a/includes/language/LanguageNameUtils.php +++ b/includes/language/LanguageNameUtils.php @@ -22,13 +22,13 @@ namespace MediaWiki\Languages; use BagOStuff; use HashBagOStuff; +use InvalidArgumentException; use LanguageCode; use MediaWiki\Config\ServiceOptions; use MediaWiki\HookContainer\HookContainer; use MediaWiki\HookContainer\HookRunner; use MediaWiki\MainConfigNames; use MediaWiki\Title\MediaWikiTitleCodec; -use MWException; /** * A service that provides utilities to do with language names and codes. @@ -302,12 +302,11 @@ class LanguageNameUtils { * @param string $prefix Prepend this to the filename * @param string $code Language code * @param string $suffix Append this to the filename - * @throws MWException * @return string $prefix . $mangledCode . $suffix */ public function getFileName( $prefix, $code, $suffix = '.php' ) { if ( !$this->isValidBuiltInCode( $code ) ) { - throw new MWException( "Invalid language code \"$code\"" ); + throw new InvalidArgumentException( "Invalid language code \"$code\"" ); } return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix; @@ -327,13 +326,12 @@ class LanguageNameUtils { /** * @param string $code * @return string - * @throws MWException */ public function getJsonMessagesFileName( $code ) { global $IP; if ( !$this->isValidBuiltInCode( $code ) ) { - throw new MWException( "Invalid language code \"$code\"" ); + throw new InvalidArgumentException( "Invalid language code \"$code\"" ); } return "$IP/languages/i18n/$code.json"; diff --git a/includes/language/LocalisationCache.php b/includes/language/LocalisationCache.php index 9c38d1d8bf90..b3d16ce7dc25 100644 --- a/includes/language/LocalisationCache.php +++ b/includes/language/LocalisationCache.php @@ -290,7 +290,7 @@ class LocalisationCache { } elseif ( $conf['store'] === 'array' ) { $storeClass = LCStoreStaticArray::class; } else { - throw new MWException( + throw new ConfigException( 'Please set $wgLocalisationCacheConf[\'store\'] to something sensible.' ); } @@ -586,7 +586,6 @@ class LocalisationCache { * Initialise a language in this object. Rebuild the cache if necessary. * * @param string $code - * @throws MWException */ private function initLanguage( $code ) { if ( isset( $this->initialisedLangs[$code] ) ) { @@ -607,7 +606,7 @@ class LocalisationCache { if ( $this->langNameUtils->isSupportedLanguage( $code ) ) { $this->recache( $code ); } elseif ( $code === 'en' ) { - throw new MWException( 'MessagesEn.php is missing.' ); + throw new RuntimeException( 'MessagesEn.php is missing.' ); } else { $this->initShallowFallback( $code, 'en' ); } @@ -621,14 +620,14 @@ class LocalisationCache { if ( $this->manualRecache ) { // No Messages*.php file. Do shallow fallback to en. if ( $code === 'en' ) { - throw new MWException( 'No localisation cache found for English. ' . + throw new RuntimeException( 'No localisation cache found for English. ' . 'Please run maintenance/rebuildLocalisationCache.php.' ); } $this->initShallowFallback( $code, 'en' ); return; } else { - throw new MWException( 'Invalid or missing localisation cache.' ); + throw new RuntimeException( 'Invalid or missing localisation cache.' ); } } @@ -687,7 +686,6 @@ class LocalisationCache { * * @param string $_fileName * @param string $_fileType - * @throws MWException * @return array */ protected function readPHPFile( $_fileName, $_fileType ) { @@ -714,7 +712,7 @@ class LocalisationCache { $data['aliases'] = $aliases; } } else { - throw new MWException( __METHOD__ . ": Invalid file type: $_fileType" ); + throw new InvalidArgumentException( __METHOD__ . ": Invalid file type: $_fileType" ); } return $data; @@ -982,7 +980,7 @@ class LocalisationCache { */ private function loadCoreData( string $code ) { if ( !$code ) { - throw new MWException( "Invalid language code requested" ); + throw new InvalidArgumentException( "Invalid language code requested" ); } if ( $this->coreDataLoaded[$code] ?? false ) { return; @@ -1061,11 +1059,10 @@ class LocalisationCache { * and save it to the persistent cache store and the process cache. * * @param string $code - * @throws MWException */ public function recache( $code ) { if ( !$code ) { - throw new MWException( "Invalid language code requested" ); + throw new InvalidArgumentException( "Invalid language code requested" ); } $this->recachedLangs[ $code ] = true; @@ -1186,7 +1183,7 @@ class LocalisationCache { } if ( !isset( $allData['rtl'] ) ) { - throw new MWException( __METHOD__ . ': Localisation data failed validation check! ' . + throw new RuntimeException( __METHOD__ . ': Localisation data failed validation check! ' . 'Check that your languages/messages/MessagesEn.php file is intact.' ); } diff --git a/includes/language/Message.php b/includes/language/Message.php index 921a7797cce2..83543274d323 100644 --- a/includes/language/Message.php +++ b/includes/language/Message.php @@ -188,6 +188,7 @@ class Message implements MessageSpecifier, Serializable { /** * @var string[] List of keys to try when fetching the message. + * @phan-var non-empty-list<string> */ protected $keysToTry; @@ -1476,7 +1477,6 @@ class Message implements MessageSpecifier, Serializable { * @since 1.17 * * @return string|false - * @throws MWException If message key array is empty. */ protected function fetchMessage() { if ( $this->message === null ) { diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 4f3842c6d8e6..e93ffe0dec44 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -33,7 +33,6 @@ use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter; use MediaWiki\Parser\Parsoid\ParsoidRenderID; use MediaWiki\Title\Title; use MediaWiki\Title\TitleValue; -use MWException; use Parser; use UnexpectedValueException; use Wikimedia\Bcp47Code\Bcp47Code; @@ -1086,12 +1085,10 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { /** * @param ParsoidLinkTarget $link must be an interwiki link * (used to require Title until 1.38). - * - * @throws MWException If given invalid input */ public function addInterwikiLink( $link ): void { if ( !$link->isExternal() ) { - throw new MWException( 'Non-interwiki link passed, internal parser error.' ); + throw new InvalidArgumentException( 'Non-interwiki link passed, internal parser error.' ); } $prefix = $link->getInterwiki(); $this->mInterwikiLinks[$prefix][$link->getDBkey()] = 1; diff --git a/includes/password/AbstractPbkdf2Password.php b/includes/password/AbstractPbkdf2Password.php index 3fe84a4629ed..ea0393d9bd31 100644 --- a/includes/password/AbstractPbkdf2Password.php +++ b/includes/password/AbstractPbkdf2Password.php @@ -52,7 +52,6 @@ abstract class AbstractPbkdf2Password extends ParameterizedPassword { * @param array $config Array of engine configuration options for hashing * @param string|null $hash The raw hash, including the type * @return AbstractPbkdf2Password The created object - * @throws Exception If $config does not contain required parameters */ public static function newInstance( PasswordFactory $factory, diff --git a/includes/password/BcryptPassword.php b/includes/password/BcryptPassword.php index 86409325a5ca..df27030572ce 100644 --- a/includes/password/BcryptPassword.php +++ b/includes/password/BcryptPassword.php @@ -48,14 +48,15 @@ class BcryptPassword extends ParameterizedPassword { } /** + * @note Callers should make sure that bcrypt is available before calling this method. + * * @param string $password Password to encrypt * * @throws PasswordError If bcrypt has an unknown error - * @throws MWException If bcrypt is not supported by PHP */ public function crypt( string $password ): void { if ( !defined( 'CRYPT_BLOWFISH' ) ) { - throw new MWException( 'Bcrypt is not supported.' ); + throw new RuntimeException( 'Bcrypt is not supported.' ); } // Either use existing hash or make a new salt diff --git a/includes/password/EncryptedPassword.php b/includes/password/EncryptedPassword.php index 27d4d31fa8de..1f4bcc90aa62 100644 --- a/includes/password/EncryptedPassword.php +++ b/includes/password/EncryptedPassword.php @@ -76,7 +76,7 @@ class EncryptedPassword extends ParameterizedPassword { /** * Updates the underlying hash by encrypting it with the newest secret. * - * @throws MWException If the configuration is not valid + * @throws PasswordError If the configuration is not valid * @return bool True if the password was updated */ public function update(): bool { diff --git a/includes/password/LayeredParameterizedPassword.php b/includes/password/LayeredParameterizedPassword.php index 956e5e6ed341..1b9849dae44b 100644 --- a/includes/password/LayeredParameterizedPassword.php +++ b/includes/password/LayeredParameterizedPassword.php @@ -44,9 +44,11 @@ class LayeredParameterizedPassword extends ParameterizedPassword { $passObj = $this->factory->newFromType( $type ); if ( !$passObj instanceof ParameterizedPassword ) { - throw new MWException( 'Underlying type must be a parameterized password.' ); + throw new UnexpectedValueException( 'Underlying type must be a parameterized password.' ); } elseif ( $passObj->getDelimiter() === $this->getDelimiter() ) { - throw new MWException( 'Underlying type cannot use same delimiter as encapsulating type.' ); + throw new UnexpectedValueException( + 'Underlying type cannot use same delimiter as encapsulating type.' + ); } $params[] = implode( $passObj->getDelimiter(), $passObj->getDefaultParams() ); @@ -95,13 +97,11 @@ class LayeredParameterizedPassword extends ParameterizedPassword { * get an updated hash with all the layers. * * @param ParameterizedPassword $passObj Password hash of the first layer - * - * @throws MWException If the first parameter is not of the correct type */ public function partialCrypt( ParameterizedPassword $passObj ) { $type = $passObj->config['type']; if ( $type !== $this->config['types'][0] ) { - throw new MWException( 'Only a hash in the first layer can be finished.' ); + throw new InvalidArgumentException( 'Only a hash in the first layer can be finished.' ); } // Gather info from the existing hash diff --git a/includes/password/Password.php b/includes/password/Password.php index c33bbef498fc..ed522c3c77f4 100644 --- a/includes/password/Password.php +++ b/includes/password/Password.php @@ -87,18 +87,16 @@ abstract class Password { * It is strongly recommended not to call this function directly unless you * have a reason to. Use the PasswordFactory class instead. * - * @throws MWException If $config does not contain required parameters - * * @param PasswordFactory $factory Factory object that created the password * @param array $config Array of engine configuration options for hashing * @param string|null $hash The raw hash, including the type */ final public function __construct( PasswordFactory $factory, array $config, string $hash = null ) { if ( !$this->isSupported() ) { - throw new Exception( 'PHP support not found for ' . get_class( $this ) ); + throw new RuntimeException( 'PHP support not found for ' . get_class( $this ) ); } if ( !isset( $config['type'] ) ) { - throw new Exception( 'Password configuration must contain a type name.' ); + throw new InvalidArgumentException( 'Password configuration must contain a type name.' ); } $this->config = $config; $this->factory = $factory; diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 7f0e4fdc35d7..d5b0ad5cba2b 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -164,7 +164,6 @@ abstract class Profiler { /** * Get all usable outputs. * - * @throws MWException * @return ProfilerOutput[] * @since 1.25 */ @@ -178,7 +177,7 @@ abstract class Profiler { ? 'ProfilerOutput' . ucfirst( $outputType ) : $outputType; if ( !class_exists( $outputClass ) ) { - throw new MWException( "'$outputType' is an invalid output type" ); + throw new UnexpectedValueException( "'$outputType' is an invalid output type" ); } $outputInstance = new $outputClass( $this, $this->params ); if ( $outputInstance->canUse() ) { @@ -223,7 +222,6 @@ abstract class Profiler { /** * Log the data to the script/request output for all ProfilerOutput instances that do so * - * @throws MWException * @since 1.26 */ public function logDataPageOutputOnly() { diff --git a/includes/specialpage/QueryPage.php b/includes/specialpage/QueryPage.php index 07fa7a098653..e1824097519f 100644 --- a/includes/specialpage/QueryPage.php +++ b/includes/specialpage/QueryPage.php @@ -24,6 +24,7 @@ namespace MediaWiki\SpecialPage; use Exception; +use LogicException; use MediaWiki\Cache\LinkBatchFactory; use MediaWiki\Config\Config; use MediaWiki\HookContainer\HookRunner; @@ -65,7 +66,6 @@ use MediaWiki\Specials\SpecialWantedPages; use MediaWiki\Specials\SpecialWantedTemplates; use MediaWiki\Specials\SpecialWithoutInterwiki; use MWDebug; -use MWException; use Skin; use stdClass; use Wikimedia\Rdbms\DBError; @@ -267,13 +267,12 @@ abstract class QueryPage extends SpecialPage { /** * For back-compat, subclasses may return a raw SQL query here, as a string. * @deprecated since 1.39; getQueryInfo() should be overridden instead. - * @throws MWException * @return string * @suppress PhanPluginNeverReturnMethod */ protected function getSQL() { wfDeprecated( __METHOD__, '1.39' ); - throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor " + throw new LogicException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor " . "getQuery() properly" ); } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index af91d98e0abd..1edc2d8a559c 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -53,7 +53,6 @@ use MediaWiki\User\UserIdentityLookup; use MediaWiki\User\UserNamePrefixSearch; use MediaWiki\User\UserNameUtils; use MediaWiki\User\UserRigorOptions; -use MWException; use Wikimedia\IPUtils; use Wikimedia\Rdbms\IConnectionProvider; @@ -960,7 +959,6 @@ class SpecialContributions extends IncludableSpecialPage { /** * @inheritDoc - * @throws MWException */ public function getAssociatedNavigationLinks(): array { if ( diff --git a/includes/specials/SpecialRevisionDelete.php b/includes/specials/SpecialRevisionDelete.php index 2e24da5a9007..b139c55f1152 100644 --- a/includes/specials/SpecialRevisionDelete.php +++ b/includes/specials/SpecialRevisionDelete.php @@ -36,7 +36,6 @@ use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\SpecialPage\UnlistedSpecialPage; use MediaWiki\Status\Status; use MediaWiki\Title\Title; -use MWException; use PermissionsError; use RepoGroup; use RevDelList; @@ -352,8 +351,6 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { * Show a deleted file version requested by the visitor. * @todo Mostly copied from Special:Undelete. Refactor. * @param string $archiveName - * @throws MWException - * @throws PermissionsError */ protected function tryShowFile( $archiveName ) { $repo = $this->repoGroup->getLocalRepo(); diff --git a/includes/specials/SpecialUserLogout.php b/includes/specials/SpecialUserLogout.php index a4cbe0f91433..6f7e5931edf2 100644 --- a/includes/specials/SpecialUserLogout.php +++ b/includes/specials/SpecialUserLogout.php @@ -29,9 +29,6 @@ use MediaWiki\Session\SessionManager; use MediaWiki\SpecialPage\FormSpecialPage; use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Status\Status; -use MWException; -use PermissionsError; -use ThrottledError; /** * Implements Special:Userlogout @@ -94,8 +91,6 @@ class SpecialUserLogout extends FormSpecialPage { * userCanExecute(), and if the data array contains 'Username', etc, then Username * resets are allowed. * @param array $data - * @throws MWException - * @throws ThrottledError|PermissionsError * @return Status */ public function onSubmit( array $data ) { diff --git a/includes/specials/pagers/ImageListPager.php b/includes/specials/pagers/ImageListPager.php index c0bb7e64033f..d4edfdcb5a71 100644 --- a/includes/specials/pagers/ImageListPager.php +++ b/includes/specials/pagers/ImageListPager.php @@ -33,8 +33,8 @@ use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Title\Title; use MediaWiki\User\User; use MediaWiki\User\UserNameUtils; -use MWException; use RepoGroup; +use UnexpectedValueException; use UserCache; use Wikimedia\Rdbms\FakeResultWrapper; use Wikimedia\Rdbms\IConnectionProvider; @@ -320,7 +320,6 @@ class ImageListPager extends TablePager { * @param int $limit * @param bool $order IndexPager::QUERY_ASCENDING or IndexPager::QUERY_DESCENDING * @return IResultWrapper - * @throws MWException */ public function reallyDoQuery( $offset, $limit, $order ) { $dbr = $this->getDatabase(); @@ -341,10 +340,11 @@ class ImageListPager extends TablePager { $oldIndex = $this->mIndexField; foreach ( $this->mIndexField as &$index ) { if ( !str_starts_with( $index, 'img_' ) ) { - throw new MWException( "Expected to be sorting on an image table field" ); + throw new UnexpectedValueException( "Expected to be sorting on an image table field" ); } $index = 'oi_' . substr( $index, 4 ); } + unset( $index ); [ $tables, $fields, $conds, $fname, $options, $join_conds ] = $this->buildQueryInfo( $offset, $limit, $order ); @@ -436,7 +436,6 @@ class ImageListPager extends TablePager { * @param string $field * @param string|null $value * @return string - * @throws MWException */ public function formatValue( $field, $value ) { $linkRenderer = $this->getLinkRenderer(); @@ -520,7 +519,7 @@ class ImageListPager extends TablePager { // Messages: listfiles-latestversion-yes, listfiles-latestversion-no return $this->msg( 'listfiles-latestversion-' . $value )->escaped(); default: - throw new MWException( "Unknown field '$field'" ); + throw new UnexpectedValueException( "Unknown field '$field'" ); } } diff --git a/includes/specials/pagers/ProtectedPagesPager.php b/includes/specials/pagers/ProtectedPagesPager.php index 9aab5fc68969..8b88176a8cd5 100644 --- a/includes/specials/pagers/ProtectedPagesPager.php +++ b/includes/specials/pagers/ProtectedPagesPager.php @@ -31,7 +31,7 @@ use MediaWiki\Html\Html; use MediaWiki\Linker\Linker; use MediaWiki\Linker\LinkRenderer; use MediaWiki\Title\Title; -use MWException; +use UnexpectedValueException; use UserCache; use Wikimedia\Rdbms\IConnectionProvider; @@ -165,7 +165,6 @@ class ProtectedPagesPager extends TablePager { * @param string $field * @param string|null $value * @return string HTML - * @throws MWException */ public function formatValue( $field, $value ) { /** @var stdClass $row */ @@ -292,7 +291,7 @@ class ProtectedPagesPager extends TablePager { break; default: - throw new MWException( "Unknown field '$field'" ); + throw new UnexpectedValueException( "Unknown field '$field'" ); } return $formatted; diff --git a/includes/title/ForeignTitle.php b/includes/title/ForeignTitle.php index 86cef063f528..04fc499bfb9e 100644 --- a/includes/title/ForeignTitle.php +++ b/includes/title/ForeignTitle.php @@ -23,7 +23,7 @@ namespace MediaWiki\Title; -use MWException; +use RuntimeException; /** * A simple, immutable structure to hold the title of a page on a foreign @@ -67,13 +67,12 @@ class ForeignTitle { } /** + * @note Callers should make sure that isNamespaceIdKnown() is true before calling this method. * @return int - * @throws MWException If isNamespaceIdKnown() is false, it does not make - * sense to call this function. */ public function getNamespaceId() { if ( $this->namespaceId === null ) { - throw new MWException( + throw new RuntimeException( "Attempted to call getNamespaceId when the namespace ID is not known" ); } return $this->namespaceId; diff --git a/tests/phpunit/includes/specials/ImageListPagerTest.php b/tests/phpunit/includes/specials/ImageListPagerTest.php index 73ea77188794..e1d9121397ea 100644 --- a/tests/phpunit/includes/specials/ImageListPagerTest.php +++ b/tests/phpunit/includes/specials/ImageListPagerTest.php @@ -31,7 +31,7 @@ class ImageListPagerTest extends MediaWikiIntegrationTestCase { false, false ); - $this->expectException( MWException::class ); + $this->expectException( UnexpectedValueException::class ); $this->expectExceptionMessage( "invalid_field" ); $page->formatValue( 'invalid_field', 'invalid_value' ); } diff --git a/tests/phpunit/unit/includes/HookContainer/HookContainerTest.php b/tests/phpunit/unit/includes/HookContainer/HookContainerTest.php index 15934a6047dc..e57c158817f0 100644 --- a/tests/phpunit/unit/includes/HookContainer/HookContainerTest.php +++ b/tests/phpunit/unit/includes/HookContainer/HookContainerTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\HookContainer { use Error; use InvalidArgumentException; + use LogicException; use MediaWiki\Tests\Unit\DummyServicesTrait; use MediaWikiUnitTestCase; use stdClass; @@ -177,7 +178,7 @@ namespace MediaWiki\HookContainer { $secondHookContainer->register( 'TestHook', self::HANDLER_FUNCTION ); - $this->expectException( \MWException::class ); + $this->expectException( LogicException::class ); $secondHookContainer->salvage( $firstHookContainer ); } diff --git a/tests/phpunit/unit/includes/language/LanguageNameUtilsTestTrait.php b/tests/phpunit/unit/includes/language/LanguageNameUtilsTestTrait.php index 3a2d368cd0bb..9de5e9f2df9a 100644 --- a/tests/phpunit/unit/includes/language/LanguageNameUtilsTestTrait.php +++ b/tests/phpunit/unit/includes/language/LanguageNameUtilsTestTrait.php @@ -532,7 +532,7 @@ trait LanguageNameUtilsTestTrait { * @param string $code */ public function testExceptionFromInvalidCode( $callback, $code ) { - $this->expectException( MWException::class ); + $this->expectException( InvalidArgumentException::class ); $this->expectExceptionMessage( "Invalid language code \"$code\"" ); $callback( $code ); diff --git a/tests/phpunit/unit/includes/title/ForeignTitleTest.php b/tests/phpunit/unit/includes/title/ForeignTitleTest.php index 712692e7fd71..7b77b4733c66 100644 --- a/tests/phpunit/unit/includes/title/ForeignTitleTest.php +++ b/tests/phpunit/unit/includes/title/ForeignTitleTest.php @@ -70,7 +70,7 @@ class ForeignTitleTest extends \MediaWikiUnitTestCase { } public function testUnknownNamespaceError() { - $this->expectException( MWException::class ); + $this->expectException( RuntimeException::class ); $title = new ForeignTitle( null, 'this', 'that' ); $title->getNamespaceId(); } |