Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated MWException #276

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions includes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MediaWiki\Extension\DynamicPageList3;

use MWException;
use ConfigException;

class Config {
/**
Expand All @@ -25,7 +25,7 @@ public static function init( $settings = false ) {
}

if ( !is_array( $settings ) ) {
throw new MWException( __METHOD__ . ": Invalid settings passed." );
throw new ConfigException( __METHOD__ . ': Invalid settings passed.' );
}

self::$settings = array_merge( self::$settings, $settings );
Expand Down Expand Up @@ -58,7 +58,7 @@ public static function getAllSettings() {
*/
public static function setSetting( $setting, $value = null ) {
if ( empty( $setting ) || !is_string( $setting ) ) {
throw new MWException( __METHOD__ . ": Setting keys can not be blank." );
throw new ConfigException( __METHOD__ . ': Setting keys can not be blank.' );
}

self::$settings[$setting] = $value;
Expand Down
8 changes: 4 additions & 4 deletions includes/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace MediaWiki\Extension\DynamicPageList3;

use InvalidArgumentException;
use MediaWiki\MediaWikiServices;
use MWException;
use PermissionsError;
use RequestContext;
use StringUtils;
Expand Down Expand Up @@ -202,7 +202,7 @@ public function __call( $parameter, $arguments ) {
*/
public static function sortByPriority( $parameters ) {
if ( !is_array( $parameters ) ) {
throw new MWException( __METHOD__ . ': A non-array was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': A non-array was passed.' );
}

// 'category' to get category headings first for ordermethod.
Expand Down Expand Up @@ -241,7 +241,7 @@ public static function sortByPriority( $parameters ) {
*/
private function setSelectionCriteriaFound( $found = true ) {
if ( !is_bool( $found ) ) {
throw new MWException( __METHOD__ . ': A non-boolean was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': A non-boolean was passed.' );
}

$this->selectionCriteriaFound = $found;
Expand All @@ -264,7 +264,7 @@ public function isSelectionCriteriaFound() {
*/
private function setOpenReferencesConflict( $conflict = true ) {
if ( !is_bool( $conflict ) ) {
throw new MWException( __METHOD__ . ': A non-boolean was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': A non-boolean was passed.' );
}

$this->openReferencesConflict = $conflict;
Expand Down
18 changes: 9 additions & 9 deletions includes/ParametersData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MediaWiki\Extension\DynamicPageList3;

use MWException;
use UnexpectedValueException;

class ParametersData {
/**
Expand Down Expand Up @@ -1256,7 +1256,7 @@ public function getDefault( $parameter ) {
return null;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1274,7 +1274,7 @@ public function getValues( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1292,7 +1292,7 @@ public function setsCriteriaFound( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1310,7 +1310,7 @@ public function isOpenReferenceConflict( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1328,7 +1328,7 @@ public function shouldPreserveCase( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1346,7 +1346,7 @@ public function isPageNameList( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1364,7 +1364,7 @@ public function isBoolean( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}

/**
Expand All @@ -1382,6 +1382,6 @@ public function isTimestamp( $parameter ) {
return false;
}

throw new MWException( __METHOD__ . ": Attempted to load a parameter that does not exist." );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to load a parameter that does not exist.' );
}
}
32 changes: 17 additions & 15 deletions includes/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use DateTime;
use Exception;
use ExtensionRegistry;
use InvalidArgumentException;
use LogicException;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserFactory;
use MWException;
use PoolCounterWorkViaCallback;
use UnexpectedValueException;
use WANObjectCache;
use WikiMap;
use Wikimedia\Rdbms\Database;
Expand Down Expand Up @@ -185,7 +187,7 @@
}

if ( $success === false ) {
throw new MWException( __METHOD__ . ": SQL Build Error returned from {$function} for " . serialize( $option ) . "." );
throw new LogicException( __METHOD__ . ": SQL Build Error returned from {$function} for " . serialize( $option ) . '.' );
}

$this->parametersProcessed[$parameter] = true;
Expand Down Expand Up @@ -359,7 +361,7 @@
$this->sqlQuery = $query;
}
} catch ( Exception $e ) {
throw new MWException( __METHOD__ . ': ' . wfMessage( 'dpl_query_error', Hooks::getVersion(), $this->dbr->lastError() )->text() );
throw new LogicException( __METHOD__ . ': ' . wfMessage( 'dpl_query_error', Hooks::getVersion(), $this->dbr->lastError() )->text() );
Dismissed Show dismissed Hide dismissed
}

// Partially taken from intersection
Expand Down Expand Up @@ -473,11 +475,11 @@
*/
public function addTable( $table, $alias ) {
if ( empty( $table ) ) {
throw new MWException( __METHOD__ . ': An empty table name was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty table name was passed.' );
}

if ( empty( $alias ) || is_numeric( $alias ) ) {
throw new MWException( __METHOD__ . ': An empty or numeric table alias was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty or numeric table alias was passed.' );
}

if ( !isset( $this->tables[$alias] ) ) {
Expand Down Expand Up @@ -509,15 +511,15 @@
*/
public function addWhere( $where ) {
if ( empty( $where ) ) {
throw new MWException( __METHOD__ . ': An empty where clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty where clause was passed.' );
}

if ( is_string( $where ) ) {
$this->where[] = $where;
} elseif ( is_array( $where ) ) {
$this->where = array_merge( $this->where, $where );
} else {
throw new MWException( __METHOD__ . ': An invalid where clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An invalid where clause was passed.' );
}

return true;
Expand All @@ -531,15 +533,15 @@
*/
public function addNotWhere( $where ) {
if ( empty( $where ) ) {
throw new MWException( __METHOD__ . ': An empty not where clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty not where clause was passed.' );
}

if ( is_array( $where ) ) {
foreach ( $where as $field => $values ) {
$this->where[] = $field . ( count( $values ) > 1 ? ' NOT IN(' . $this->dbr->makeList( $values ) . ')' : ' != ' . $this->dbr->addQuotes( current( $values ) ) );
}
} else {
throw new MWException( __METHOD__ . ': An invalid NOT WHERE clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An invalid NOT WHERE clause was passed.' );
}

return true;
Expand All @@ -554,13 +556,13 @@
*/
public function addSelect( $fields ) {
if ( !is_array( $fields ) ) {
throw new MWException( __METHOD__ . ': A non-array was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': A non-array was passed.' );
}

foreach ( $fields as $alias => $field ) {
if ( !is_numeric( $alias ) && array_key_exists( $alias, $this->select ) && $this->select[$alias] != $field ) {
// In case of a code bug that is overwriting an existing field alias throw an exception.
throw new MWException( __METHOD__ . ": Attempted to overwrite existing field alias `{$this->select[$alias]}` AS `{$alias}` with `{$field}` AS `{$alias}`." );
throw new UnexpectedValueException( __METHOD__ . ": Attempted to overwrite existing field alias `{$this->select[$alias]}` AS `{$alias}` with `{$field}` AS `{$alias}`." );
}

// String alias and does not exist already.
Expand All @@ -586,7 +588,7 @@
*/
public function addGroupBy( $groupBy ) {
if ( empty( $groupBy ) ) {
throw new MWException( __METHOD__ . ': An empty GROUP BY clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty GROUP BY clause was passed.' );
}

$this->groupBy[] = $groupBy;
Expand All @@ -602,7 +604,7 @@
*/
public function addOrderBy( $orderBy ) {
if ( empty( $orderBy ) ) {
throw new MWException( __METHOD__ . ': An empty ORDER BY clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty ORDER BY clause was passed.' );
}

$this->orderBy[] = $orderBy;
Expand All @@ -619,11 +621,11 @@
*/
public function addJoin( $tableAlias, $joinConditions ) {
if ( empty( $tableAlias ) || empty( $joinConditions ) ) {
throw new MWException( __METHOD__ . ': An empty JOIN clause was passed.' );
throw new InvalidArgumentException( __METHOD__ . ': An empty JOIN clause was passed.' );
}

if ( isset( $this->join[$tableAlias] ) ) {
throw new MWException( __METHOD__ . ': Attempted to overwrite existing JOIN clause.' );
throw new UnexpectedValueException( __METHOD__ . ': Attempted to overwrite existing JOIN clause.' );
}

$this->join[$tableAlias] = $joinConditions;
Expand Down
Loading