From fd5a884b77458684e570ae4030c2759ac6108feb Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 3 Dec 2007 15:52:27 +0000 Subject: [PATCH] API: A cleaner implementation of r28057: this one also hides disabled modules from the list of possible actions on top of the help screen. --- includes/api/ApiBlock.php | 6 +++++- includes/api/ApiChangeRights.php | 4 ---- includes/api/ApiDelete.php | 4 ---- includes/api/ApiMain.php | 20 +++++++++++--------- 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, 16 insertions(+), 38 deletions(-) diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 103a7757a9..9899884cb9 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -114,7 +114,11 @@ class ApiBlock 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/ApiChangeRights.php b/includes/api/ApiChangeRights.php index f9ae90d3c9..e8138b8710 100644 --- a/includes/api/ApiChangeRights.php +++ b/includes/api/ApiChangeRights.php @@ -123,10 +123,6 @@ 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 cc66fd81d8..74695f1183 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -136,10 +136,6 @@ class ApiDelete extends ApiBase { $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason); $this->getResult()->addValue(null, $this->getModuleName(), $r); } - - public function isEditMode() { - return true; - } protected function getAllowedParams() { return array ( diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 3cabf542e9..8c06b8fbd2 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -57,6 +57,12 @@ class ApiMain extends ApiBase { 'expandtemplates' => 'ApiExpandTemplates', 'render' => 'ApiRender', 'parse' => 'ApiParse', + 'opensearch' => 'ApiOpenSearch', + 'feedwatchlist' => 'ApiFeedWatchlist', + 'help' => 'ApiHelp', + ); + + private static $WriteModules = array ( 'rollback' => 'ApiRollback', 'delete' => 'ApiDelete', 'undelete' => 'ApiUndelete', @@ -64,10 +70,7 @@ class ApiMain extends ApiBase { 'block' => 'ApiBlock', 'unblock' => 'ApiUnblock', 'changerights' => 'ApiChangeRights', - 'move' => 'ApiMove', - 'opensearch' => 'ApiOpenSearch', - 'feedwatchlist' => 'ApiFeedWatchlist', - 'help' => 'ApiHelp', + 'move' => 'ApiMove' ); /** @@ -117,8 +120,10 @@ class ApiMain extends ApiBase { } } - global $wgAPIModules; // extension modules + global $wgAPIModules, $wgEnableWriteAPI; // extension modules $this->mModules = $wgAPIModules + self :: $Modules; + if($wgEnableWriteAPI) + $this->mModules += self::$WriteModules; $this->mModuleNames = array_keys($this->mModules); // todo: optimize $this->mFormats = self :: $Formats; @@ -436,8 +441,7 @@ 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 @@ -447,8 +451,6 @@ 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 282f32c7f9..f122a29329 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -140,10 +140,6 @@ class ApiMove extends ApiBase { $dbw->commit(); // Make sure all changes are really written to the DB $this->getResult()->addValue(null, $this->getModuleName(), $r); } - - public function isEditMode() { - return true; - } protected function getAllowedParams() { return array ( diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 8205a685b1..e48bfe602c 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -99,10 +99,6 @@ 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 39d908e522..1d0e16ee97 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -115,10 +115,6 @@ class ApiRollback extends ApiBase { $this->getResult()->addValue(null, $this->getModuleName(), $info); } - - public function isEditMode() { - return true; - } protected function getAllowedParams() { return array ( diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index c8e76d8dc8..7b82998ca8 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -91,10 +91,6 @@ 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 2359f32bd0..1e7609e874 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -88,10 +88,6 @@ class ApiUndelete extends ApiBase { $info['reason'] = $retval[2]; $this->getResult()->addValue(null, $this->getModuleName(), $info); } - - public function isEditMode() { - return true; - } protected function getAllowedParams() { return array ( -- 2.20.1