Use precise ApiMain/ApiQuery type hints in all API modules

Which type is used depends on the ApiModuleManager responsible for
the API module. There are two managers, one in ApiMain and one in
ApiQuery. Both contain a list of API modules they instantiate.
Both use $this as the first parameter in the constructors of the
individual modules. There is no other regular way to instantiate the
modules, so we know the type must either be ApiMain or ApiQuery.

The lists don't intersect.

I would have prefered the naming scheme $mainModule for ApiMain
modules and $queryModule for ApiQuery modules but since this
doesn't add much I left the shorter variable names untouched.

Change-Id: Ie6bf19150f1c9b619655a06a8e051412665e54db
This commit is contained in:
Thiemo Mättig 2014-03-25 18:22:11 +01:00 committed by Brad Jorsch
parent e10b688d5f
commit 23632a4ecd
57 changed files with 73 additions and 65 deletions

View file

@ -34,12 +34,11 @@ abstract class ApiFormatBase extends ApiBase {
private $mBufferResult = false, $mBuffer, $mDisabled = false;
/**
* Constructor
* If $format ends with 'fm', pretty-print the output in HTML.
* @param ApiMain $main
* @param string $format Format name
*/
public function __construct( $main, $format ) {
public function __construct( ApiMain $main, $format ) {
parent::__construct( $main, $format );
$this->mIsHtml = ( substr( $format, -2, 2 ) === 'fm' ); // ends with 'fm'
@ -347,7 +346,7 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
*/
class ApiFormatFeedWrapper extends ApiFormatBase {
public function __construct( $main ) {
public function __construct( ApiMain $main ) {
parent::__construct( $main, 'feed' );
}

View file

@ -32,7 +32,7 @@ class ApiFormatJson extends ApiFormatBase {
private $mIsRaw;
public function __construct( $main, $format ) {
public function __construct( ApiMain $main, $format ) {
parent::__construct( $main, $format );
$this->mIsRaw = ( $format === 'rawfm' );
}

View file

@ -31,11 +31,10 @@
class ApiFormatRaw extends ApiFormatBase {
/**
* Constructor
* @param ApiMain $main
* @param ApiFormatBase $errorFallback ApiFormatBase object to fall back on for errors
* @param ApiFormatBase $errorFallback Object to fall back on for errors
*/
public function __construct( $main, $errorFallback ) {
public function __construct( ApiMain $main, ApiFormatBase $errorFallback ) {
parent::__construct( $main, 'raw' );
$this->mErrorFallback = $errorFallback;
}

View file

@ -32,7 +32,7 @@
*/
class ApiLogin extends ApiBase {
public function __construct( $main, $action ) {
public function __construct( ApiMain $main, $action ) {
parent::__construct( $main, $action, 'lg' );
}

View file

@ -33,9 +33,21 @@
*/
class ApiModuleManager extends ContextSource {
/**
* @var ApiBase
*/
private $mParent;
/**
* @var ApiBase[]
*/
private $mInstances = array();
/**
* @var null[]
*/
private $mGroups = array();
/**
* @var array[]
*/
private $mModules = array();
/**

View file

@ -98,7 +98,6 @@ class ApiPageSet extends ApiBase {
}
/**
* Constructor
* @param ApiBase $dbSource Module implementing getDB().
* Allows PageSet to reuse existing db connection from the shared state like ApiQuery.
* @param int $flags Zero or more flags like DISABLE_GENERATORS

View file

@ -34,7 +34,7 @@ class ApiParamInfo extends ApiBase {
*/
protected $queryObj;
public function __construct( $main, $action ) {
public function __construct( ApiMain $main, $action ) {
parent::__construct( $main, $action );
$this->queryObj = new ApiQuery( $this->getMain(), 'query' );
}

View file

@ -125,7 +125,7 @@ class ApiQuery extends ApiBase {
* @param ApiMain $main
* @param string $action
*/
public function __construct( $main, $action ) {
public function __construct( ApiMain $main, $action ) {
parent::__construct( $main, $action );
$this->mModuleMgr = new ApiModuleManager( $this );

View file

@ -32,7 +32,7 @@
*/
class ApiQueryAllCategories extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ac' );
}

View file

@ -34,7 +34,7 @@
class ApiQueryAllImages extends ApiQueryGeneratorBase {
protected $mRepo;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ai' );
$this->mRepo = RepoGroup::singleton()->getLocalRepo();
}

View file

@ -39,7 +39,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
private $useIndex = null;
private $props = array(), $propHelp = array();
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
switch ( $moduleName ) {
case 'alllinks':
$prefix = 'al';

View file

@ -31,7 +31,7 @@
*/
class ApiQueryAllMessages extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'am' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryAllPages extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ap' );
}

View file

@ -30,7 +30,7 @@
* @ingroup API
*/
class ApiQueryAllUsers extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'au' );
}

View file

@ -75,7 +75,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
)
);
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
$settings = $this->backlinksSettings[$moduleName];
$prefix = $settings['prefix'];
$code = $settings['code'];

View file

@ -36,13 +36,13 @@ abstract class ApiQueryBase extends ApiBase {
private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
/**
* @param ApiBase $query
* @param ApiQuery $queryModule
* @param string $moduleName
* @param string $paramPrefix
*/
public function __construct( ApiBase $query, $moduleName, $paramPrefix = '' ) {
parent::__construct( $query->getMain(), $moduleName, $paramPrefix );
$this->mQueryModule = $query;
public function __construct( ApiQuery $queryModule, $moduleName, $paramPrefix = '' ) {
parent::__construct( $queryModule->getMain(), $moduleName, $paramPrefix );
$this->mQueryModule = $queryModule;
$this->mDb = null;
$this->resetQueryParams();
}

View file

@ -36,7 +36,7 @@ class ApiQueryBlocks extends ApiQueryBase {
*/
protected $usernames;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'bk' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryCategories extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'cl' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryCategoryInfo extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ci' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'cm' );
}

View file

@ -38,7 +38,7 @@ class ApiQueryContributors extends ApiQueryBase {
*/
const MAX_PAGES = 100;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
// "pc" is short for "page contributors", "co" was already taken by the
// GeoData extension's prop=coordinates.
parent::__construct( $query, $moduleName, 'pc' );

View file

@ -31,7 +31,7 @@
*/
class ApiQueryDeletedrevs extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'dr' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'df' );
}

View file

@ -29,7 +29,7 @@
*/
class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'eu' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryExternalLinks extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'el' );
}

View file

@ -29,7 +29,7 @@
*/
class ApiQueryFileRepoInfo extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'fri' );
}

View file

@ -33,7 +33,7 @@
*/
class ApiQueryFilearchive extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'fa' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'iwbl' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryIWLinks extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'iw' );
}

View file

@ -33,7 +33,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
const TRANSFORM_LIMIT = 50;
private static $transformCount = 0;
public function __construct( $query, $moduleName, $prefix = 'ii' ) {
public function __construct( ApiQuery $query, $moduleName, $prefix = 'ii' ) {
// We allow a subclass to override the prefix, to create a related API
// module. Some other parts of MediaWiki construct this with a null
// $prefix, which used to be ignored when this only took two arguments

View file

@ -32,7 +32,7 @@
*/
class ApiQueryImages extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'im' );
}

View file

@ -48,7 +48,7 @@ class ApiQueryInfo extends ApiQueryBase {
private $tokenFunctions;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'in' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'lbl' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryLangLinks extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'll' );
}

View file

@ -36,7 +36,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
private $table, $prefix, $description, $helpUrl;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
switch ( $moduleName ) {
case self::LINKS:
$this->table = 'pagelinks';

View file

@ -31,7 +31,7 @@
*/
class ApiQueryLogEvents extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'le' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryPagePropNames extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ppn' );
}

View file

@ -33,7 +33,7 @@ class ApiQueryPageProps extends ApiQueryBase {
private $params;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'pp' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryPagesWithProp extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'pwp' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'pt' );
}

View file

@ -32,7 +32,7 @@
class ApiQueryQueryPage extends ApiQueryGeneratorBase {
private $qpMap;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'qp' );
// Build mapping from special page names to QueryPage classes
global $wgAPIUselessQueryPages;

View file

@ -33,7 +33,7 @@
class ApiQueryRandom extends ApiQueryGeneratorBase {
private $pageIDs;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rn' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rc' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryRedirects extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rd' );
}

View file

@ -37,7 +37,7 @@ class ApiQueryRevisions extends ApiQueryBase {
private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
$token, $parseContent, $contentFormat;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rv' );
}

View file

@ -39,7 +39,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
*/
const BACKEND_NULL_PARAM = 'database-backed';
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'sr' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQuerySiteinfo extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'si' );
}

View file

@ -27,7 +27,7 @@
*/
class ApiQueryStashImageInfo extends ApiQueryImageInfo {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'sii' );
}

View file

@ -40,7 +40,7 @@ class ApiQueryTags extends ApiQueryBase {
private $fld_displayname = false, $fld_description = false,
$fld_hitcount = false;
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'tg' );
}

