*API: rewired generator (more work needed)
authorYuri Astrakhan <yurik@users.mediawiki.org>
Tue, 3 Oct 2006 05:41:55 +0000 (05:41 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Tue, 3 Oct 2006 05:41:55 +0000 (05:41 +0000)
*API: structure cleanup: module names & parameters

12 files changed:
includes/api/ApiBase.php
includes/api/ApiFormatBase.php
includes/api/ApiHelp.php
includes/api/ApiLogin.php
includes/api/ApiMain.php
includes/api/ApiQuery.php
includes/api/ApiQueryAllpages.php
includes/api/ApiQueryBase.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiResult.php

index bde8b87..bf04426 100644 (file)
@@ -35,13 +35,15 @@ abstract class ApiBase {
        const PARAM_MAX2 = 4;
        const PARAM_MIN = 5;
 
-       private $mMainModule;
+       private $mMainModule, $mModuleName, $mParamPrefix;
 
        /**
        * Constructor
        */
-       public function __construct($mainModule) {
+       public function __construct($mainModule, $moduleName, $paramPrefix = '') {
                $this->mMainModule = $mainModule;
+        $this->mModuleName = $moduleName;
+               $this->mParamPrefix = $paramPrefix;
        }
 
        /**
@@ -49,6 +51,13 @@ abstract class ApiBase {
         */
        public abstract function execute();
 
+    /**
+     * Get the name of the query being executed by this instance 
+     */
+    public function getModuleName() {
+        return $this->mModuleName;
+    }
+
        /**
         * Get main module
         */
@@ -136,7 +145,7 @@ abstract class ApiBase {
                                $desc = isset ($paramsDescription[$paramName]) ? $paramsDescription[$paramName] : '';
                                if (is_array($desc))
                                        $desc = implode("\n" . str_repeat(' ', 19), $desc);
-                               $msg .= sprintf("  %-14s - %s\n", $paramName, $desc);
+                               $msg .= sprintf("  %-14s - %s\n", $this->encodeParamName($paramName), $desc);
                        }
                        return $msg;
 
@@ -171,33 +180,50 @@ abstract class ApiBase {
        protected function getParamDescription() {
                return false;
        }
+       
+       /**
+        * This method mangles parameter name based on the prefix supplied to the constructor.
+        * Override this method to change parameter name during runtime 
+        */
+       public function encodeParamName($paramName) {
+               return $this->mParamPrefix . $paramName;
+       }
 
        /**
        * Using getAllowedParams(), makes an array of the values provided by the user,
        * with key being the name of the variable, and value - validated value from user or default.
        * This method can be used to generate local variables using extract().
-       * 
-       * @param $prefix String: prepend this prefix to all parameter names. 
        */
-       public function extractRequestParams($prefix = '') {
+       public function extractRequestParams() {
                $params = $this->getAllowedParams();
                $results = array ();
 
                foreach ($params as $paramName => $paramSettings)
-                       $results[$paramName] = $this->getParameterFromSettings($prefix . $paramName, $paramSettings);
+                       $results[$paramName] = $this->getParameterFromSettings($paramName, $paramSettings);
 
                return $results;
        }
 
-       protected function getParameter($paramName, $prefix = '') {
+       /**
+        * Get a value for the given parameter 
+        */
+       protected function getParameter($paramName) {
                $params = $this->getAllowedParams();
                $paramSettings = $params[$paramName];
-               return $this->getParameterFromSettings($prefix . $paramName, $paramSettings);
+               return $this->getParameterFromSettings($paramName, $paramSettings);
        }
-       
+
+       /**
+        * Using the settings determine the value for the given parameter
+        * @param $paramName String: parameter name
+        * @param $paramSettings Mixed: default value or an array of settings using PARAM_* constants.
+        */     
        protected function getParameterFromSettings($paramName, $paramSettings) {
                global $wgRequest;
 
+               // Some classes may decide to change parameter names
+               $paramName = $this->encodeParamName($paramName);
+
                if (!is_array($paramSettings)) {
                        $default = $paramSettings;
                        $multi = false;
@@ -319,7 +345,7 @@ abstract class ApiBase {
         * Call main module's error handler 
         */
        public function dieUsage($description, $errorCode, $httpRespCode = 0) {
-               $this->getMain()->mainDieUsage($description, $errorCode, $httpRespCode);
+               $this->getMain()->mainDieUsage($description, $this->encodeParamName($errorCode), $httpRespCode);
        }
 
        /**
index 64f6b95..92c9213 100644 (file)
@@ -31,15 +31,14 @@ if (!defined('MEDIAWIKI')) {
 
 abstract class ApiFormatBase extends ApiBase {
 
-       private $mIsHtml, $mFormat, $mOriginalFormat;
+       private $mIsHtml, $mFormat;
 
        /**
        * Constructor
        */
        public function __construct($main, $format) {
-               parent :: __construct($main);
+               parent :: __construct($main, $format);
 
-               $this->mOriginalFormat = $format;
                $this->mIsHtml = (substr($format, -2, 2) === 'fm'); // ends with 'fm'
                if ($this->mIsHtml)
                        $this->mFormat = substr($format, 0, -2); // remove ending 'fm'
@@ -152,7 +151,7 @@ abstract class ApiFormatBase extends ApiBase {
         * Returns usage examples for this format.
         */
        protected function getExamples() {
-               return 'api.php?action=query&meta=siteinfo&si=namespaces&format=' . $this->mOriginalFormat;
+               return 'api.php?action=query&meta=siteinfo&si=namespaces&format=' . $this->getModuleName();
        }
 
        public static function getBaseVersion() {
index a3380a9..07108ce 100644 (file)
@@ -32,7 +32,7 @@ if (!defined('MEDIAWIKI')) {
 class ApiHelp extends ApiBase {
 
        public function __construct($main, $action) {
-               parent :: __construct($main);
+               parent :: __construct($main, $action);
        }
 
        /**
index 932d777..f008337 100644 (file)
@@ -32,17 +32,17 @@ if (!defined('MEDIAWIKI')) {
 class ApiLogin extends ApiBase {
 
        public function __construct($main, $action) {
-               parent :: __construct($main);
+               parent :: __construct($main, $action, 'lg');
        }
 
        public function execute() {
-               $lgname = $lgpassword = $lgdomain = null;
+               $name = $password = $domain = null;
                extract($this->extractRequestParams());
 
                $params = new FauxRequest(array (
-                       'wpName' => $lgname,
-                       'wpPassword' => $lgpassword,
-                       'wpDomain' => $lgdomain,
+                       'wpName' => $name,
+                       'wpPassword' => $password,
+                       'wpDomain' => $domain,
                        'wpRemember' => ''
                ));
 
@@ -89,17 +89,17 @@ class ApiLogin extends ApiBase {
 
        protected function getAllowedParams() {
                return array (
-                       'lgname' => '',
-                       'lgpassword' => '',
-                       'lgdomain' => null
+                       'name' => '',
+                       'password' => '',
+                       'domain' => null
                );
        }
 
        protected function getParamDescription() {
                return array (
-                       'lgname' => 'User Name',
-                       'lgpassword' => 'Password',
-                       'lgdomain' => 'Domain (optional)'
+                       'name' => 'User Name',
+                       'password' => 'Password',
+                       'domain' => 'Domain (optional)'
                );
        }
 
@@ -108,6 +108,12 @@ class ApiLogin extends ApiBase {
                        'This module is used to login and get the authentication tokens.'
                );
        }
+       
+       protected function getExamples() {
+               return array(
+                       'api.php?action=login&lgname=user&lgpassword=password'
+               );
+       }
 
        public function getVersion() {
                return __CLASS__ . ': $Id$';
index 1f4214a..3f7611d 100644 (file)
@@ -41,7 +41,7 @@ class ApiMain extends ApiBase {
        */
        public function __construct($apiStartTime, $modules, $formats, $enableWrite) {
                // Special handling for the main module: $parent === $this
-               parent :: __construct($this);
+               parent :: __construct($this, 'main');
 
                $this->mModules = $modules;
                $this->mModuleNames = array_keys($modules);
index 4137b1b..92c8284 100644 (file)
@@ -65,7 +65,7 @@ class ApiQuery extends ApiBase {
        private $mSlaveDB = null;
 
        public function __construct($main, $action) {
-               parent :: __construct($main);
+               parent :: __construct($main, $action);
                $this->mPropModuleNames = array_keys($this->mQueryPropModules);
                $this->mListModuleNames = array_keys($this->mQueryListModules);
                $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
@@ -104,12 +104,6 @@ class ApiQuery extends ApiBase {
                //
                $this->mPageSet = new ApiPageSet($this);
 
-               //
-               // If generator is provided, get a new dataset to work on
-               //
-               if (isset ($generator))
-                       $this->executeGenerator($generator);
-
                // Instantiate required modules
                $modules = array ();
                if (isset ($prop))
@@ -129,16 +123,24 @@ class ApiQuery extends ApiBase {
                }
 
                //
-               // Get page information for the given pageSet
+               // If given, execute generator to substitute user supplied data with generated data.  
+               //
+               if (isset ($generator))
+                       $this->executeGenerator($generator);
+
+               //
+               // Populate page information for the given pageSet
                //
                $this->mPageSet->execute();
 
                //
-               // Record page information
+               // Record page information (title, namespace, if exists, etc)
                //
                $this->outputGeneralPageInfo();
 
+               //
                // Execute all requested modules.
+               //
                foreach ($modules as $module) {
                        $module->profileIn();
                        $module->execute();
@@ -213,24 +215,37 @@ class ApiQuery extends ApiBase {
        protected function executeGenerator($generatorName) {
 
                // Find class that implements requested generator
-               if (isset ($this->mQueryListModules[$generatorName]))
+               if (isset ($this->mQueryListModules[$generatorName])) {
                        $className = $this->mQueryListModules[$generatorName];
-               elseif (isset ($this->mQueryPropModules[$generatorName])) $className = $this->mQueryPropModules[$generatorName];
-               else
+               }
+               elseif (isset ($this->mQueryPropModules[$generatorName])) {
+                       $className = $this->mQueryPropModules[$generatorName];
+               } else {
                        ApiBase :: dieDebug(__METHOD__, "Unknown generator=$generatorName");
+               }
 
-               $generator = new $className ($this, $generatorName, true);
-               if (!$generator->getCanGenerate())
+               // Use current pageset as the result, and create a new one just for the generator 
+               $resultPageSet = $this->mPageSet;
+               $this->mPageSet = new ApiPageSet($this);
+
+               // Create and execute the generator
+               $generator = new $className ($this, $generatorName);
+               if (!$generator instanceof ApiQueryGeneratorBase)
                        $this->dieUsage("Module $generatorName cannot be used as a generator", "badgenerator");
-                       
+
+               $generator->setGeneratorMode();
                $generator->requestExtraData();
 
-               // execute pageSet here to get the data required by the generator module
+               // execute current pageSet to get the data for the generator module
                $this->mPageSet->execute();
-
+               
+               // populate resultPageSet with the generator output
                $generator->profileIn();
-               $this->mPageSet = $generator->execute();
+               $generator->executeGenerator($resultPageSet);
                $generator->profileOut();
+               
+               // Swap the resulting pageset back in
+               $this->mPageSet = $resultPageSet;
        }
 
        protected function getAllowedParams() {
@@ -248,8 +263,8 @@ class ApiQuery extends ApiBase {
                                ApiBase :: PARAM_TYPE => $this->mMetaModuleNames
                        ),
                        'generator' => array (
-                           ApiBase::PARAM_TYPE => $this->mAllowedGenerators
-                       )                       
+                               ApiBase :: PARAM_TYPE => $this->mAllowedGenerators
+                       )
                );
        }
 
@@ -286,7 +301,7 @@ class ApiQuery extends ApiBase {
                        $msg2 = $module->makeHelpMsg();
                        if ($msg2 !== false)
                                $msg .= $msg2;
-                       if ($module->getCanGenerate())
+                       if ($module instanceof ApiQueryGeneratorBase)
                                $msg .= "Generator:\n  This module may be used as a generator\n";
                        $moduleDscriptions[] = $msg;
                }
@@ -327,10 +342,10 @@ class ApiQuery extends ApiBase {
 
        public function getVersion() {
                $psModule = new ApiPageSet($this);
-               $vers = array();
+               $vers = array ();
                $vers[] = __CLASS__ . ': $Id$';
                $vers[] = $psModule->getVersion();
                return $vers;
        }
 }
-?>
\ No newline at end of file
+?>
index 2a48eee..55b5bdb 100644 (file)
@@ -29,26 +29,38 @@ if (!defined('MEDIAWIKI')) {
        require_once ('ApiQueryBase.php');
 }
 
-class ApiQueryAllpages extends ApiQueryBase {
+class ApiQueryAllpages extends ApiQueryGeneratorBase {
 
-       public function __construct($query, $moduleName, $generator = false) {
-               parent :: __construct($query, $moduleName, $generator);
+       public function __construct($query, $moduleName) {
+               parent :: __construct($query, $moduleName, 'ap');
        }
 
        public function execute() {
-               $aplimit = $apfrom = $apnamespace = $apfilterredir = null;
+               $this->run();
+       }
+
+       public function executeGenerator($resultPageSet) {
+               $this->run($resultPageSet);
+       }
+
+       private function run($resultPageSet = null) {
+               $limit = $from = $namespace = $filterredir = null;
                extract($this->extractRequestParams());
 
                $db = $this->getDB();
+
                $where = array (
-                       'page_namespace' => $apnamespace
+                       'page_namespace' => $namespace
                );
-               if (isset ($apfrom))
-                       $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($apfrom));
-
-               if ($apfilterredir === 'redirects')
+               if (isset ($from)) {
+                       $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($from));
+               }
+               if ($filterredir === 'redirects') {
                        $where['page_is_redirect'] = 1;
-               elseif ($apfilterredir === 'nonredirects') $where['page_is_redirect'] = 0;
+               }
+               elseif ($filterredir === 'nonredirects') {
+                       $where['page_is_redirect'] = 0;
+               }
 
                $this->profileDBIn();
                $res = $db->select('page', array (
@@ -57,22 +69,18 @@ class ApiQueryAllpages extends ApiQueryBase {
                        'page_title'
                ), $where, __CLASS__ . '::' . __METHOD__, array (
                        'USE INDEX' => 'name_title',
-                       'LIMIT' => $aplimit +1,
+                       'LIMIT' => $limit +1,
                        'ORDER BY' => 'page_namespace, page_title'
                ));
                $this->profileDBOut();
 
                $data = array ();
-               if(!$this->isGenerator())
-                       ApiResult :: setIndexedTagName($data, 'p');
-                       
                $count = 0;
                while ($row = $db->fetchObject($res)) {
-                       if (++ $count > $aplimit) {
+                       if (++ $count > $limit) {
                                // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                $msg = array (
-                                       'continue' => ($this->isGenerator() ? 'g' : '') . 'apfrom=' . ApiQueryBase :: keyToTitle($row->page_title
-                               ));
+                               'continue' => $this->encodeParamName('from') . '='. ApiQueryBase :: keyToTitle($row->page_title));
                                $this->getResult()->addValue('query-status', 'allpages', $msg);
                                break;
                        }
@@ -82,27 +90,26 @@ class ApiQueryAllpages extends ApiQueryBase {
                        if ($title->userCanRead()) {
                                $id = intval($row->page_id);
 
-                               if ($this->isGenerator()) {
-                                       $data[] = $id;  // in generator mode, just assemble a list of page IDs.
-                               } else {
+                               if (is_null($resultPageSet)) {
                                        $pagedata = array ();
                                        $pagedata['id'] = $id;
                                        if ($title->getNamespace() !== 0)
                                                $pagedata['ns'] = $title->getNamespace();
                                        $pagedata['title'] = $title->getPrefixedText();
-       
+
                                        $data[$id] = $pagedata;
+                               } else {
+                                       $data[] = $id; // in generator mode, just assemble a list of page IDs.
                                }
                        }
                }
                $db->freeResult($res);
 
-               if ($this->isGenerator()) {
-                       $pageSet = new ApiPageSet($this->getQuery());
-                       $pageSet->executeForPageIDs($data);
-                       return $pageSet;
-               } else {
+               if (is_null($resultPageSet)) {
+                       ApiResult :: setIndexedTagName($data, 'p');
                        $this->getResult()->addValue('query', 'allpages', $data);
+               } else {
+                       $resultPageSet->executeForPageIDs($data);
                }
        }
 
@@ -116,12 +123,12 @@ class ApiQueryAllpages extends ApiQueryBase {
                }
 
                return array (
-                       'apfrom' => null,
-                       'apnamespace' => array (
+                       'from' => null,
+                       'namespace' => array (
                                ApiBase :: PARAM_DFLT => 0,
                                ApiBase :: PARAM_TYPE => $validNamespaces
                        ),
-                       'apfilterredir' => array (
+                       'filterredir' => array (
                                ApiBase :: PARAM_DFLT => 'all',
                                ApiBase :: PARAM_TYPE => array (
                                        'all',
@@ -129,7 +136,7 @@ class ApiQueryAllpages extends ApiQueryBase {
                                        'nonredirects'
                                )
                        ),
-                       'aplimit' => array (
+                       'limit' => array (
                                ApiBase :: PARAM_DFLT => 10,
                                ApiBase :: PARAM_TYPE => 'limit',
                                ApiBase :: PARAM_MIN => 1,
@@ -141,10 +148,10 @@ class ApiQueryAllpages extends ApiQueryBase {
 
        protected function getParamDescription() {
                return array (
-                       'apfrom' => 'The page title to start enumerating from.',
-                       'apnamespace' => 'The namespace to enumerate. Default 0 (Main).',
-                       'apfilterredir' => 'Which pages to list: "all" (default), "redirects", or "nonredirects"',
-                       'aplimit' => 'How many total pages to return'
+                       'from' => 'The page title to start enumerating from.',
+                       'namespace' => 'The namespace to enumerate. Default 0 (Main).',
+                       'filterredir' => 'Which pages to list: "all" (default), "redirects", or "nonredirects"',
+                       'limit' => 'How many total pages to return'
                );
        }
 
@@ -160,10 +167,6 @@ class ApiQueryAllpages extends ApiQueryBase {
                );
        }
 
-       public function getCanGenerate() {
-               return true;
-       }
-
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
index 4f11520..d688806 100644 (file)
@@ -31,13 +31,11 @@ if (!defined('MEDIAWIKI')) {
 
 abstract class ApiQueryBase extends ApiBase {
 
-       private $mQueryModule, $mModuleName, $mIsGenerator;
-
-       public function __construct($query, $moduleName, $isGenerator = false) {
-               parent :: __construct($query->getMain());
+       private $mQueryModule;
+    
+       public function __construct($query, $moduleName, $paramPrefix = '') {
+               parent :: __construct($query->getMain(), $moduleName, $paramPrefix);
                $this->mQueryModule = $query;
-               $this->mModuleName = $moduleName;
-               $this->mIsGenerator = $isGenerator;
        }
 
        /**
@@ -54,23 +52,6 @@ abstract class ApiQueryBase extends ApiBase {
                return $this->mQueryModule;
        }
 
-       /**
-        * Get the name of the query being executed by this instance 
-        */
-       public function getModuleName() {
-               return $this->mModuleName;
-       }
-
-       /**
-        * Overrides base class to prepend 'g' to every generator parameter
-        */
-       public function extractRequestParams() {
-               $prefix = '';
-               if($this->isGenerator())
-                       $prefix = 'g';
-               return parent :: extractRequestParams($prefix);
-       }
-       
        /**
         * Get the Query database connection (readonly)
         */
@@ -86,24 +67,10 @@ abstract class ApiQueryBase extends ApiBase {
                return $this->mQueryModule->getPageSet();
        }
 
-       /**
-        * Return true if this instance is being used as a generator.
-        */
-       protected function isGenerator() {
-               return $this->mIsGenerator;
-       }
-
-       /**
-        * Derived classes return true when they can be used as title generators for other query modules.
-        */
-       public function getCanGenerate() {
-               return false;
-       }
-
        public static function titleToKey($title) {
                return str_replace(' ', '_', $title);
        }
-       
+
        public static function keyToTitle($key) {
                return str_replace('_', ' ', $key);
        }
@@ -112,4 +79,34 @@ abstract class ApiQueryBase extends ApiBase {
                return __CLASS__ . ': $Id$';
        }
 }
-?>
+
+abstract class ApiQueryGeneratorBase extends ApiQueryBase {
+
+       private $mIsGenerator;
+
+       public function __construct($query, $moduleName, $paramPrefix = '') {
+               parent :: __construct($query, $moduleName, $paramPrefix);
+               $mIsGenerator = false;
+       }
+
+       public function setGeneratorMode() {
+               $this->mIsGenerator = true;
+       }
+
+       /**
+        * Overrides base class to prepend 'g' to every generator parameter
+        */
+       public function encodeParamName($paramName) {
+               if ($this->mIsGenerator)
+                       return 'g' . parent :: encodeParamName($paramName);
+               else
+                       return parent :: encodeParamName($paramName);
+       }
+
+       /**
+        * Execute this module as a generator
+        * @param $resultPageSet PageSet: All output should be appended to this object
+        */
+       public abstract function executeGenerator($resultPageSet);
+}
+?>
\ No newline at end of file
index baee279..cf3f30e 100644 (file)
@@ -31,10 +31,8 @@ if (!defined('MEDIAWIKI')) {
 
 class ApiQueryInfo extends ApiQueryBase {
 
-       //      private $mParameters;
-
-       public function __construct($query, $moduleName, $generator = false) {
-               parent :: __construct($query, $moduleName, $generator);
+       public function __construct($query, $moduleName) {
+               parent :: __construct($query, $moduleName);
        }
 
        public function requestExtraData() {
index 51270cb..dce0a8d 100644 (file)
@@ -31,24 +31,24 @@ if (!defined('MEDIAWIKI')) {
 
 class ApiQueryRevisions extends ApiQueryBase {
 
-       public function __construct($query, $moduleName, $generator = false) {
-               parent :: __construct($query, $moduleName, $generator);
+       public function __construct($query, $moduleName) {
+               parent :: __construct($query, $moduleName, 'rv');
        }
 
        public function execute() {
-               $rvlimit = $rvstartid = $rvendid = $rvstart = $rvend = $rvdir = $rvprop = null;
+               $limit = $startid = $endid = $start = $end = $dir = $prop = null;
                extract($this->extractRequestParams());
 
                $db = $this->getDB();
 
                // true when ordered by timestamp from older to newer, false otherwise
-               $dirNewer = ($rvdir === 'newer');
+               $dirNewer = ($dir === 'newer');
 
                // If any of those parameters are used, work in 'enumeration' mode.
                // Enum mode can only be used when exactly one page is provided.
                // Enumerating revisions on multiple pages make it extremelly 
                // difficult to manage continuations and require additional sql indexes  
-               $enumRevMode = ($rvlimit !== 0 || $rvstartid !== 0 || $rvendid !== 0 || $dirNewer || isset ($rvstart) || isset ($rvend));
+               $enumRevMode = ($limit !== 0 || $startid !== 0 || $endid !== 0 || $dirNewer || isset ($start) || isset ($end));
 
                $pageSet = $this->getPageSet();
                $pageCount = $pageSet->getGoodTitleCount();
@@ -59,13 +59,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                        return;
 
                if ($revCount > 0 && $pageCount > 0)
-                       $this->dieUsage('The revids= parameter may not be used with titles, pageids, or generator options.', 'rv_revids');
+                       $this->dieUsage('The revids= parameter may not be used with titles, pageids, or generator options.', 'revids');
 
                if ($revCount > 0 && $enumRevMode)
-                       $this->dieUsage('The revids= parameter may not be used with the list options (rvlimit, rvstartid, rvendid, dirNewer, rvstart, rvend).', 'rv_revids');
+                       $this->dieUsage('The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids');
 
                if ($revCount === 0 && $pageCount > 1 && $enumRevMode)
-                       $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the rvlimit, rvstartid, rvendid, dirNewer, rvstart, and rvend parameters may only be used on a single page.', 'rv_multpages');
+                       $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, start, and end parameters may only be used on a single page.', 'multpages');
 
                $tables = array (
                        'revision'
@@ -82,9 +82,9 @@ class ApiQueryRevisions extends ApiQueryBase {
                $options = array ();
 
                $showTimestamp = $showUser = $showComment = $showContent = false;
-               if (isset ($rvprop)) {
-                       foreach ($rvprop as $prop) {
-                               switch ($prop) {
+               if (isset ($prop)) {
+                       foreach ($prop as $p) {
+                               switch ($p) {
                                        case 'timestamp' :
                                                $fields[] = 'rev_timestamp';
                                                $showTimestamp = true;
@@ -107,7 +107,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                                $showContent = true;
                                                break;
                                        default :
-                                               ApiBase :: dieDebug(__METHOD__, "unknown rvprop $prop");
+                                               ApiBase :: dieDebug(__METHOD__, "unknown prop $p");
                                }
                        }
                }
@@ -118,11 +118,11 @@ class ApiQueryRevisions extends ApiQueryBase {
                if ($enumRevMode) {
 
                        // This is mostly to prevent parameter errors (and optimize sql?)
-                       if ($rvstartid !== 0 && isset ($rvstart))
-                               $this->dieUsage('rvstart and rvstartid cannot be used together', 'rv_badparams');
+                       if ($startid !== 0 && isset ($start))
+                               $this->dieUsage('start and startid cannot be used together', 'badparams');
 
-                       if ($rvendid !== 0 && isset ($rvend))
-                               $this->dieUsage('rvend and rvend cannot be used together', 'rv_badparams');
+                       if ($endid !== 0 && isset ($end))
+                               $this->dieUsage('end and endid cannot be used together', 'badparams');
 
                        // This code makes an assumption that sorting by rev_id and rev_timestamp produces
                        // the same result. This way users may request revisions starting at a given time,
@@ -130,25 +130,25 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Switching to rev_id removes the potential problem of having more than 
                        // one row with the same timestamp for the same page. 
                        // The order needs to be the same as start parameter to avoid SQL filesort.
-                       $options['ORDER BY'] = ($rvstartid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC');
+                       $options['ORDER BY'] = ($startid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC');
 
                        $before = ($dirNewer ? '<=' : '>=');
                        $after = ($dirNewer ? '>=' : '<=');
 
-                       if ($rvstartid !== 0)
-                               $conds[] = 'rev_id' . $after . intval($rvstartid);
-                       if ($rvendid !== 0)
-                               $conds[] = 'rev_id' . $before . intval($rvendid);
-                       if (isset ($rvstart))
-                               $conds[] = 'rev_timestamp' . $after . $db->addQuotes($rvstart);
-                       if (isset ($rvend))
-                               $conds[] = 'rev_timestamp' . $before . $db->addQuotes($rvend);
+                       if ($startid !== 0)
+                               $conds[] = 'rev_id' . $after . intval($startid);
+                       if ($endid !== 0)
+                               $conds[] = 'rev_id' . $before . intval($endid);
+                       if (isset ($start))
+                               $conds[] = 'rev_timestamp' . $after . $db->addQuotes($start);
+                       if (isset ($end))
+                               $conds[] = 'rev_timestamp' . $before . $db->addQuotes($end);
 
-                       // must manually initialize unset rvlimit
-                       if (!isset ($rvlimit))
-                               $rvlimit = 10;
+                       // must manually initialize unset limit
+                       if (!isset ($limit))
+                               $limit = 10;
 
-                       $this->validateLimit('rvlimit', $rvlimit, 1, $userMax, $botMax);
+                       $this->validateLimit($this->encodeParamName('limit'), $limit, 1, $userMax, $botMax);
 
                        // There is only one ID, use it
                        $conds['rev_page'] = array_pop(array_keys($pageSet->getGoodTitles()));
@@ -165,7 +165,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Get all page IDs
                        $conds['page_id'] = array_keys($pageSet->getGoodTitles());
 
-                       $rvlimit = $pageCount; // assumption testing -- we should never get more then $pageCount rows.
+                       $limit = $pageCount; // assumption testing -- we should never get more then $pageCount rows.
                }
                elseif ($revCount > 0) {
                        $this->validateLimit('rev_count', $revCount, 1, $userMax, $botMax);
@@ -173,11 +173,11 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Get all revision IDs
                        $conds['rev_id'] = array_keys($pageSet->getRevisionIDs());
 
-                       $rvlimit = $revCount; // assumption testing -- we should never get more then $revCount rows.
+                       $limit = $revCount; // assumption testing -- we should never get more then $revCount rows.
                } else
                        ApiBase :: dieDebug(__METHOD__, 'param validation?');
 
-               $options['LIMIT'] = $rvlimit +1;
+               $options['LIMIT'] = $limit +1;
 
                $this->profileDBIn();
                $res = $db->select($tables, $fields, $conds, __METHOD__, $options);
@@ -187,12 +187,12 @@ class ApiQueryRevisions extends ApiQueryBase {
                $count = 0;
                while ($row = $db->fetchObject($res)) {
 
-                       if (++ $count > $rvlimit) {
+                       if (++ $count > $limit) {
                                // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                if (!$enumRevMode)
                                        ApiBase :: dieDebug(__METHOD__, 'Got more rows then expected'); // bug report
 
-                               $startStr = 'rvstartid=' . $row->rev_id;
+                               $startStr = 'startid=' . $row->rev_id;
                                $msg = array (
                                        'continue' => $startStr
                                );
@@ -243,7 +243,7 @@ class ApiQueryRevisions extends ApiQueryBase {
 
        protected function getAllowedParams() {
                return array (
-                       'rvprop' => array (
+                       'prop' => array (
                                ApiBase :: PARAM_ISMULTI => true,
                                ApiBase :: PARAM_TYPE => array (
                                        'timestamp',
@@ -252,22 +252,22 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        'content'
                                )
                        ),
-                       'rvlimit' => array (
+                       'limit' => array (
                                ApiBase :: PARAM_DFLT => 0,
                                ApiBase :: PARAM_TYPE => 'limit',
                                ApiBase :: PARAM_MIN => 0,
                                ApiBase :: PARAM_MAX1 => 50,
                                ApiBase :: PARAM_MAX2 => 500
                        ),
-                       'rvstartid' => 0,
-                       'rvendid' => 0,
-                       'rvstart' => array (
+                       'startid' => 0,
+                       'endid' => 0,
+                       'start' => array (
                                ApiBase :: PARAM_TYPE => 'timestamp'
                        ),
-                       'rvend' => array (
+                       'end' => array (
                                ApiBase :: PARAM_TYPE => 'timestamp'
                        ),
-                       'rvdir' => array (
+                       'dir' => array (
                                ApiBase :: PARAM_DFLT => 'older',
                                ApiBase :: PARAM_TYPE => array (
                                        'newer',
@@ -279,13 +279,13 @@ class ApiQueryRevisions extends ApiQueryBase {
 
        protected function getParamDescription() {
                return array (
-                       'rvprop' => 'Which properties to get for each revision: user|timestamp|comment|content',
-                       'rvlimit' => 'limit how many revisions will be returned (enum)',
-                       'rvstartid' => 'from which revision id to start enumeration (enum)',
-                       'rvendid' => 'stop revision enumeration on this revid (enum)',
-                       'rvstart' => 'from which revision timestamp to start enumeration (enum)',
-                       'rvend' => 'enumerate up to this timestamp (enum)',
-                       'rvdir' => 'direction of enumeration - towards "newer" or "older" revisions (enum)'
+                       'prop' => 'Which properties to get for each revision: user|timestamp|comment|content',
+                       'limit' => 'limit how many revisions will be returned (enum)',
+                       'startid' => 'from which revision id to start enumeration (enum)',
+                       'endid' => 'stop revision enumeration on this revid (enum)',
+                       'start' => 'from which revision timestamp to start enumeration (enum)',
+                       'end' => 'enumerate up to this timestamp (enum)',
+                       'dir' => 'direction of enumeration - towards "newer" or "older" revisions (enum)'
                );
        }
 
@@ -294,7 +294,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        'Get revision information.',
                        'This module may be used in several ways:',
                        ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter.',
-                       ' 2) Get revisions for one given page, by using titles/pageids with rvstart/rvend/rvlimit params.',
+                       ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params.',
                        ' 3) Get data about a set of revisions by setting their IDs with revids parameter.',
                        'All parameters marked as (enum) may only be used with a single page (#2).'
                );
index d78ca86..3bd1cbd 100644 (file)
@@ -32,15 +32,15 @@ if (!defined('MEDIAWIKI')) {
 class ApiQuerySiteinfo extends ApiQueryBase {
 
        public function __construct($query, $moduleName) {
-               parent :: __construct($query, $moduleName);
+               parent :: __construct($query, $moduleName, 'si');
        }
 
        public function execute() {
-               $siprop = null;
+               $prop = null;
                extract($this->extractRequestParams());
 
-               foreach ($siprop as $prop) {
-                       switch ($prop) {
+               foreach ($prop as $p) {
+                       switch ($p) {
 
                                case 'general' :
 
@@ -52,7 +52,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        $data['sitename'] = $wgSitename;
                                        $data['generator'] = "MediaWiki $wgVersion";
                                        $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
-                                       $this->getResult()->addValue('query', $prop, $data);
+                                       $this->getResult()->addValue('query', $p, $data);
                                        break;
 
                                case 'namespaces' :
@@ -66,18 +66,18 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                                ApiResult :: setContent($data[$ns], $title);
                                        }
                                        ApiResult :: setIndexedTagName($data, 'ns');
-                                       $this->getResult()->addValue('query', $prop, $data);
+                                       $this->getResult()->addValue('query', $p, $data);
                                        break;
 
                                default :
-                                       ApiBase :: dieDebug(__METHOD__, "Unknown siprop=$prop");
+                                       ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
                        }
                }
        }
 
        protected function getAllowedParams() {
                return array (
-                       'siprop' => array (
+                       'prop' => array (
                                ApiBase :: PARAM_DFLT => 'general',
                                ApiBase :: PARAM_ISMULTI => true,
                                ApiBase :: PARAM_TYPE => array (
@@ -90,7 +90,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        protected function getParamDescription() {
                return array (
-                       'siprop' => array (
+                       'prop' => array (
                                'Which sysinfo properties to get:',
                                ' "general"    - Overall system information',
                                ' "namespaces" - List of registered namespaces (localized)'
index a414c7d..eff2055 100644 (file)
@@ -37,7 +37,7 @@ class ApiResult extends ApiBase {
        * Constructor
        */
        public function __construct($main) {
-               parent :: __construct($main);
+               parent :: __construct($main, 'result');
                $this->Reset();
        }