From: Yuri Astrakhan Date: Sun, 1 Oct 2006 21:20:55 +0000 (+0000) Subject: * API: added version information to each module (available via api.php?version command) X-Git-Tag: 1.31.0-rc.0~55676 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=04399b206392b1a48ccb53a63d735e0f9ca7115e;p=lhc%2Fweb%2Fwiklou.git * API: added version information to each module (available via api.php?version command) --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index c145b1df4f..80c0182956 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index e960699b87..f6d7dce3eb 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -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 diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 12048d0bdc..b13551e66a 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -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 diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 31edc8469e..11efcf948c 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -153,5 +153,9 @@ class ApiFormatXml extends ApiFormatBase { 'xmlindent' => 'Enable XML indentation' ); } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } } ?> \ No newline at end of file diff --git a/includes/api/ApiFormatYaml.php b/includes/api/ApiFormatYaml.php index ed52fb5db2..ca952e20f6 100644 --- a/includes/api/ApiFormatYaml.php +++ b/includes/api/ApiFormatYaml.php @@ -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 diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php index b90ab0c5c8..a3380a9733 100644 --- a/includes/api/ApiHelp.php +++ b/includes/api/ApiHelp.php @@ -47,5 +47,9 @@ class ApiHelp extends ApiBase { 'Display this help screen.' ); } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } } ?> \ No newline at end of file diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index d253804692..932d777d7d 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -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$'; + } } ?> diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 767c7d93a2..0a55346a20 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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()); + } } /** diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 13c37514de..4bff40e352 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -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 diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 533c95cd2a..9a45b53ec8 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -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; + } } ?> diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index 6c519c5d6d..393dc61b3e 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -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 diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 927af18953..1708143687 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -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$'; + } } ?> diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 2a1e059a58..baee279595 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -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 diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 7a12ce71eb..613b91ff24 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -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 diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 0ec37dddd4..d78ca86132 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -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 diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 55cdafb6f4..a414c7dd55 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -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