View file

@ -31,7 +31,7 @@
*/
class ApiQueryContributions extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'uc' );
}

View file

@ -33,7 +33,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
private $prop = array();
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ui' );
}

View file

@ -50,7 +50,7 @@ class ApiQueryUsers extends ApiQueryBase {
'gender',
);
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'us' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryWatchlist extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'wl' );
}

View file

@ -32,7 +32,7 @@
*/
class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'wr' );
}

View file

@ -59,10 +59,9 @@ class ApiResult extends ApiBase {
private $mData, $mIsRawMode, $mSize, $mCheckingSize;
/**
* Constructor
* @param ApiMain $main
*/
public function __construct( $main ) {
public function __construct( ApiMain $main ) {
parent::__construct( $main, 'result' );
$this->mIsRawMode = false;
$this->mCheckingSize = true;

View file

@ -160,7 +160,7 @@ class ApiRsd extends ApiBase {
}
class ApiFormatXmlRsd extends ApiFormatXml {
public function __construct( $main, $format ) {
public function __construct( ApiMain $main, $format ) {
parent::__construct( $main, $format );
$this->setRootElement( 'rsd' );
}

View file

@ -14,8 +14,8 @@ class PrefixUniquenessTest extends MediaWikiTestCase {
$prefixes = array();
foreach ( $modules as $name => $class ) {
/** @var ApiMain $module */
$module = new $class( $main, $name );
/** @var ApiQueryBase $module */
$module = new $class( $query, $name );
$prefix = $module->getModulePrefix();
if ( isset( $prefixes[$prefix] ) ) {
$this->fail( "Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}" );