Removed all instances of empty() where error suppression was not intended. Replaced...
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index b3d8a94..1fc65f3 100644 (file)
@@ -164,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;
@@ -257,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
@@ -285,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;
@@ -387,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 {
@@ -582,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*";