From 8a7397e8ad87d871f30a1936d4231613b464fbe5 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 26 Sep 2006 06:37:26 +0000 Subject: [PATCH] * API: Overall query-related cleanup. --- api.php | 6 +-- includes/api/ApiBase.php | 33 ++++++------- includes/api/ApiFormatBase.php | 2 +- includes/api/ApiFormatJson.php | 2 +- includes/api/ApiFormatXml.php | 2 +- includes/api/ApiHelp.php | 6 ++- includes/api/ApiLogin.php | 37 +++++++------- includes/api/ApiMain.php | 9 ++-- includes/api/ApiPageSet.php | 39 +++++++-------- includes/api/ApiQuery.php | 55 ++++++++++++--------- includes/api/ApiQueryAllpages.php | 66 ++++++++++++++----------- includes/api/ApiQueryBase.php | 44 +++++++++-------- includes/api/ApiQueryContent.php | 78 ------------------------------ includes/api/ApiQueryInfo.php | 8 +-- includes/api/ApiQueryRevisions.php | 4 +- includes/api/ApiQuerySiteinfo.php | 4 +- 16 files changed, 172 insertions(+), 223 deletions(-) delete mode 100644 includes/api/ApiQueryContent.php diff --git a/api.php b/api.php index 28b56c8fbc..d862d6c1ae 100644 --- a/api.php +++ b/api.php @@ -62,7 +62,7 @@ $wgApiAutoloadClasses = array ( 'ApiQuerySiteinfo' => 'ApiQuerySiteinfo.php', 'ApiQueryInfo' => 'ApiQueryInfo.php', 'ApiQueryRevisions' => 'ApiQueryRevisions.php', - 'ApiQueryAllpages' => 'ApiQueryAllpages.php' + 'ApiQueryAllpages' => 'ApiQueryAllpages.php' ); /** @@ -115,9 +115,9 @@ function ApiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) { // Prefix each api class with the proper prefix, // and append them to $wgAutoloadClasses global $wgAutoloadClasses; - + if (!isset ($wgAutoloadClasses)) - $wgAutoloadClasses = array(); + $wgAutoloadClasses = array (); foreach ($apiAutoloadClasses as $className => $classFile) $wgAutoloadClasses[$className] = $apiDirectory . $classFile; diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 8d8a5831e6..649ae5112c 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -195,7 +195,7 @@ abstract class ApiBase { // More validation only when choices were not given // choices were validated in ParseMultiValue() - if (!is_array ($type) && isset ($value)) { + if (!is_array($type) && isset ($value)) { switch ($type) { case 'NULL' : // nothing to do @@ -205,14 +205,14 @@ abstract class ApiBase { case 'integer' : // Force everything using intval() $value = is_array($value) ? array_map('intval', $value) : intval($value); break; - case 'limit': - if (!isset ($enumParams[GN_ENUM_MAX1]) || !isset($enumParams[GN_ENUM_MAX2])) + case 'limit' : + if (!isset ($enumParams[GN_ENUM_MAX1]) || !isset ($enumParams[GN_ENUM_MAX2])) $this->DieDebug("MAX1 or MAX2 are not defined for the limit $param"); if ($multi) $this->DieDebug("Multi-values not supported for $param"); - $min = isset($enumParams[GN_ENUM_MIN]) ? $enumParams[GN_ENUM_MIN] : 0; + $min = isset ($enumParams[GN_ENUM_MIN]) ? $enumParams[GN_ENUM_MIN] : 0; $value = intval($value); - $this->ValidateLimit($param, $value, $min, $enumParams[GN_ENUM_MAX1], $enumParams[GN_ENUM_MAX2]); + $this->ValidateLimit($param, $value, $min, $enumParams[GN_ENUM_MAX1], $enumParams[GN_ENUM_MAX2]); break; case 'boolean' : if ($multi) @@ -226,7 +226,7 @@ abstract class ApiBase { break; default : $this->DieDebug("Param $param's type is unknown - $type"); - + } } @@ -276,21 +276,20 @@ abstract class ApiBase { /** * Validate the value against the minimum and user/bot maximum limits. Prints usage info on failure. */ - function ValidateLimit( $varname, $value, $min, $max, $botMax ) - { + function ValidateLimit($varname, $value, $min, $max, $botMax) { global $wgUser; - - if ( $value < $min ) { - $this->dieUsage( "$varname may not be less than $min (set to $value)", $varname ); + + if ($value < $min) { + $this->dieUsage("$varname may not be less than $min (set to $value)", $varname); } - - if( $this->GetMain()->IsBot() ) { - if ( $value > $botMax ) { - $this->dieUsage( "$varname may not be over $botMax (set to $value) for bots", $varname ); + + if ($this->GetMain()->IsBot()) { + if ($value > $botMax) { + $this->dieUsage("$varname may not be over $botMax (set to $value) for bots", $varname); } } else { - if( $value > $max ) { - $this->dieUsage( "$varname may not be over $max (set to $value) for users", $varname ); + if ($value > $max) { + $this->dieUsage("$varname may not be over $max (set to $value) for users", $varname); } } } diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 7bfad21550..716201f853 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -142,7 +142,7 @@ abstract class ApiFormatBase extends ApiBase { $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '\\0', $text); // make strings inside * bold $text = ereg_replace("\\*[^<>\n]+\\*", '\\0', $text); - + return $text; } diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index ec23968509..3563de3445 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -42,7 +42,7 @@ class ApiFormatJson extends ApiFormatBase { public function Execute() { require_once ('ApiFormatJson_json.php'); $json = new Services_JSON(); - $this->PrintText( $json->encode( $this->GetResult()->GetData(), true )); + $this->PrintText($json->encode($this->GetResult()->GetData(), true)); } protected function GetDescription() { diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 301130b6c8..b27763b6ad 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -38,7 +38,7 @@ class ApiFormatXml extends ApiFormatBase { public function GetMimeType() { return 'text/xml'; } - + public function GetNeedsRawData() { return true; } diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php index 2eff7f08ca..907fc2fe9d 100644 --- a/includes/api/ApiHelp.php +++ b/includes/api/ApiHelp.php @@ -41,9 +41,11 @@ class ApiHelp extends ApiBase { public function Execute() { $this->DieUsage('', 'help'); } - + protected function GetDescription() { - return array('Display this help screen.'); + return array ( + 'Display this help screen.' + ); } } ?> \ No newline at end of file diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 349751e274..ca5a5c72de 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -45,41 +45,40 @@ class ApiLogin extends ApiBase { 'wpDomain' => $lgdomain, 'wpRemember' => '' )); - - $result = array(); - + + $result = array (); + $loginForm = new LoginForm($params); - switch ($loginForm->authenticateUserData()) - { - case (AuthSuccess): + switch ($loginForm->authenticateUserData()) { + case (AuthSuccess) : $result['result'] = 'Success'; $result['lguserid'] = $_SESSION['wsUserID']; $result['lgusername'] = $_SESSION['wsUserName']; $result['lgtoken'] = $_SESSION['wsToken']; break; - case (AuthNoName): + case (AuthNoName) : $result['result'] = 'AuthNoName'; break; - case (AuthIllegal): + case (AuthIllegal) : $result['result'] = 'AuthIllegal'; break; - case (AuthWrongPluginPass): + case (AuthWrongPluginPass) : $result['result'] = 'AuthWrongPluginPass'; break; - case (AuthNotExists): + case (AuthNotExists) : $result['result'] = 'AuthNotExists'; break; - case (AuthWrongPass): + case (AuthWrongPass) : $result['result'] = 'AuthWrongPass'; break; - case (AuthEmptyPass): + case (AuthEmptyPass) : $result['result'] = 'AuthEmptyPass'; break; - default: - $this->DieDebug( "Unhandled case value" ); + default : + $this->DieDebug("Unhandled case value"); } - + $this->GetResult()->AddMessage('login', null, $result); } @@ -87,7 +86,7 @@ class ApiLogin extends ApiBase { return array ( 'lgname' => '', 'lgpassword' => '', - 'lgdomain' => null + 'lgdomain' => null ); } @@ -95,12 +94,14 @@ class ApiLogin extends ApiBase { return array ( 'lgname' => 'User Name', 'lgpassword' => 'Password', - 'lgdomain' => 'Domain (optional)' + 'lgdomain' => 'Domain (optional)' ); } protected function GetDescription() { - return array('This module is used to login and get the authentication tokens.'); + return array ( + 'This module is used to login and get the authentication tokens.' + ); } } ?> \ No newline at end of file diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 8b7a1ca2a4..e31c879e1b 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -33,7 +33,8 @@ if (!defined('MEDIAWIKI')) { * @desc This exception will be thrown when DieUsage is called to stop module execution. */ class UsageException extends Exception { - var $codestr; + + private $codestr; public function __construct($message, $codestr) { parent :: __construct($message); @@ -172,12 +173,12 @@ class ApiMain extends ApiBase { return $msg; } - + private $mIsBot = null; public function IsBot() { - if (!isset($this->mIsBot)) { + if (!isset ($this->mIsBot)) { global $wgUser; - $this->mIsBot = $wgUser->isAllowed( 'bot' ); + $this->mIsBot = $wgUser->isAllowed('bot'); } return $this->mIsBot; } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index d19048c2c5..4d779789ee 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -26,25 +26,24 @@ if (!defined('MEDIAWIKI')) { // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); + require_once ("ApiQueryBase.php"); } -class ApiPageSet extends ApiBase { +class ApiPageSet extends ApiQueryBase { private $allPages; // [ns][dbkey] => page_id or 0 when missing - private $db, $resolveRedirs; + private $resolveRedirs; private $goodTitles, $missingTitles, $redirectTitles, $normalizedTitles; - public function __construct($main, $db, $resolveRedirs) { - parent :: __construct($main); - $this->db = $db; + public function __construct($query, $resolveRedirs) { + parent :: __construct($query, __CLASS__); $this->resolveRedirs = $resolveRedirs; $this->allPages = array (); $this->goodTitles = array (); $this->missingTitles = array (); $this->redirectTitles = array (); - $this->normalizedTitles = array(); + $this->normalizedTitles = array (); } /** @@ -79,7 +78,7 @@ class ApiPageSet extends ApiBase { public function GetNormalizedTitles() { return $this->normalizedTitles; } - + /** * Given an array of title strings, convert them into Title objects. * This method validates access rights for the title, @@ -141,11 +140,13 @@ class ApiPageSet extends ApiBase { // Get validated and normalized title objects $linkBatch = $this->ProcessTitlesStrings($titles); - + + $db = $this->GetDB(); + // // Repeat until all redirects have been resolved // - while (false !== ($set = $linkBatch->constructSet('page', $this->db))) { + while (false !== ($set = $linkBatch->constructSet('page', $db))) { // Hack: Get the ns:titles stored in array(ns => array(titles)) format $remaining = $linkBatch->data; @@ -155,8 +156,8 @@ class ApiPageSet extends ApiBase { // // Get data about $linkBatch from `page` table // - $res = $this->db->select('page', $pageFlds, $set, __CLASS__ . '::' . __FUNCTION__); - while ($row = $this->db->fetchObject($res)) { + $res = $db->select('page', $pageFlds, $set, __CLASS__ . '::' . __FUNCTION__); + while ($row = $db->fetchObject($res)) { unset ($remaining[$row->page_namespace][$row->page_title]); $title = Title :: makeTitle($row->page_namespace, $row->page_title); @@ -168,7 +169,7 @@ class ApiPageSet extends ApiBase { $this->goodTitles[$row->page_id] = $title; } } - $this->db->freeResult($res); + $db->freeResult($res); // // The remaining titles in $remaining are non-existant pages @@ -186,12 +187,12 @@ class ApiPageSet extends ApiBase { // // Resolve redirects by querying the pagelinks table, and repeat the process // - + // Create a new linkBatch object for the next pass $linkBatch = new LinkBatch(); // find redirect targets for all redirect pages - $res = $this->db->select('pagelinks', array ( + $res = $db->select('pagelinks', array ( 'pl_from', 'pl_namespace', 'pl_title' @@ -199,19 +200,19 @@ class ApiPageSet extends ApiBase { 'pl_from' => array_keys($redirectIds )), __CLASS__ . '::' . __FUNCTION__); - while ($row = $this->db->fetchObject($res)) { + while ($row = $db->fetchObject($res)) { // Bug 7304 workaround // ( http://bugzilla.wikipedia.org/show_bug.cgi?id=7304 ) // A redirect page may have more than one link. // This code will only use the first link returned. - if (isset ($redirectIds[$row->pl_from])) { // remove line when 7304 is fixed + if (isset ($redirectIds[$row->pl_from])) { // remove line when 7304 is fixed $titleStrFrom = $redirectIds[$row->pl_from]->getPrefixedText(); $titleStrTo = Title :: makeTitle($row->pl_namespace, $row->pl_title)->getPrefixedText(); $this->redirectTitles[$titleStrFrom] = $titleStrTo; - unset ($redirectIds[$row->pl_from]); // remove line when 7304 is fixed + unset ($redirectIds[$row->pl_from]); // remove line when 7304 is fixed // Avoid an infinite loop by checking if we have already processed this target if (!isset ($this->allPages[$row->pl_namespace][$row->pl_title])) { @@ -219,7 +220,7 @@ class ApiPageSet extends ApiBase { } } } - $this->db->freeResult($res); + $db->freeResult($res); } } diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index c6e3b1653e..f1220898f3 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -31,7 +31,8 @@ if (!defined('MEDIAWIKI')) { class ApiQuery extends ApiBase { - var $mMetaModuleNames, $mPropModuleNames, $mListModuleNames; + private $mMetaModuleNames, $mPropModuleNames, $mListModuleNames; + private $mData; private $mQueryMetaModules = array ( 'siteinfo' => 'ApiQuerySiteinfo' @@ -80,6 +81,10 @@ class ApiQuery extends ApiBase { return $this->mSlaveDB; } + public function GetData() { + return $this->mData; + } + /** * Query execution happens in the following steps: * #1 Create a PageSet object with any pages requested by the user @@ -113,17 +118,17 @@ class ApiQuery extends ApiBase { $dataSource = 'revids'; } - $data = new ApiPageSet($this->GetMain(), $this->GetDB(), $redirects); + $this->mData = new ApiPageSet($this, $redirects); switch ($dataSource) { case 'titles' : - $data->PopulateTitles($titles); + $this->mData->PopulateTitles($titles); break; case 'pageids' : - $data->PopulatePageIDs($pageids); + $this->mData->PopulatePageIDs($pageids); break; case 'titles' : - $data->PopulateRevIDs($revids); + $this->mData->PopulateRevIDs($revids); break; default : // Do nothing - some queries do not need any of the data sources. @@ -134,24 +139,24 @@ class ApiQuery extends ApiBase { // If generator is provided, get a new dataset to work on // if (isset ($generator)) - $data = $this->ExecuteGenerator($generator, $data, $redirects); + $this->ExecuteGenerator($generator, $redirects); // Instantiate required modules - // During instantiation, modules may optimize data requests through the $data object - // $data will be lazy loaded when modules begin to request data during execution + // During instantiation, modules may optimize data requests through the $this->mData object + // $this->mData will be lazy loaded when modules begin to request data during execution $modules = array (); if (isset ($meta)) foreach ($meta as $moduleName) - $modules[] = new $this->mQueryMetaModules[$moduleName] ($this->GetMain(), $this, $moduleName, $data); + $modules[] = new $this->mQueryMetaModules[$moduleName] ($this, $moduleName); if (isset ($prop)) foreach ($prop as $moduleName) - $modules[] = new $this->mQueryPropModules[$moduleName] ($this->GetMain(), $this, $moduleName, $data); + $modules[] = new $this->mQueryPropModules[$moduleName] ($this, $moduleName); if (isset ($list)) foreach ($list as $moduleName) - $modules[] = new $this->mQueryListModules[$moduleName] ($this->GetMain(), $this, $moduleName, $data); + $modules[] = new $this->mQueryListModules[$moduleName] ($this, $moduleName); // Title normalizations - foreach ($data->GetNormalizedTitles() as $rawTitleStr => $titleStr) { + foreach ($this->mData->GetNormalizedTitles() as $rawTitleStr => $titleStr) { $this->GetResult()->AddMessage('query', 'normalized', array ( 'from' => $rawTitleStr, 'to' => $titleStr @@ -160,7 +165,7 @@ class ApiQuery extends ApiBase { // Show redirect information if ($redirects) { - foreach ($data->GetRedirectTitles() as $titleStrFrom => $titleStrTo) { + foreach ($this->mData->GetRedirectTitles() as $titleStrFrom => $titleStrTo) { $this->GetResult()->AddMessage('query', 'redirects', array ( 'from' => $titleStrFrom, 'to' => $titleStrTo @@ -173,18 +178,20 @@ class ApiQuery extends ApiBase { $module->Execute(); } - protected function ExecuteGenerator($generator, $data, $redirects) { - + protected function ExecuteGenerator($generator, $redirects) { + // Find class that implements requested generator if (isset ($this->mQueryListModules[$generator])) $className = $this->mQueryListModules[$generator]; - else if (isset ($this->mQueryPropModules[$generator])) - $className = $this->mQueryPropModules[$generator]; else - $this->DieDebug("Unknown generator=$generator"); - - - $module = new $className($this->GetMain(), $this, $generator, $data, true); + if (isset ($this->mQueryPropModules[$generator])) + $className = $this->mQueryPropModules[$generator]; + else + $this->DieDebug("Unknown generator=$generator"); + + $module = new $className ($this, $generator, true); + + // change $this->mData // TODO: implement $this->DieUsage("Generator execution has not been implemented", 'notimplemented'); @@ -230,6 +237,10 @@ class ApiQuery extends ApiBase { // Use parent to make default message for the query module $msg = parent :: MakeHelpMsg(); + // Make sure the internal object is empty + // (just in case a sub-module decides to optimize during instantiation) + $this->mData = null; + $astriks = str_repeat('--- ', 8); $msg .= "\n$astriks Query: Meta $astriks\n\n"; $msg .= $this->MakeHelpMsgHelper($this->mQueryMetaModules, 'meta'); @@ -246,7 +257,7 @@ class ApiQuery extends ApiBase { foreach ($moduleList as $moduleName => $moduleClass) { $msg .= "* $paramName=$moduleName *"; - $module = new $moduleClass ($this->GetMain(), $this, $moduleName, null); + $module = new $moduleClass ($this, $moduleName); $msg2 = $module->MakeHelpMsg(); if ($msg2 !== false) $msg .= $msg2; diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index b0530b9b4b..a69ad438bb 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -31,49 +31,57 @@ if (!defined('MEDIAWIKI')) { class ApiQueryAllpages extends ApiQueryBase { - public function __construct($main, $query, $moduleName, $data, $generator = false) { - parent :: __construct($main, $query, $moduleName, $data, $generator); + public function __construct($query, $moduleName, $generator = false) { + parent :: __construct($query, $moduleName, $generator); } public function Execute() { $aplimit = $apfrom = $apnamespace = $apfilterredir = null; extract($this->ExtractRequestParams()); - $db = $this->GetQuery()->GetDB(); - $where = array( 'page_namespace' => $apnamespace ); - if( isset($apfrom)) - $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase::TitleToKey($apfrom)); + $db = $this->GetDB(); + $where = array ( + 'page_namespace' => $apnamespace + ); + if (isset ($apfrom)) + $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: TitleToKey($apfrom)); if ($apfilterredir === 'redirects') - $where['page_is_redirect'] = 1; - else if ($apfilterredir === 'nonredirects') - $where['page_is_redirect'] = 0; - - $res = $db->select( - 'page', - array( 'page_id', 'page_namespace', 'page_title' ), - $where, - __CLASS__ . '::' . __METHOD__, - array( 'USE INDEX' => 'name_title', 'LIMIT' => $aplimit+1, 'ORDER BY' => 'page_namespace, page_title' )); - - $data = array(); + $where['page_is_redirect'] = 1; + else + if ($apfilterredir === 'nonredirects') + $where['page_is_redirect'] = 0; + + $res = $db->select('page', array ( + 'page_id', + 'page_namespace', + 'page_title' + ), $where, __CLASS__ . '::' . __METHOD__, array ( + 'USE INDEX' => 'name_title', + 'LIMIT' => $aplimit +1, + 'ORDER BY' => 'page_namespace, page_title' + )); + + $data = array (); $data['_element'] = 'p'; $count = 0; - while ( $row = $db->fetchObject( $res ) ) { - if( ++$count > $aplimit ) { + while ($row = $db->fetchObject($res)) { + if (++ $count > $aplimit) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... - $msg = array('continue' => 'apfrom=' . ApiQueryBase::KeyToTitle($row->page_title)); + $msg = array ( + 'continue' => 'apfrom=' . ApiQueryBase :: KeyToTitle($row->page_title + )); $this->GetResult()->AddMessage('query-status', 'allpages', $msg); break; } - $title = Title::makeTitle( $row->page_namespace, $row->page_title ); + $title = Title :: makeTitle($row->page_namespace, $row->page_title); // skip any pages that user has no rights to read - if ( $title->userCanRead() ) { - + if ($title->userCanRead()) { + $id = intval($row->page_id); - $pagedata = array(); - $pagedata['id'] = $id; + $pagedata = array (); + $pagedata['id'] = $id; if ($title->getNamespace() !== 0) $pagedata['ns'] = $title->getNamespace(); $pagedata['title'] = $title->getPrefixedText(); @@ -82,19 +90,19 @@ class ApiQueryAllpages extends ApiQueryBase { $data[$id] = $pagedata; } } - $db->freeResult( $res ); + $db->freeResult($res); $this->GetResult()->AddMessage('query', 'allpages', $data); } protected function GetAllowedParams() { global $wgContLang; - $validNamespaces = array(); + $validNamespaces = array (); foreach (array_keys($wgContLang->getNamespaces()) as $ns) { if ($ns >= 0) $validNamespaces[] = $ns; // strval($ns); } - + return array ( 'apfrom' => null, 'apnamespace' => array ( diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 176604ff8f..f64acfb6bd 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -31,37 +31,43 @@ if (!defined('MEDIAWIKI')) { abstract class ApiQueryBase extends ApiBase { - private $mQueryModule, $mModuleName, $mData, $mGenerator; - - public function __construct($main, $query, $moduleName, $data, $generator=false) { - parent :: __construct($main); + private $mQueryModule, $mModuleName, $mGenerator; + + public function __construct($query, $moduleName, $generator = false) { + parent :: __construct($query->GetMain()); $this->mQueryModule = $query; $this->mModuleName = $moduleName; - $this->mData = $data; $this->mGenerator = $generator; } - + /** * Get the main Query module */ public function GetQuery() { return $this->mQueryModule; } - + /** * Get the name of the query being executed by this instance - */ + */ public function GetModuleName() { return $this->mModuleName; - } - + } + + /** + * Get the Query database connection (readonly) + */ + protected function GetDB() { + return $this->GetQuery()->GetDB(); + } + /** * Get the PageSet object to work on */ protected function GetData() { - return $this->mData; + return $this->mQueryModule->GetData(); } - + /** * Return true if this instance is being used as a generator. */ @@ -75,14 +81,12 @@ abstract class ApiQueryBase extends ApiBase { public function GetCanGenerate() { return false; } - - public static function TitleToKey($title) - { - return str_replace(' ', '_', $title); + + public static function TitleToKey($title) { + return str_replace(' ', '_', $title); } - public static function KeyToTitle($key) - { - return str_replace('_', ' ', $key); + public static function KeyToTitle($key) { + return str_replace('_', ' ', $key); } } -?> \ No newline at end of file +?> diff --git a/includes/api/ApiQueryContent.php b/includes/api/ApiQueryContent.php deleted file mode 100644 index 8a2fee6611..0000000000 --- a/includes/api/ApiQueryContent.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiQueryBase.php"); -} - -class ApiQueryContent extends ApiQueryBase { - - /** - * Constructor - */ - public function __construct($main, $query, $data) { - parent :: __construct($main, $query); - } - - public function Execute() { - - } - - /** - * Returns an array of allowed parameters (keys) => default value for that parameter - */ - protected function GetAllowedParams() { - return array ( - 'param' => 'default', - 'enumparam' => array ( - GN_ENUM_DFLT => 'default', - GN_ENUM_ISMULTI => false, - GN_ENUM_CHOICES => array ( - 'a', - 'b' - ) - ) - ); - } - - /** - * Returns the description string for this module - */ - protected function GetDescription() { - return 'module a'; - } - - /** - * Returns usage examples for this module. Return null if no examples are available. - */ - protected function GetExamples() { - return array ( - 'http://...' - ); - } -} -?> \ No newline at end of file diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 7caed4f2ea..2cddeb8386 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -31,12 +31,12 @@ if (!defined('MEDIAWIKI')) { class ApiQueryInfo extends ApiQueryBase { - public function __construct($main, $moduleName, $query, $data) { - parent :: __construct($main, $moduleName, $query, $data); + public function __construct($main, $moduleName, $query) { + parent :: __construct($main, $moduleName, $query); } public function Execute() { - + } protected function GetAllowedParams() { @@ -54,7 +54,7 @@ class ApiQueryInfo extends ApiQueryBase { } protected function GetParamDescription() { - return array(); + return array (); } protected function GetDescription() { diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 499af5cb7c..5e25c22a7b 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -31,8 +31,8 @@ if (!defined('MEDIAWIKI')) { class ApiQueryRevisions extends ApiQueryBase { - public function __construct($main, $query, $moduleName, $data, $generator=false) { - parent :: __construct($main, $query, $moduleName, $data, $generator); + public function __construct($query, $moduleName, $generator = false) { + parent :: __construct($query, $moduleName, $generator); } public function Execute() { diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 50e9c271f7..2d52e5a509 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -31,8 +31,8 @@ if (!defined('MEDIAWIKI')) { class ApiQuerySiteinfo extends ApiQueryBase { - public function __construct($main, $query, $moduleName, $data) { - parent :: __construct($main, $query, $moduleName, $data); + public function __construct($query, $moduleName) { + parent :: __construct($query, $moduleName); } public function Execute() { -- 2.20.1