*API: better version gen, added check for read-only api, added allpages params descri...
authorYuri Astrakhan <yurik@users.mediawiki.org>
Mon, 2 Oct 2006 18:27:06 +0000 (18:27 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Mon, 2 Oct 2006 18:27:06 +0000 (18:27 +0000)
api.php
includes/api/ApiBase.php
includes/api/ApiFormatBase.php
includes/api/ApiMain.php
includes/api/ApiPageSet.php
includes/api/ApiQuery.php
includes/api/ApiQueryAllpages.php
includes/api/ApiQueryBase.php
includes/api/ApiQueryRevisions.php

diff --git a/api.php b/api.php
index a2c2c05..fd56db4 100644 (file)
--- 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');
index 80c0182..b4a18a9 100644 (file)
@@ -398,7 +398,9 @@ abstract class ApiBase {
                return $this->mDBTime;
        }
 
-       public function getVersion() {
+       public abstract function getVersion();
+       
+       public static function getBaseVersion() {
                return __CLASS__ . ': $Id$';
        }
 }
index f6d7dce..64f6b95 100644 (file)
@@ -142,6 +142,8 @@ 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);
+               // make strings inside $ italic
+               $text = ereg_replace("\\$[^<>\n]+\\$", '<b><i>\\0</i></b>', $text);
 
                return $text;
        }
index 0a55346..1f4214a 100644 (file)
@@ -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;
        }
 }
 
index 4bff40e..0c1b7c4 100644 (file)
@@ -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
index 9a45b53..4fc2b9e 100644 (file)
@@ -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;
        }
 }
index 393dc61..d499e24 100644 (file)
@@ -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() {
index 1708143..3928a2f 100644 (file)
@@ -98,7 +98,7 @@ abstract class ApiQueryBase extends ApiBase {
                return str_replace('_', ' ', $key);
        }
 
-       public function getVersion() {
+       public static function getBaseVersion() {
                return __CLASS__ . ': $Id$';
        }
 }
index 613b91f..51270cb 100644 (file)
@@ -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 ? '>=' : '<=');