* API: Optimized PageSet object to avoid executing queries against page table twice.
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 0a55346..f31f3e2 100644 (file)
@@ -31,16 +31,17 @@ 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);
+               parent :: __construct($this, 'main');
 
                $this->mModules = $modules;
                $this->mModuleNames = array_keys($modules);
@@ -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 (
@@ -140,7 +148,8 @@ class ApiMain extends ApiBase {
                        header($errorCode, true, $httpRespCode);
 
                $data = array (
-                       'code' => $errorCode
+                       'code' => $errorCode,
+                       'info' => $description
                );
                ApiResult :: setContent($data, $this->makeHelpMsg());
                $this->mResult->addValue(null, 'error', $data);
@@ -190,9 +199,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;
        }
 }