From c01eb06e5ef995c4163e6dacb9a596226db5d57e Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 2 Oct 2006 18:27:06 +0000 Subject: [PATCH] *API: better version gen, added check for read-only api, added allpages params description --- api.php | 6 +++++- includes/api/ApiBase.php | 4 +++- includes/api/ApiFormatBase.php | 2 ++ includes/api/ApiMain.php | 21 ++++++++++++++++----- includes/api/ApiPageSet.php | 3 +-- includes/api/ApiQuery.php | 3 ++- includes/api/ApiQueryAllpages.php | 7 ++++++- includes/api/ApiQueryBase.php | 2 +- includes/api/ApiQueryRevisions.php | 12 ++++++++---- 9 files changed, 44 insertions(+), 16 deletions(-) diff --git a/api.php b/api.php index a2c2c054d3..fd56db4ff3 100644 --- a/api.php +++ b/api.php @@ -103,7 +103,11 @@ if (!isset ($wgEnableAPI) || !$wgEnableAPI) { } $wgAutoloadClasses = array_merge($wgAutoloadClasses, $wgApiAutoloadClasses); -$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats); + +if (!isset($wgEnableWriteAPI)) + $wgEnableWriteAPI = false; // This should be 'true' later, once the api is stable. + +$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats, $wgEnableWriteAPI); $processor->execute(); wfProfileOut('api.php'); diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 80c0182956..b4a18a91b1 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -398,7 +398,9 @@ abstract class ApiBase { return $this->mDBTime; } - public function getVersion() { + public abstract function getVersion(); + + public static function getBaseVersion() { return __CLASS__ . ': $Id$'; } } diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index f6d7dce3eb..64f6b95ac6 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -142,6 +142,8 @@ abstract class ApiFormatBase extends ApiBase { $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '\\0', $text); // make strings inside * bold $text = ereg_replace("\\*[^<>\n]+\\*", '\\0', $text); + // make strings inside $ italic + $text = ereg_replace("\\$[^<>\n]+\\$", '\\0', $text); return $text; } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 0a55346a20..1f4214adc2 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -31,14 +31,15 @@ if (!defined('MEDIAWIKI')) { class ApiMain extends ApiBase { - private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mApiStartTime, $mResult, $mShowVersions; + private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames; + private $mApiStartTime, $mResult, $mShowVersions, $mEnableWrite; /** * Constructor * $apiStartTime - time of the originating call for profiling purposes * $modules - an array of actions (keys) and classes that handle them (values) */ - public function __construct($apiStartTime, $modules, $formats) { + public function __construct($apiStartTime, $modules, $formats, $enableWrite) { // Special handling for the main module: $parent === $this parent :: __construct($this); @@ -49,6 +50,7 @@ class ApiMain extends ApiBase { $this->mApiStartTime = $apiStartTime; $this->mResult = new ApiResult($this); $this->mShowVersions = false; + $this->mEnableWrite = $enableWrite; } public function & getResult() { @@ -59,6 +61,12 @@ class ApiMain extends ApiBase { return $this->mShowVersions; } + public function requestWriteMode() { + if (!$this->mEnableWrite) + $this->dieUsage('Editing of this site is disabled. Make sure the $wgEnableWriteAPI=true; ' . + 'statement is included in the site\'s LocalSettings.php file', 'readonly'); + } + protected function getAllowedParams() { return array ( 'format' => array ( @@ -190,9 +198,12 @@ class ApiMain extends ApiBase { } public function getVersion() { - - return array ( - parent :: getVersion(), __CLASS__ . ': $Id$', ApiFormatBase :: getBaseVersion()); + $vers = array (); + $vers[] = __CLASS__ . ': $Id$'; + $vers[] = ApiBase :: getBaseVersion(); + $vers[] = ApiFormatBase :: getBaseVersion(); + $vers[] = ApiQueryBase :: getBaseVersion(); + return $vers; } } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 4bff40e352..0c1b7c406a 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -401,8 +401,7 @@ class ApiPageSet extends ApiQueryBase { } public function getVersion() { - return array ( - parent :: getVersion(), __CLASS__ . ': $Id$'); + return __CLASS__ . ': $Id$'; } } ?> \ No newline at end of file diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 9a45b53ec8..4fc2b9e12c 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -331,8 +331,9 @@ class ApiQuery extends ApiBase { public function getVersion() { $psModule = new ApiPageSet($this); - $vers = $psModule->getVersion(); + $vers = array(); $vers[] = __CLASS__ . ': $Id$'; + $vers[] = $psModule->getVersion(); return $vers; } } diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index 393dc61b3e..d499e246df 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -127,7 +127,12 @@ class ApiQueryAllpages extends ApiQueryBase { } protected function getParamDescription() { - return array (); + 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' + ); } protected function getDescription() { diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 1708143687..3928a2f679 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -98,7 +98,7 @@ abstract class ApiQueryBase extends ApiBase { return str_replace('_', ' ', $key); } - public function getVersion() { + public static function getBaseVersion() { return __CLASS__ . ': $Id$'; } } diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 613b91ff24..51270cbbf9 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -99,9 +99,6 @@ class ApiQueryRevisions extends ApiQueryBase { $showComment = true; break; case 'content' : - // todo: check the page count/limit when requesting content - //$this->validateLimit( 'content: (rvlimit*pages)+revids', - //$rvlimit * count($this->existingPageIds) + count($this->revIdsArray), 50, 200 ); $tables[] = 'text'; $conds[] = 'rev_text_id=old_id'; $fields[] = 'old_id'; @@ -127,7 +124,14 @@ class ApiQueryRevisions extends ApiQueryBase { if ($rvendid !== 0 && isset ($rvend)) $this->dieUsage('rvend and rvend cannot be used together', 'rv_badparams'); - $options['ORDER BY'] = 'rev_timestamp' . ($dirNewer ? '' : ' DESC'); + // 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, + // but to page through results use the rev_id returned after each page. + // 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'); + $before = ($dirNewer ? '<=' : '>='); $after = ($dirNewer ? '>=' : '<='); -- 2.20.1