From 8a0e46d97c79a534ba3506cf5485cb7074d36d20 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 23 Jan 2008 18:40:40 +0000 Subject: [PATCH] API: * Fixing buggy class instantiation in ApiParamInfo * Adding getModules() method to ApiMain and ApiQuery --- includes/api/ApiMain.php | 7 +++++++ includes/api/ApiParamInfo.php | 23 ++++++++++++++--------- includes/api/ApiQuery.php | 7 +++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index dff4ab9aa7..ce69502ca3 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -570,6 +570,13 @@ class ApiMain extends ApiBase { protected function addFormat( $fmtName, $fmtClass ) { $this->mFormats[$fmtName] = $fmtClass; } + + /** + * Get the array mapping module names to class names + */ + function getModules() { + return $this->mModules; + } } /** diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 2c9ef2ee93..b14fafc642 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -43,30 +43,35 @@ class ApiParamInfo extends ApiBase { $result = $this->getResult(); $r = array(); if(is_array($params['modules'])) + { + $modArr = $this->getMain()->getModules(); foreach($params['modules'] as $m) { - $className = "Api$m"; - if(!class_exists($className)) + if(!isset($modArr[$m])) { - $mods[$m] = array('missing' => ''); + $r['modules'][$m] = array('missing' => ''); continue; } - $obj = new $className($this->getMain(), $m); + $obj = new $modArr[$m]($this->getMain(), $m); $r['modules'][$m] = $this->getClassInfo($obj); } + } if(is_array($params['querymodules'])) + { + $queryObj = new ApiQuery($this->getMain(), 'query'); + $qmodArr = $queryObj->getModules(); foreach($params['querymodules'] as $qm) { - $className = "ApiQuery$qm"; - if(!class_exists($className)) + if(!isset($qmodArr[$qm])) { - $qmods[$qm] = array('missing' => ''); + $r['querymodules'][$qm] = array('missing' => ''); continue; } - $obj = new $className($this, $qm); + $obj = new $qmodArr[$qm]($this, $qm); $r['querymodules'][$qm] = $this->getClassInfo($obj); } - $result->addValue( null, $this->getModuleName(), $r ); + } + $result->addValue(null, $this->getModuleName(), $r); } function getClassInfo($obj) diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index c42e7c98f1..7ff6e67e9a 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -147,6 +147,13 @@ class ApiQuery extends ApiBase { public function getPageSet() { return $this->mPageSet; } + + /** + * Get the array mapping module names to class names + */ + function getModules() { + return array_merge($this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules); + } /** * Query execution happens in the following steps: -- 2.20.1