* API: added version information to each module (available via api.php?version command)
authorYuri Astrakhan <yurik@users.mediawiki.org>
Sun, 1 Oct 2006 21:20:55 +0000 (21:20 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Sun, 1 Oct 2006 21:20:55 +0000 (21:20 +0000)
16 files changed:
includes/api/ApiBase.php
includes/api/ApiFormatBase.php
includes/api/ApiFormatJson.php
includes/api/ApiFormatXml.php
includes/api/ApiFormatYaml.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/ApiQueryInfo.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiResult.php

index c145b1d..80c0182 100644 (file)
@@ -47,7 +47,7 @@ abstract class ApiBase {
        /**
         * Executes this module
         */
-       abstract function execute();
+       public abstract function execute();
 
        /**
         * Get main module
@@ -114,6 +114,13 @@ abstract class ApiBase {
                                $msg .= 'Example' . (count($examples) > 1 ? 's' : '') . ":\n  ";
                                $msg .= implode($lnPrfx, $examples) . "\n";
                        }
+
+                       if ($this->getMain()->getShowVersions()) {
+                               $versions = $this->getVersion();
+                               if (is_array($versions))
+                                       $versions = implode("\n  ", $versions);
+                               $msg .= "Version:\n  $versions\n";
+                       }
                }
 
                return $msg;
@@ -390,5 +397,9 @@ abstract class ApiBase {
                        ApiBase :: dieDebug(__METHOD__, 'called without calling profileDBOut() first');
                return $this->mDBTime;
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index e960699..f6d7dce 100644 (file)
@@ -152,5 +152,9 @@ abstract class ApiFormatBase extends ApiBase {
        protected function getExamples() {
                return 'api.php?action=query&meta=siteinfo&si=namespaces&format=' . $this->mOriginalFormat;
        }
+
+       public static function getBaseVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index 12048d0..b13551e 100644 (file)
@@ -48,5 +48,9 @@ class ApiFormatJson extends ApiFormatBase {
        protected function getDescription() {
                return 'Output data in JSON format';
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index 31edc84..11efcf9 100644 (file)
@@ -153,5 +153,9 @@ class ApiFormatXml extends ApiFormatBase {
                        'xmlindent' => 'Enable XML indentation'
                );
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index ed52fb5..ca952e2 100644 (file)
@@ -47,5 +47,9 @@ class ApiFormatYaml extends ApiFormatBase {
        protected function getDescription() {
                return 'Output data in YAML format';
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index b90ab0c..a3380a9 100644 (file)
@@ -47,5 +47,9 @@ class ApiHelp extends ApiBase {
                        'Display this help screen.'
                );
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index d253804..932d777 100644 (file)
@@ -108,5 +108,9 @@ class ApiLogin extends ApiBase {
                        'This module is used to login and get the authentication tokens.'
                );
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
index 767c7d9..0a55346 100644 (file)
@@ -31,7 +31,7 @@ if (!defined('MEDIAWIKI')) {
 
 class ApiMain extends ApiBase {
 
-       private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mApiStartTime, $mResult;
+       private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mApiStartTime, $mResult, $mShowVersions;
 
        /**
        * Constructor
@@ -48,12 +48,17 @@ class ApiMain extends ApiBase {
                $this->mFormatNames = array_keys($formats);
                $this->mApiStartTime = $apiStartTime;
                $this->mResult = new ApiResult($this);
+               $this->mShowVersions = false;
        }
 
        public function & getResult() {
                return $this->mResult;
        }
 
+       public function getShowVersions() {
+               return $this->mShowVersions;
+       }
+
        protected function getAllowedParams() {
                return array (
                        'format' => array (
@@ -63,22 +68,25 @@ class ApiMain extends ApiBase {
                        'action' => array (
                                ApiBase :: PARAM_DFLT => 'help',
                                ApiBase :: PARAM_TYPE => $this->mModuleNames
-                       )
+                       ),
+                       'version' => false
                );
        }
 
        protected function getParamDescription() {
                return array (
                        'format' => 'The format of the output',
-                       'action' => 'What action you would like to perform'
+                       'action' => 'What action you would like to perform',
+                       'version' => 'When showing help, include version for each module'
                );
        }
 
        public function execute() {
                $this->profileIn();
-               $action = $format = null;
+               $action = $format = $version = null;
                try {
                        extract($this->extractRequestParams());
+                       $this->mShowVersions = $version;
 
                        // Create an appropriate printer
                        $this->mPrinter = new $this->mFormats[$format] ($this, $format);
@@ -89,11 +97,14 @@ class ApiMain extends ApiBase {
                        $module->execute();
                        $module->profileOut();
                        $this->printResult(false);
+
                } catch (UsageException $e) {
+
                        // Printer may not be initialized if the extractRequestParams() fails for the main module
                        if (!isset ($this->mPrinter))
                                $this->mPrinter = new $this->mFormats[API_DEFAULT_FORMAT] ($this, API_DEFAULT_FORMAT);
                        $this->printResult(true);
+
                }
                $this->profileOut();
        }
@@ -177,6 +188,12 @@ class ApiMain extends ApiBase {
                }
                return $this->mIsBot;
        }
+
+       public function getVersion() {
+
+               return array (
+               parent :: getVersion(), __CLASS__ . ': $Id$', ApiFormatBase :: getBaseVersion());
+       }
 }
 
 /**
index 13c3751..4bff40e 100644 (file)
@@ -399,5 +399,10 @@ class ApiPageSet extends ApiQueryBase {
                        'redirects' => 'Automatically resolve redirects'
                );
        }
+
+       public function getVersion() {
+               return array (
+               parent :: getVersion(), __CLASS__ . ': $Id$');
+       }
 }
 ?>
\ No newline at end of file
index 533c95c..9a45b53 100644 (file)
@@ -302,8 +302,8 @@ class ApiQuery extends ApiBase {
         * Override to add extra parameters from PageSet
         */
        public function makeHelpMsgParameters() {
-               $module = new ApiPageSet($this);
-               return $module->makeHelpMsgParameters() . parent :: makeHelpMsgParameters();
+               $psModule = new ApiPageSet($this);
+               return $psModule->makeHelpMsgParameters() . parent :: makeHelpMsgParameters();
        }
 
        protected function getParamDescription() {
@@ -328,5 +328,12 @@ class ApiQuery extends ApiBase {
                        'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment'
                );
        }
+
+       public function getVersion() {
+               $psModule = new ApiPageSet($this);
+               $vers = $psModule->getVersion();
+               $vers[] = __CLASS__ . ': $Id$';
+               return $vers;
+       }
 }
 ?>
index 6c519c5..393dc61 100644 (file)
@@ -140,8 +140,13 @@ class ApiQueryAllpages extends ApiQueryBase {
                        'api.php?action=query&list=allpages&apfrom=B&aplimit=5'
                );
        }
+
        public function getCanGenerate() {
                return true;
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index 927af18..1708143 100644 (file)
@@ -93,8 +93,13 @@ abstract class ApiQueryBase extends ApiBase {
        public static function titleToKey($title) {
                return str_replace(' ', '_', $title);
        }
+       
        public static function keyToTitle($key) {
                return str_replace('_', ' ', $key);
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
index 2a1e059..baee279 100644 (file)
@@ -76,5 +76,9 @@ class ApiQueryInfo extends ApiQueryBase {
                        'api.php?action=query&prop=info&titles=Main%20Page'
                );
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index 7a12ce7..613b91f 100644 (file)
@@ -308,5 +308,9 @@ class ApiQueryRevisions extends ApiQueryBase {
                        '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000'
                );
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index 0ec37dd..d78ca86 100644 (file)
@@ -105,5 +105,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        protected function getExamples() {
                return 'api.php?action=query&meta=siteinfo&siprop=general|namespaces';
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file
index 55cdafb..a414c7d 100644 (file)
@@ -145,5 +145,9 @@ class ApiResult extends ApiBase {
        public function execute() {
                ApiBase :: dieDebug(__METHOD__, 'execute() is not supported on Result object');
        }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
 }
 ?>
\ No newline at end of file