From b16eb8a42ea629e4ab44ead99992a1dbbdc4b59f Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Wed, 11 Feb 2015 17:38:18 -0800 Subject: [PATCH] New hooks ApiMain::moduleManager and ApiQuery::moduleManager Needed to conditionally register API modules. The previous way, messing with globals from extension functions, is getting problematic because Config class will make this impossible. Change-Id: I86b40aeec555dd6b3cd82cab31d96e85fdf0a665 --- RELEASE-NOTES-1.25 | 4 ++++ docs/hooks.txt | 8 ++++++++ includes/api/ApiMain.php | 2 ++ includes/api/ApiQuery.php | 2 ++ 4 files changed, 16 insertions(+) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 5ce61e1ef0..1621c5f4b0 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -107,6 +107,8 @@ production. to allow extensions to override how links to pages are rendered within NS_CATEGORY * (T19665) Special:WantedPages only lists page which having at least one red link pointing to it. +* New hooks 'ApiMain::moduleManager' and 'ApiQuery::moduleManager', can be + used for conditional registration of API modules. ==== External libraries ==== * MediaWiki now requires certain external libraries to be installed. In the past @@ -278,6 +280,8 @@ production. * ApiQueryDeletedrevs * Default type param for ApiQueryWatchlist and ApiQueryRecentChanges has been changed from all types (e.g. including 'external') to 'edit|new|log'. +* New hooks 'ApiMain::moduleManager' and 'ApiQuery::moduleManager', can be + used for conditional registration of API modules. === Languages updated in 1.25 === diff --git a/docs/hooks.txt b/docs/hooks.txt index e81637a992..1d211af9bc 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -418,6 +418,10 @@ $module: ApiBase Module object &$help: Array of HTML strings to be joined for the output. $options: Array Options passed to ApiHelp::getHelp +'ApiMain::moduleManager': Called when ApiMain has finished initializing its +module manager. Can be used to conditionally register API modules. +$moduleManager: ApiModuleManager Module manager instance + 'ApiOpenSearchSuggest': Called when constructing the OpenSearch results. Hooks can alter or append to the array. &$results: array with integer keys to associative arrays. Keys in associative @@ -431,6 +435,10 @@ array: (url), 'width', 'height', 'alt', 'align'. - url: Url for the given title. +'ApiQuery::moduleManager': Called when ApiQuery has finished initializing its +module manager. Can be used to conditionally register API query modules. +$moduleManager: ApiModuleManager Module manager instance + 'APIQueryAfterExecute': After calling the execute() method of an action=query submodule. Use this to extend core API modules. &$module: Module object diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 34ed523031..fe01f114c4 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -215,6 +215,8 @@ class ApiMain extends ApiBase { $this->mModuleMgr->addModules( self::$Formats, 'format' ); $this->mModuleMgr->addModules( $config->get( 'APIFormatModules' ), 'format' ); + Hooks::run( 'ApiMain::moduleManager', array( $this->mModuleMgr ) ); + $this->mResult = new ApiResult( $this ); $this->mEnableWrite = $enableWrite; diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 514d559430..9196dc7333 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -143,6 +143,8 @@ class ApiQuery extends ApiBase { $this->mModuleMgr->addModules( self::$QueryMetaModules, 'meta' ); $this->mModuleMgr->addModules( $config->get( 'APIMetaModules' ), 'meta' ); + Hooks::run( 'ApiQuery::moduleManager', array( $this->mModuleMgr ) ); + // Create PageSet that will process titles/pageids/revids/generator $this->mPageSet = new ApiPageSet( $this ); } -- 2.20.1