Removed all instances of empty() where error suppression was not intended. Replaced...
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 22f14a3..1fc65f3 100644 (file)
@@ -65,6 +65,7 @@ class ApiMain extends ApiBase {
                'feedwatchlist' => 'ApiFeedWatchlist',
                'help' => 'ApiHelp',
                'paraminfo' => 'ApiParamInfo',
+               'purge' => 'ApiPurge',
        );
 
        private static $WriteModules = array (
@@ -77,6 +78,8 @@ class ApiMain extends ApiBase {
                'move' => 'ApiMove',
                'edit' => 'ApiEditPage',
                'emailuser' => 'ApiEmailUser',
+               'watch' => 'ApiWatch',
+               'patrol' => 'ApiPatrol',
        );
 
        /**
@@ -161,9 +164,9 @@ class ApiMain extends ApiBase {
                if($wgEnableWriteAPI)
                        $this->mModules += self::$WriteModules;
 
-               $this->mModuleNames = array_keys($this->mModules); // todo: optimize
+               $this->mModuleNames = array_keys($this->mModules);
                $this->mFormats = self :: $Formats;
-               $this->mFormatNames = array_keys($this->mFormats); // todo: optimize
+               $this->mFormatNames = array_keys($this->mFormats);
 
                $this->mResult = new ApiResult($this);
                $this->mShowVersions = false;
@@ -210,6 +213,8 @@ class ApiMain extends ApiBase {
                if (!$wgUser->isAllowed('writeapi'))
                        $this->dieUsage('You\'re not allowed to edit this ' .
                        'wiki through the API', 'writeapidenied');
+               if (wfReadOnly())
+                       $this->dieUsageMsg(array('readonlytext'));
        }
 
        /**
@@ -252,6 +257,11 @@ class ApiMain extends ApiBase {
                try {
                        $this->executeAction();
                } catch (Exception $e) {
+                       // Log it
+                       if ( $e instanceof MWException ) {
+                               wfDebugLog( 'exception', $e->getLogMessage() );
+                       }
+
                        //
                        // Handle any kind of exception by outputing properly formatted error message.
                        // If this fails, an unhandled exception should be thrown so that global error
@@ -265,7 +275,7 @@ class ApiMain extends ApiBase {
 
                        $headerStr = 'MediaWiki-API-Error: ' . $errCode;
                        if ($e->getCode() === 0)
-                               header($headerStr, true);
+                               header($headerStr);
                        else
                                header($headerStr, true, $e->getCode());
 
@@ -280,8 +290,8 @@ class ApiMain extends ApiBase {
                if($this->mSquidMaxage == -1)
                {
                        # Nobody called setCacheMaxAge(), use the (s)maxage parameters
-                       $smaxage = $this->mRequest->getVal('smaxage', 0);
-                       $maxage = $this->mRequest->getVal('maxage', 0);
+                       $smaxage = $this->getParameter('smaxage');
+                       $maxage = $this->getParameter('maxage');
                }
                else
                        $smaxage = $maxage = $this->mSquidMaxage;
@@ -382,6 +392,9 @@ class ApiMain extends ApiBase {
                        $maxLag = $params['maxlag'];
                        list( $host, $lag ) = wfGetLB()->getMaxLag();
                        if ( $lag > $maxLag ) {
+                               header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
+                               header( 'X-Database-Lag: ' . intval( $lag ) );
+                               // XXX: should we return a 503 HTTP error code like wfMaxlagError() does?
                                if( $wgShowHostnames ) {
                                        ApiBase :: dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
                                } else {
@@ -410,6 +423,7 @@ class ApiMain extends ApiBase {
                // Execute
                $module->profileIn();
                $module->execute();
+               wfRunHooks('APIAfterExecute', array(&$module));
                $module->profileOut();
 
                if (!$this->mInternalMode) {
@@ -521,7 +535,7 @@ class ApiMain extends ApiBase {
                        'API developers:',
                        '    Roan Kattouw <Firstname>.<Lastname>@home.nl (lead developer Sep 2007-present)',
                        '    Victor Vasiliev - vasilvv at gee mail dot com',
-                       '    Bryan Tongh Minh - bryan dot tonghminh at gee mail dot com',
+                       '    Bryan Tong Minh - bryan . tongminh @ gmail . 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',
@@ -576,7 +590,7 @@ class ApiMain extends ApiBase {
 
        public static function makeHelpMsgHeader($module, $paramName) {
                $modulePrefix = $module->getModulePrefix();
-               if (!empty($modulePrefix))
+               if (strval($modulePrefix) !== '')
                        $modulePrefix = "($modulePrefix) ";
 
                return "* $paramName={$module->getModuleName()} $modulePrefix*";