Remove comments literally repeating the next line of code
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index bc76f8f..680e7dc 100644 (file)
@@ -829,6 +829,7 @@ class ApiMain extends ApiBase {
                        'dnt',
                        'origin',
                        /* MediaWiki whitelist */
+                       'user-agent',
                        'api-user-agent',
                ] );
                foreach ( $requestedHeaders as $rHeader ) {
@@ -1276,8 +1277,8 @@ class ApiMain extends ApiBase {
                        if ( $lagInfo['lag'] > $maxLag ) {
                                $response = $this->getRequest()->response();
 
-                               $response->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
-                               $response->header( 'X-Database-Lag: ' . intval( $lagInfo['lag'] ) );
+                               $response->header( 'Retry-After: ' . max( (int)$maxLag, 5 ) );
+                               $response->header( 'X-Database-Lag: ' . (int)$lagInfo['lag'] );
 
                                if ( $this->getConfig()->get( 'ShowHostnames' ) ) {
                                        $this->dieWithError(
@@ -1591,17 +1592,14 @@ class ApiMain extends ApiBase {
                        $this->setupExternalResponse( $module, $params );
                }
 
-               // Execute
                $module->execute();
                Hooks::run( 'APIAfterExecute', [ &$module ] );
 
                $this->reportUnusedParams();
 
                if ( !$this->mInternalMode ) {
-                       // append Debug information
                        MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() );
 
-                       // Print result data
                        $this->printResult();
                }
        }
@@ -1631,7 +1629,7 @@ class ApiMain extends ApiBase {
         */
        protected function logRequest( $time, $e = null ) {
                $request = $this->getRequest();
-               $logCtx = [
+               $legacyLogCtx = [
                        'ts' => time(),
                        'ip' => $request->getIP(),
                        'userAgent' => $this->getUserAgent(),
@@ -1642,17 +1640,43 @@ class ApiMain extends ApiBase {
                        'params' => [],
                ];
 
+               $logCtx = [
+                       '$schema' => '/mediawiki/api/request/0.0.1',
+                       'meta' => [
+                               'id' => UIDGenerator::newUUIDv1(),
+                               'dt' => gmdate( 'c' ),
+                               'domain' => $this->getConfig()->get( 'ServerName' ),
+                               'stream' => 'mediawiki.api-request'
+                       ],
+                       'http' => [
+                               'method' => $request->getMethod(),
+                               'client_ip' => $request->getIP(),
+                               'request_headers' => [
+                                       'user-agent' => $request->getHeader( 'User-agent' ),
+                                       'api-user-agent' => $request->getHeader( 'Api-user-agent' )
+                               ],
+                       ],
+                       'database' => wfWikiID(),
+                       'backend_time_ms' => (int)round( $time * 1000 ),
+                       'params' => []
+               ];
+
+               $logCtx['meta']['request_id'] =
+                       $logCtx['http']['request_headers']['x-request-id'] = WebRequest::getRequestId();
+
                if ( $e ) {
+                       $logCtx['api_error_codes'] = [];
                        foreach ( $this->errorMessagesFromException( $e ) as $msg ) {
-                               $logCtx['errorCodes'][] = $msg->getApiCode();
+                               $legacyLogCtx['errorCodes'][] = $msg->getApiCode();
+                               $logCtx['api_error_codes'][] = $msg->getApiCode();
                        }
                }
 
                // Construct space separated message for 'api' log channel
                $msg = "API {$request->getMethod()} " .
                        wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) .
-                       " {$logCtx['ip']} " .
-                       "T={$logCtx['timeSpentBackend']}ms";
+                       " {$legacyLogCtx['ip']} " .
+                       "T={$legacyLogCtx['timeSpentBackend']}ms";
 
                $sensitive = array_flip( $this->getSensitiveParams() );
                foreach ( $this->getParamsUsed() as $name ) {
@@ -1671,13 +1695,17 @@ class ApiMain extends ApiBase {
                                $encValue = $this->encodeRequestLogValue( $value );
                        }
 
+                       $legacyLogCtx['params'][$name] = $value;
                        $logCtx['params'][$name] = $value;
                        $msg .= " {$name}={$encValue}";
                }
 
                wfDebugLog( 'api', $msg, 'private' );
-               // ApiAction channel is for structured data consumers
-               wfDebugLog( 'ApiAction', '', 'private', $logCtx );
+               // ApiAction channel is for structured data consumers.
+               // The ApiAction was using logging channel is deprecated and is replaced
+               // by the api-request channel.
+               wfDebugLog( 'ApiAction', '', 'private', $legacyLogCtx );
+               wfDebugLog( 'api-request', '', 'private', $logCtx );
        }
 
        /**