* API: Overall query-related cleanup.
authorYuri Astrakhan <yurik@users.mediawiki.org>
Tue, 26 Sep 2006 06:37:26 +0000 (06:37 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Tue, 26 Sep 2006 06:37:26 +0000 (06:37 +0000)
16 files changed:
api.php
includes/api/ApiBase.php
includes/api/ApiFormatBase.php
includes/api/ApiFormatJson.php
includes/api/ApiFormatXml.php
includes/api/ApiHelp.php
includes/api/ApiLogin.php
includes/api/ApiMain.php
includes/api/ApiPageSet.php
includes/api/ApiQuery.php
includes/api/ApiQueryAllpages.php
includes/api/ApiQueryBase.php
includes/api/ApiQueryContent.php [deleted file]
includes/api/ApiQueryInfo.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQuerySiteinfo.php

diff --git a/api.php b/api.php
index 28b56c8..d862d6c 100644 (file)
--- a/api.php
+++ b/api.php
@@ -62,7 +62,7 @@ $wgApiAutoloadClasses = array (
        'ApiQuerySiteinfo' => 'ApiQuerySiteinfo.php',\r
        'ApiQueryInfo' => 'ApiQueryInfo.php',\r
        'ApiQueryRevisions' => 'ApiQueryRevisions.php',\r
-       'ApiQueryAllpages' => 'ApiQueryAllpages.php'    \r
+       'ApiQueryAllpages' => 'ApiQueryAllpages.php'\r
 );\r
 \r
 /**\r
@@ -115,9 +115,9 @@ function ApiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {
        // Prefix each api class with the proper prefix,\r
        // and append them to $wgAutoloadClasses\r
        global $wgAutoloadClasses;\r
-       \r
+\r
        if (!isset ($wgAutoloadClasses))\r
-               $wgAutoloadClasses = array();\r
+               $wgAutoloadClasses = array ();\r
 \r
        foreach ($apiAutoloadClasses as $className => $classFile)\r
                $wgAutoloadClasses[$className] = $apiDirectory . $classFile;\r
index 8d8a583..649ae51 100644 (file)
@@ -195,7 +195,7 @@ abstract class ApiBase {
 \r
                        // More validation only when choices were not given\r
                        // choices were validated in ParseMultiValue()\r
-                       if (!is_array ($type) && isset ($value)) {\r
+                       if (!is_array($type) && isset ($value)) {\r
 \r
                                switch ($type) {\r
                                        case 'NULL' : // nothing to do\r
@@ -205,14 +205,14 @@ abstract class ApiBase {
                                        case 'integer' : // Force everything using intval()\r
                                                $value = is_array($value) ? array_map('intval', $value) : intval($value);\r
                                                break;\r
-                                       case 'limit':\r
-                                               if (!isset ($enumParams[GN_ENUM_MAX1]) || !isset($enumParams[GN_ENUM_MAX2]))\r
+                                       case 'limit' :\r
+                                               if (!isset ($enumParams[GN_ENUM_MAX1]) || !isset ($enumParams[GN_ENUM_MAX2]))\r
                                                        $this->DieDebug("MAX1 or MAX2 are not defined for the limit $param");\r
                                                if ($multi)\r
                                                        $this->DieDebug("Multi-values not supported for $param");\r
-                                               $min = isset($enumParams[GN_ENUM_MIN]) ? $enumParams[GN_ENUM_MIN] : 0;\r
+                                               $min = isset ($enumParams[GN_ENUM_MIN]) ? $enumParams[GN_ENUM_MIN] : 0;\r
                                                $value = intval($value);\r
-                                               $this->ValidateLimit($param, $value, $min, $enumParams[GN_ENUM_MAX1], $enumParams[GN_ENUM_MAX2]);                                                       \r
+                                               $this->ValidateLimit($param, $value, $min, $enumParams[GN_ENUM_MAX1], $enumParams[GN_ENUM_MAX2]);\r
                                                break;\r
                                        case 'boolean' :\r
                                                if ($multi)\r
@@ -226,7 +226,7 @@ abstract class ApiBase {
                                                break;\r
                                        default :\r
                                                $this->DieDebug("Param $param's type is unknown - $type");\r
-                               \r
+\r
                                }\r
                        }\r
 \r
@@ -276,21 +276,20 @@ abstract class ApiBase {
        /**\r
        * Validate the value against the minimum and user/bot maximum limits. Prints usage info on failure.\r
        */\r
-       function ValidateLimit( $varname, $value, $min, $max, $botMax )\r
-       {\r
+       function ValidateLimit($varname, $value, $min, $max, $botMax) {\r
                global $wgUser;\r
-               \r
-               if ( $value < $min ) {\r
-                       $this->dieUsage( "$varname may not be less than $min (set to $value)", $varname );\r
+\r
+               if ($value < $min) {\r
+                       $this->dieUsage("$varname may not be less than $min (set to $value)", $varname);\r
                }\r
-               \r
-               if( $this->GetMain()->IsBot() ) {\r
-                       if ( $value > $botMax ) {\r
-                               $this->dieUsage( "$varname may not be over $botMax (set to $value) for bots", $varname );\r
+\r
+               if ($this->GetMain()->IsBot()) {\r
+                       if ($value > $botMax) {\r
+                               $this->dieUsage("$varname may not be over $botMax (set to $value) for bots", $varname);\r
                        }\r
                } else {\r
-                       if( $value > $max ) {\r
-                               $this->dieUsage( "$varname may not be over $max (set to $value) for users", $varname );\r
+                       if ($value > $max) {\r
+                               $this->dieUsage("$varname may not be over $max (set to $value) for users", $varname);\r
                        }\r
                }\r
        }\r
index 7bfad21..716201f 100644 (file)
@@ -142,7 +142,7 @@ abstract class ApiFormatBase extends ApiBase {
                $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
                // make strings inside * bold
                $text = ereg_replace("\\*[^<>\n]+\\*", '<b>\\0</b>', $text);
-               
+
                return $text;
        }
 
index ec23968..3563de3 100644 (file)
@@ -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() {
index 301130b..b27763b 100644 (file)
@@ -38,7 +38,7 @@ class ApiFormatXml extends ApiFormatBase {
        public function GetMimeType() {
                return 'text/xml';
        }
-       
+
        public function GetNeedsRawData() {
                return true;
        }
index 2eff7f0..907fc2f 100644 (file)
@@ -41,9 +41,11 @@ class ApiHelp extends ApiBase {
        public function Execute() {\r
                $this->DieUsage('', 'help');\r
        }\r
-       \r
+\r
        protected function GetDescription() {\r
-               return array('Display this help screen.');\r
+               return array (\r
+                       'Display this help screen.'\r
+               );\r
        }\r
 }\r
 ?>
\ No newline at end of file
index 349751e..ca5a5c7 100644 (file)
@@ -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
index 8b7a1ca..e31c879 100644 (file)
@@ -33,7 +33,8 @@ if (!defined('MEDIAWIKI')) {
 * @desc This exception will be thrown when DieUsage is called to stop module execution.\r
 */\r
 class UsageException extends Exception {\r
-       var $codestr;\r
+\r
+       private $codestr;\r
 \r
        public function __construct($message, $codestr) {\r
                parent :: __construct($message);\r
@@ -172,12 +173,12 @@ class ApiMain extends ApiBase {
 \r
                return $msg;\r
        }\r
-       \r
+\r
        private $mIsBot = null;\r
        public function IsBot() {\r
-               if (!isset($this->mIsBot)) {\r
+               if (!isset ($this->mIsBot)) {\r
                        global $wgUser;\r
-                       $this->mIsBot = $wgUser->isAllowed( 'bot' );\r
+                       $this->mIsBot = $wgUser->isAllowed('bot');\r
                }\r
                return $this->mIsBot;\r
        }\r
index d19048c..4d77978 100644 (file)
 
 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);
                }
        }
 
index c6e3b16..f122089 100644 (file)
@@ -31,7 +31,8 @@ if (!defined('MEDIAWIKI')) {
 \r
 class ApiQuery extends ApiBase {\r
 \r
-       var $mMetaModuleNames, $mPropModuleNames, $mListModuleNames;\r
+       private $mMetaModuleNames, $mPropModuleNames, $mListModuleNames;\r
+       private $mData;\r
 \r
        private $mQueryMetaModules = array (\r
                'siteinfo' => 'ApiQuerySiteinfo'\r
@@ -80,6 +81,10 @@ class ApiQuery extends ApiBase {
                return $this->mSlaveDB;\r
        }\r
 \r
+       public function GetData() {\r
+               return $this->mData;\r
+       }\r
+\r
        /**\r
         * Query execution happens in the following steps:\r
         * #1 Create a PageSet object with any pages requested by the user\r
@@ -113,17 +118,17 @@ class ApiQuery extends ApiBase {
                        $dataSource = 'revids';\r
                }\r
 \r
-               $data = new ApiPageSet($this->GetMain(), $this->GetDB(), $redirects);\r
+               $this->mData = new ApiPageSet($this, $redirects);\r
 \r
                switch ($dataSource) {\r
                        case 'titles' :\r
-                               $data->PopulateTitles($titles);\r
+                               $this->mData->PopulateTitles($titles);\r
                                break;\r
                        case 'pageids' :\r
-                               $data->PopulatePageIDs($pageids);\r
+                               $this->mData->PopulatePageIDs($pageids);\r
                                break;\r
                        case 'titles' :\r
-                               $data->PopulateRevIDs($revids);\r
+                               $this->mData->PopulateRevIDs($revids);\r
                                break;\r
                        default :\r
                                // Do nothing - some queries do not need any of the data sources.\r
@@ -134,24 +139,24 @@ class ApiQuery extends ApiBase {
                // If generator is provided, get a new dataset to work on\r
                //\r
                if (isset ($generator))\r
-                       $data = $this->ExecuteGenerator($generator, $data, $redirects);\r
+                       $this->ExecuteGenerator($generator, $redirects);\r
 \r
                // Instantiate required modules\r
-               // During instantiation, modules may optimize data requests through the $data object \r
-               // $data will be lazy loaded when modules begin to request data during execution\r
+               // During instantiation, modules may optimize data requests through the $this->mData object \r
+               // $this->mData will be lazy loaded when modules begin to request data during execution\r
                $modules = array ();\r
                if (isset ($meta))\r
                        foreach ($meta as $moduleName)\r
-                               $modules[] = new $this->mQueryMetaModules[$moduleName] ($this->GetMain(), $this, $moduleName, $data);\r
+                               $modules[] = new $this->mQueryMetaModules[$moduleName] ($this, $moduleName);\r
                if (isset ($prop))\r
                        foreach ($prop as $moduleName)\r
-                               $modules[] = new $this->mQueryPropModules[$moduleName] ($this->GetMain(), $this, $moduleName, $data);\r
+                               $modules[] = new $this->mQueryPropModules[$moduleName] ($this, $moduleName);\r
                if (isset ($list))\r
                        foreach ($list as $moduleName)\r
-                               $modules[] = new $this->mQueryListModules[$moduleName] ($this->GetMain(), $this, $moduleName, $data);\r
+                               $modules[] = new $this->mQueryListModules[$moduleName] ($this, $moduleName);\r
 \r
                // Title normalizations\r
-               foreach ($data->GetNormalizedTitles() as $rawTitleStr => $titleStr) {\r
+               foreach ($this->mData->GetNormalizedTitles() as $rawTitleStr => $titleStr) {\r
                        $this->GetResult()->AddMessage('query', 'normalized', array (\r
                                'from' => $rawTitleStr,\r
                                'to' => $titleStr\r
@@ -160,7 +165,7 @@ class ApiQuery extends ApiBase {
 \r
                // Show redirect information\r
                if ($redirects) {\r
-                       foreach ($data->GetRedirectTitles() as $titleStrFrom => $titleStrTo) {\r
+                       foreach ($this->mData->GetRedirectTitles() as $titleStrFrom => $titleStrTo) {\r
                                $this->GetResult()->AddMessage('query', 'redirects', array (\r
                                        'from' => $titleStrFrom,\r
                                        'to' => $titleStrTo\r
@@ -173,18 +178,20 @@ class ApiQuery extends ApiBase {
                        $module->Execute();\r
        }\r
 \r
-       protected function ExecuteGenerator($generator, $data, $redirects) {\r
-               \r
+       protected function ExecuteGenerator($generator, $redirects) {\r
+\r
                // Find class that implements requested generator\r
                if (isset ($this->mQueryListModules[$generator]))\r
                        $className = $this->mQueryListModules[$generator];\r
-               else if (isset ($this->mQueryPropModules[$generator]))\r
-                       $className = $this->mQueryPropModules[$generator];\r
                else\r
-                       $this->DieDebug("Unknown generator=$generator");\r
-                       \r
-                       \r
-               $module = new $className($this->GetMain(), $this, $generator, $data, true);\r
+                       if (isset ($this->mQueryPropModules[$generator]))\r
+                               $className = $this->mQueryPropModules[$generator];\r
+                       else\r
+                               $this->DieDebug("Unknown generator=$generator");\r
+\r
+               $module = new $className ($this, $generator, true);\r
+\r
+               // change $this->mData\r
 \r
                // TODO: implement\r
                $this->DieUsage("Generator execution has not been implemented", 'notimplemented');\r
@@ -230,6 +237,10 @@ class ApiQuery extends ApiBase {
                // Use parent to make default message for the query module\r
                $msg = parent :: MakeHelpMsg();\r
 \r
+               // Make sure the internal object is empty\r
+               // (just in case a sub-module decides to optimize during instantiation)\r
+               $this->mData = null;\r
+\r
                $astriks = str_repeat('--- ', 8);\r
                $msg .= "\n$astriks Query: Meta  $astriks\n\n";\r
                $msg .= $this->MakeHelpMsgHelper($this->mQueryMetaModules, 'meta');\r
@@ -246,7 +257,7 @@ class ApiQuery extends ApiBase {
 \r
                foreach ($moduleList as $moduleName => $moduleClass) {\r
                        $msg .= "* $paramName=$moduleName *";\r
-                       $module = new $moduleClass ($this->GetMain(), $this, $moduleName, null);\r
+                       $module = new $moduleClass ($this, $moduleName);\r
                        $msg2 = $module->MakeHelpMsg();\r
                        if ($msg2 !== false)\r
                                $msg .= $msg2;\r
index b0530b9..a69ad43 100644 (file)
@@ -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 (
index 176604f..f64acfb 100644 (file)
@@ -31,37 +31,43 @@ if (!defined('MEDIAWIKI')) {
 \r
 abstract class ApiQueryBase extends ApiBase {\r
 \r
-       private $mQueryModule, $mModuleName, $mData, $mGenerator;\r
-       \r
-       public function __construct($main, $query, $moduleName, $data, $generator=false) {\r
-               parent :: __construct($main);\r
+       private $mQueryModule, $mModuleName, $mGenerator;\r
+\r
+       public function __construct($query, $moduleName, $generator = false) {\r
+               parent :: __construct($query->GetMain());\r
                $this->mQueryModule = $query;\r
                $this->mModuleName = $moduleName;\r
-               $this->mData = $data;\r
                $this->mGenerator = $generator;\r
        }\r
-       \r
+\r
        /**\r
         * Get the main Query module \r
         */\r
        public function GetQuery() {\r
                return $this->mQueryModule;\r
        }\r
-       \r
+\r
        /**\r
         * Get the name of the query being executed by this instance \r
-        */ \r
+        */\r
        public function GetModuleName() {\r
                return $this->mModuleName;\r
-       }       \r
-       \r
+       }\r
+\r
+       /**\r
+        * Get the Query database connection (readonly)\r
+        */\r
+       protected function GetDB() {\r
+               return $this->GetQuery()->GetDB();\r
+       }\r
+\r
        /**\r
         * Get the PageSet object to work on\r
         */\r
        protected function GetData() {\r
-               return $this->mData;\r
+               return $this->mQueryModule->GetData();\r
        }\r
-       \r
+\r
        /**\r
         * Return true if this instance is being used as a generator.\r
         */\r
@@ -75,14 +81,12 @@ abstract class ApiQueryBase extends ApiBase {
        public function GetCanGenerate() {\r
                return false;\r
        }\r
-       \r
-       public static function TitleToKey($title)\r
-       {\r
-           return str_replace(' ', '_', $title);\r
+\r
+       public static function TitleToKey($title) {\r
+               return str_replace(' ', '_', $title);\r
        }\r
-       public static function KeyToTitle($key)\r
-       {\r
-           return str_replace('_', ' ', $key);\r
+       public static function KeyToTitle($key) {\r
+               return str_replace('_', ' ', $key);\r
        }\r
 }\r
-?>
\ No newline at end of file
+?>\r
diff --git a/includes/api/ApiQueryContent.php b/includes/api/ApiQueryContent.php
deleted file mode 100644 (file)
index 8a2fee6..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php\r
-\r
-\r
-/*\r
- * Created on Sep 7, 2006\r
- *\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
-       // Eclipse helper - will be ignored in production\r
-       require_once ("ApiQueryBase.php");\r
-}\r
-\r
-class ApiQueryContent extends ApiQueryBase {\r
-\r
-       /**\r
-       * Constructor\r
-       */\r
-       public function __construct($main, $query, $data) {\r
-               parent :: __construct($main, $query);\r
-       }\r
-\r
-       public function Execute() {\r
-               \r
-       }\r
-\r
-       /**\r
-        * Returns an array of allowed parameters (keys) => default value for that parameter\r
-        */\r
-       protected function GetAllowedParams() {\r
-               return array (\r
-                       'param' => 'default',\r
-                       'enumparam' => array (\r
-                               GN_ENUM_DFLT => 'default',\r
-                               GN_ENUM_ISMULTI => false,\r
-                               GN_ENUM_CHOICES => array (\r
-                                       'a',\r
-                                       'b'\r
-                               )\r
-                       )\r
-               );\r
-       }\r
-\r
-       /**\r
-        * Returns the description string for this module\r
-        */\r
-       protected function GetDescription() {\r
-               return 'module a';\r
-       }\r
-\r
-       /**\r
-        * Returns usage examples for this module. Return null if no examples are available.\r
-        */\r
-       protected function GetExamples() {\r
-               return array (\r
-                       'http://...'\r
-               );\r
-       }\r
-}\r
-?>
\ No newline at end of file
index 7caed4f..2cddeb8 100644 (file)
@@ -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() {
index 499af5c..5e25c22 100644 (file)
@@ -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() {
index 50e9c27..2d52e5a 100644 (file)
@@ -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() {