API: Don't use a nonexistent message name
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index d8bc30e..6a57427 100644 (file)
@@ -53,13 +53,27 @@ class ApiMain extends ApiBase {
         */
        private static $Modules = array (
                'login' => 'ApiLogin',
+               'logout' => 'ApiLogout',
                'query' => 'ApiQuery',
                'expandtemplates' => 'ApiExpandTemplates',
-               'render' => 'ApiRender',
                'parse' => 'ApiParse',
                'opensearch' => 'ApiOpenSearch',
                'feedwatchlist' => 'ApiFeedWatchlist',
                'help' => 'ApiHelp',
+               'paraminfo' => 'ApiParamInfo',
+       );
+       
+       private static $WriteModules = array (
+               'rollback' => 'ApiRollback',
+               'delete' => 'ApiDelete',
+               'undelete' => 'ApiUndelete',
+               'protect' => 'ApiProtect',
+               'block' => 'ApiBlock',
+               'unblock' => 'ApiUnblock',
+               'move' => 'ApiMove',
+               'edit' => 'ApiEditPage',
+               #'changerights' => 'ApiChangeRights'
+               # Disabled for now
        );
 
        /**
@@ -76,7 +90,11 @@ class ApiMain extends ApiBase {
                'xmlfm' => 'ApiFormatXml',
                'yaml' => 'ApiFormatYaml',
                'yamlfm' => 'ApiFormatYaml',
-               'rawfm' => 'ApiFormatJson'
+               'rawfm' => 'ApiFormatJson',
+               'txt' => 'ApiFormatTxt',
+               'txtfm' => 'ApiFormatTxt',
+               'dbg' => 'ApiFormatDbg',
+               'dbgfm' => 'ApiFormatDbg'
        );
 
        private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
@@ -101,16 +119,27 @@ class ApiMain extends ApiBase {
                        // If the current user cannot read, 
                        // Remove all modules other than login
                        global $wgUser;
+                       
+                       if( $request->getVal( 'callback' ) !== null ) {
+                               // JSON callback allows cross-site reads.
+                               // For safety, strip user credentials.
+                               wfDebug( "API: stripping user credentials for JSON callback\n" );
+                               $wgUser = new User();
+                       }
+                       
                        if (!$wgUser->isAllowed('read')) {
                                self::$Modules = array(
-                                       'login' => self::$Modules['login'],
-                                       'help' => self::$Modules['help']
+                                       'login'  => self::$Modules['login'],
+                                       'logout' => self::$Modules['logout'],
+                                       'help'   => self::$Modules['help'],
                                        ); 
                        }
                }
 
-               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;
@@ -152,7 +181,7 @@ class ApiMain extends ApiBase {
        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');
+                       'statement is included in the site\'s LocalSettings.php file', 'noapiwrite');
        }
 
        /**
@@ -282,9 +311,9 @@ class ApiMain extends ApiBase {
         * Execute the actual module, without any error handling
         */
        protected function executeAction() {
-               
+
                $params = $this->extractRequestParams();
-               
+
                $this->mShowVersions = $params['version'];
                $this->mAction = $params['action'];
 
@@ -305,8 +334,11 @@ class ApiMain extends ApiBase {
                                return;
                        }
                }
-
+               
                if (!$this->mInternalMode) {
+                       // Ignore mustBePosted() for internal calls
+                       if($module->mustBePosted() && !$this->mRequest->wasPosted())
+                               $this->dieUsage("The {$this->mAction} module requires a POST request", 'mustbeposted');
 
                        // See if custom printer is used
                        $this->mPrinter = $module->getCustomPrinter();
@@ -317,9 +349,6 @@ class ApiMain extends ApiBase {
 
                        if ($this->mPrinter->getNeedsRawData())
                                $this->getResult()->setRawMode();
-
-                       if( $this->mAction == 'help' )
-                               $this->mPrinter->setHelp();
                }
 
                // Execute
@@ -357,7 +386,7 @@ class ApiMain extends ApiBase {
        /**
         * See ApiBase for description.
         */
-       protected function getAllowedParams() {
+       public function getAllowedParams() {
                return array (
                        'format' => array (
                                ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
@@ -377,7 +406,7 @@ class ApiMain extends ApiBase {
        /**
         * See ApiBase for description.
         */
-       protected function getParamDescription() {
+       public function getParamDescription() {
                return array (
                        'format' => 'The format of the output',
                        'action' => 'What action you would like to perform',
@@ -389,7 +418,7 @@ class ApiMain extends ApiBase {
        /**
         * See ApiBase for description.
         */
-       protected function getDescription() {
+       public function getDescription() {
                return array (
                        '',
                        '',
@@ -422,8 +451,13 @@ class ApiMain extends ApiBase {
         */
        protected function getCredits() {
                return array(
-                       'This API is being implemented by Yuri Astrakhan [[User:Yurik]] / <Firstname><Lastname>@gmail.com',
-                       'Please leave your comments and suggestions at http://www.mediawiki.org/wiki/API'
+                       'API developers:',
+                       '    Roan Kattouw <Firstname>.<Lastname>@home.nl (lead developer Sep 2007-present)',
+                       '    Victor Vasiliev - vasilvv at gee mail dot com',
+                       '    Yuri Astrakhan <Firstname><Lastname>@gmail.com (creator, lead developer Sep 2006-Sep 2007)',
+                       '',
+                       'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
+                       'or file a bug report at http://bugzilla.wikimedia.org/'
                );
        }
 
@@ -431,6 +465,8 @@ class ApiMain extends ApiBase {
         * Override the parent to generate help messages for all available modules.
         */
        public function makeHelpMsg() {
+               
+               $this->mPrinter->setHelp();
 
                // Use parent to make default message for the main module
                $msg = parent :: makeHelpMsg();
@@ -552,6 +588,13 @@ class ApiMain extends ApiBase {
        protected function addFormat( $fmtName, $fmtClass ) {
                $this->mFormats[$fmtName] = $fmtClass;
        }
+       
+       /**
+        * Get the array mapping module names to class names
+        */
+       function getModules() {
+               return $this->mModules;
+       }
 }
 
 /**