API:
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sun, 2 Dec 2007 15:04:53 +0000 (15:04 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sun, 2 Dec 2007 15:04:53 +0000 (15:04 +0000)
* Hide edit modules from help if $wgEnableWriteAPI is disabled
* Fix help formatting on UsageException

includes/api/ApiBase.php
includes/api/ApiChangeRights.php
includes/api/ApiDelete.php
includes/api/ApiMain.php
includes/api/ApiMove.php
includes/api/ApiProtect.php
includes/api/ApiRollback.php
includes/api/ApiUnblock.php
includes/api/ApiUndelete.php

index 843a3fa..da3ad3b 100644 (file)
@@ -522,6 +522,13 @@ abstract class ApiBase {
                return true;
        }
 
+       /**
+        * Indicates if this module requires edit mode
+        */
+       public function isEditMode() {
+               return false;
+       }
+
 
        /**
         * Profiling: total module execution time
index e8138b8..f9ae90d 100644 (file)
@@ -123,6 +123,10 @@ class ApiChangeRights extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+\r
        protected function getAllowedParams() {\r
                return array (\r
                        'user' => null,\r
index 2d7620a..cc66fd8 100644 (file)
@@ -137,6 +137,10 @@ class ApiDelete extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $r);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+       \r
        protected function getAllowedParams() {\r
                return array (\r
                        'title' => null,\r
index f0c8f55..3cabf54 100644 (file)
@@ -325,9 +325,6 @@ class ApiMain extends ApiBase {
 
                        if ($this->mPrinter->getNeedsRawData())
                                $this->getResult()->setRawMode();
-
-                       if( $this->mAction == 'help' )
-                               $this->mPrinter->setHelp();
                }
 
                // Execute
@@ -439,6 +436,9 @@ class ApiMain extends ApiBase {
         * Override the parent to generate help messages for all available modules.
         */
        public function makeHelpMsg() {
+               global $wgEnableWriteAPI;
+
+               $this->mPrinter->setHelp();
 
                // Use parent to make default message for the main module
                $msg = parent :: makeHelpMsg();
@@ -447,6 +447,8 @@ class ApiMain extends ApiBase {
                $msg .= "\n\n$astriks Modules  $astriks\n\n";
                foreach( $this->mModules as $moduleName => $unused ) {
                        $module = new $this->mModules[$moduleName] ($this, $moduleName);
+                       if( !$wgEnableWriteAPI && $module->isEditMode() )
+                               continue;
                        $msg .= self::makeHelpMsgHeader($module, 'action');
                        $msg2 = $module->makeHelpMsg();
                        if ($msg2 !== false)
index cdda5b1..282f32c 100644 (file)
@@ -141,6 +141,10 @@ class ApiMove extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $r);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+       \r
        protected function getAllowedParams() {\r
                return array (\r
                        'from' => null,\r
index e48bfe6..8205a68 100644 (file)
@@ -99,6 +99,10 @@ class ApiProtect extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+       \r
        protected function getAllowedParams() {\r
                return array (\r
                        'title' => null,\r
index 78d4c1b..39d908e 100644 (file)
@@ -116,6 +116,10 @@ class ApiRollback extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $info);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+       \r
        protected function getAllowedParams() {\r
                return array (\r
                        'title' => null,\r
index 7b82998..c8e76d8 100644 (file)
@@ -91,6 +91,10 @@ class ApiUnblock extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+       \r
        protected function getAllowedParams() {\r
                return array (\r
                        'id' => null,\r
index 48de1a3..2359f32 100644 (file)
@@ -89,6 +89,10 @@ class ApiUndelete extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $info);\r
        }\r
 \r
+       public function isEditMode() {\r
+               return true;\r
+       }\r
+       \r
        protected function getAllowedParams() {\r
                return array (\r
                        'title' => null,\r