From 3a24c169ea1474940633bead66fc3911fd740fc8 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sun, 2 Dec 2007 15:04:53 +0000 Subject: [PATCH] API: * Hide edit modules from help if $wgEnableWriteAPI is disabled * Fix help formatting on UsageException --- includes/api/ApiBase.php | 7 +++++++ includes/api/ApiChangeRights.php | 4 ++++ includes/api/ApiDelete.php | 4 ++++ includes/api/ApiMain.php | 8 +++++--- includes/api/ApiMove.php | 4 ++++ includes/api/ApiProtect.php | 4 ++++ includes/api/ApiRollback.php | 4 ++++ includes/api/ApiUnblock.php | 4 ++++ includes/api/ApiUndelete.php | 4 ++++ 9 files changed, 40 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 843a3fa967..da3ad3b304 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 diff --git a/includes/api/ApiChangeRights.php b/includes/api/ApiChangeRights.php index e8138b8710..f9ae90d3c9 100644 --- a/includes/api/ApiChangeRights.php +++ b/includes/api/ApiChangeRights.php @@ -123,6 +123,10 @@ class ApiChangeRights extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $res); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'user' => null, diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 2d7620a4e6..cc66fd81d8 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -137,6 +137,10 @@ class ApiDelete extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $r); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'title' => null, diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index f0c8f55967..3cabf542e9 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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) diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index cdda5b1517..282f32c7f9 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -141,6 +141,10 @@ class ApiMove extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $r); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'from' => null, diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index e48bfe602c..8205a685b1 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -99,6 +99,10 @@ class ApiProtect extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $res); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'title' => null, diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 78d4c1b528..39d908e522 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -116,6 +116,10 @@ class ApiRollback extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $info); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'title' => null, diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index 7b82998ca8..c8e76d8dc8 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -91,6 +91,10 @@ class ApiUnblock extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $res); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'id' => null, diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 48de1a3348..2359f32bd0 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -89,6 +89,10 @@ class ApiUndelete extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $info); } + public function isEditMode() { + return true; + } + protected function getAllowedParams() { return array ( 'title' => null, -- 2.20.1