jenkins-bot has submitted this change and it was merged.
Change subject: API Remove $wgAPIGeneratorModules - it's dynamic now
......................................................................
API Remove $wgAPIGeneratorModules - it's dynamic now
* $wgAPIGeneratorModules is now obsolete and will be ignored
* Removed generator tests - obsolete because there is no more list
Change-Id: I014260a42226854a2178345dc3cd0f50b41b3c08
---
M RELEASE-NOTES-1.21
M includes/DefaultSettings.php
M includes/api/ApiPageSet.php
M includes/api/ApiQuery.php
D tests/phpunit/includes/api/ApiGeneratorTest.php
5 files changed, 30 insertions(+), 125 deletions(-)
Approvals:
Anomie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21
index 7e06218..05dc4b7 100644
--- a/RELEASE-NOTES-1.21
+++ b/RELEASE-NOTES-1.21
@@ -224,6 +224,7 @@
first one keeping its meaning. ApiPageSet is now derived from ApiBase.
* BREAKING CHANGE: ApiQuery::newGenerator() and executeGeneratorModule() were
deleted.
* ApiQueryGeneratorBase::setGeneratorMode() now requires a pageset param.
+* $wgAPIGeneratorModules is now obsolete and will be ignored.
=== Languages updated in 1.21 ===
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index fc8168d..173f31e 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6082,6 +6082,11 @@
$wgAPIMetaModules = array();
$wgAPIPropModules = array();
$wgAPIListModules = array();
+
+/**
+ * This variable is ignored. To add your module to the API, please add it to
$wgAPI*Modules
+ * @deprecated since 1.21
+ */
$wgAPIGeneratorModules = array();
/**
diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php
index 3945104..954e5a1 100644
--- a/includes/api/ApiPageSet.php
+++ b/includes/api/ApiPageSet.php
@@ -956,8 +956,13 @@
'converttitles' => false,
);
if ( $this->mAllowGenerator ) {
- $result['generator'] = array(
- ApiBase::PARAM_TYPE => $this->getGenerators() );
+ if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
+ $result['generator'] = array(
+ ApiBase::PARAM_TYPE =>
$this->getGenerators()
+ );
+ } else {
+ $result['generator'] = null;
+ }
}
return $result;
}
@@ -976,7 +981,13 @@
// we must create it to get module manager
$query =
$this->getMain()->getModuleManager()->getModule( 'query' );
}
- $gens = array_keys( $query->getGenerators() );
+ $gens = array();
+ $mgr = $query->getModuleManager();
+ foreach ( $mgr->getNamesWithClasses() as $name =>
$class ) {
+ if ( is_subclass_of( $class,
'ApiQueryGeneratorBase' ) ) {
+ $gens[] = $name;
+ }
+ }
sort( $gens );
self::$generators = $gens;
}
diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php
index c1a0407..a25e78c 100644
--- a/includes/api/ApiQuery.php
+++ b/includes/api/ApiQuery.php
@@ -103,39 +103,6 @@
);
/**
- * List of Api Query generator modules
- * Defined in code, rather than being derived at runtime,
- * due to performance reasons
- * @var array
- */
- private $mQueryGenerators = array(
- 'allcategories' => 'ApiQueryAllCategories',
- 'allimages' => 'ApiQueryAllImages',
- 'alllinks' => 'ApiQueryAllLinks',
- 'allpages' => 'ApiQueryAllPages',
- 'alltransclusions' => 'ApiQueryAllLinks',
- 'backlinks' => 'ApiQueryBacklinks',
- 'categories' => 'ApiQueryCategories',
- 'categorymembers' => 'ApiQueryCategoryMembers',
- 'duplicatefiles' => 'ApiQueryDuplicateFiles',
- 'embeddedin' => 'ApiQueryBacklinks',
- 'exturlusage' => 'ApiQueryExtLinksUsage',
- 'images' => 'ApiQueryImages',
- 'imageusage' => 'ApiQueryBacklinks',
- 'iwbacklinks' => 'ApiQueryIWBacklinks',
- 'langbacklinks' => 'ApiQueryLangBacklinks',
- 'links' => 'ApiQueryLinks',
- 'protectedtitles' => 'ApiQueryProtectedTitles',
- 'querypage' => 'ApiQueryQueryPage',
- 'random' => 'ApiQueryRandom',
- 'recentchanges' => 'ApiQueryRecentChanges',
- 'search' => 'ApiQuerySearch',
- 'templates' => 'ApiQueryLinks',
- 'watchlist' => 'ApiQueryWatchlist',
- 'watchlistraw' => 'ApiQueryWatchlistRaw',
- );
-
- /**
* @var ApiPageSet
*/
private $mPageSet;
@@ -162,13 +129,6 @@
$this->mModuleMgr->addModules( $wgAPIListModules, 'list' );
$this->mModuleMgr->addModules( self::$QueryMetaModules, 'meta'
);
$this->mModuleMgr->addModules( $wgAPIMetaModules, 'meta' );
-
- global $wgAPIGeneratorModules;
- if ( is_array( $wgAPIGeneratorModules ) ) {
- foreach ( $wgAPIGeneratorModules as $moduleName =>
$moduleClass ) {
- $this->mQueryGenerators[$moduleName] =
$moduleClass;
- }
- }
// Create PageSet that will process
titles/pageids/revids/generator
$this->mPageSet = new ApiPageSet( $this );
@@ -221,10 +181,18 @@
/**
* Get the generators array mapping module names to class names
+ * @deprecated since 1.21, list of generators is maintained by
ApiPageSet
* @return array array(modulename => classname)
*/
public function getGenerators() {
- return $this->mQueryGenerators;
+ wfDeprecated( __METHOD__, '1.21' );
+ $gens = array();
+ foreach ( $this->mModuleMgr->getNamesWithClasses() as $name =>
$class ) {
+ if ( is_subclass_of( $class, 'ApiQueryGeneratorBase' )
) {
+ $gens[$name] = $class;
+ }
+ }
+ return $gens;
}
/**
@@ -502,7 +470,7 @@
'exportnowrap' => false,
'iwurl' => false,
);
- if( $flags ) {
+ if ( $flags ) {
$result += $this->getPageSet()->getFinalParams( $flags
);
}
return $result;
diff --git a/tests/phpunit/includes/api/ApiGeneratorTest.php
b/tests/phpunit/includes/api/ApiGeneratorTest.php
deleted file mode 100644
index 4a23eea..0000000
--- a/tests/phpunit/includes/api/ApiGeneratorTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-/**
- * @group API
- */
-class ApiGeneratorTest extends MediaWikiTestCase {
-
- /**
- * Helper to easily get an ApiQuery object instance
- */
- function getApiQuery() {
- // Initialize an ApiQuery object to play with
- $main = new ApiMain( new FauxRequest() );
- return new ApiQuery( $main, 'foo', 'bar' );
- }
-
- /**
- * Test whether all registered query modules which are subclasses of
- * ApiQueryGeneratorBase are listed as being a generator. Registration
is
- * done:
- * - for core: add it to ApiQuery::$mQueryGenerators
- * - for extension: by adding to $wgAPIGeneratorModules
- *
- * @dataProvider provideApiquerygeneratorbaseChilds
- */
- public function testApiquerygeneatorbaseModulesListedAsGenerators(
- $moduleName, $moduleClass
- ) {
- $generators = $this->getApiQuery()->getGenerators();
- $this->assertArrayHasKey( $moduleName, $generators,
- "API module '$moduleName' of class '$moduleClass' (an
ApiQueryGeneratorBase subclass) must be listed in ApiQuery::\$mQueryGenerators
or added to \$wgAPIGeneratorModules."
- );
- }
-
- /**
- * Returns API modules which are subclassing ApiQueryGeneratorBase.
- * Case format is:
- * (moduleName, moduleClass)
- */
- public function provideApiquerygeneratorbaseChilds() {
- $cases = array();
- $modules =
$this->getApiQuery()->getModuleManager()->getNamesWithClasses();
- foreach ( $modules as $moduleName => $moduleClass ) {
- if ( !is_subclass_of( $moduleClass,
'ApiQueryGeneratorBase' ) ) {
- continue;
- }
- $cases[] = array( $moduleName, $moduleClass );
- }
- return $cases;
- }
-
- /**
- * @dataProvider provideListedApiqueryGenerators
- */
- public function testGeneratorsAreApiquerygeneratorbaseSubclasses(
- $generatorName, $generatorClass
- ) {
- $modules =
$this->getApiQuery()->getModuleManager()->getNamesWithClasses();
- $this->assertArrayHasKey( $generatorName, $modules,
- "Class '$generatorClass' of generator '$generatorName'
must be a subclass of 'ApiQueryGeneratorBase'. Listed either in
ApiQuery::\$mQueryGenerators or in \$wgAPIGeneratorModules."
- );
-
- }
-
- /**
- * Return ApiQuery generators, either listed in ApiQuery or registered
- * via wgAPIGeneratorModules.
- * Case format is:
- * (moduleName, $moduleClass).
- */
- public function provideListedApiqueryGenerators() {
- $cases = array();
- $generators = $this->getApiQuery()->getGenerators();
- foreach ( $generators as $generatorName => $generatorClass ) {
- $cases[] = array( $generatorName, $generatorClass );
- }
- return $cases;
- }
-
-}
--
To view, visit https://gerrit.wikimedia.org/r/46196
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I014260a42226854a2178345dc3cd0f50b41b3c08
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Domas <[email protected]>
Gerrit-Reviewer: Lwelling <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits