Merge "resourceloader: Omit non-existent messages in MessageBlobStore"
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index a233368..588e31a 100644 (file)
@@ -218,7 +218,7 @@ class ApiMain extends ApiBase {
                                                'cookies' => $sessionCookies,
                                                'ip' => $request->getIP(),
                                                'userAgent' => $this->getUserAgent(),
-                                               'wiki' => wfWikiID(),
+                                               'wiki' => WikiMap::getCurrentWikiDbDomain()->getId(),
                                        ]
                                );
                        }
@@ -321,7 +321,7 @@ class ApiMain extends ApiBase {
                $request = $this->getRequest();
 
                // JSONP mode
-               if ( $request->getVal( 'callback' ) !== null ) {
+               if ( $request->getCheck( 'callback' ) ) {
                        $this->lacksSameOriginSecurity = true;
                        return true;
                }
@@ -1117,19 +1117,17 @@ class ApiMain extends ApiBase {
                                        . $this->msg( 'api-usage-mailinglist-ref' )->inLanguage( $formatter->getLanguage() )->text()
                                )
                        );
-               } else {
-                       if ( $config->get( 'ShowExceptionDetails' ) ) {
-                               $result->addContentValue(
-                                       $path,
-                                       'trace',
-                                       $this->msg( 'api-exception-trace',
-                                               get_class( $e ),
-                                               $e->getFile(),
-                                               $e->getLine(),
-                                               MWExceptionHandler::getRedactedTraceAsString( $e )
-                                       )->inLanguage( $formatter->getLanguage() )->text()
-                               );
-                       }
+               } elseif ( $config->get( 'ShowExceptionDetails' ) ) {
+                       $result->addContentValue(
+                               $path,
+                               'trace',
+                               $this->msg( 'api-exception-trace',
+                                       get_class( $e ),
+                                       $e->getFile(),
+                                       $e->getLine(),
+                                       MWExceptionHandler::getRedactedTraceAsString( $e )
+                               )->inLanguage( $formatter->getLanguage() )->text()
+                       );
                }
 
                // Add the id and such
@@ -1633,7 +1631,7 @@ class ApiMain extends ApiBase {
                        'ts' => time(),
                        'ip' => $request->getIP(),
                        'userAgent' => $this->getUserAgent(),
-                       'wiki' => wfWikiID(),
+                       'wiki' => WikiMap::getCurrentWikiDbDomain()->getId(),
                        'timeSpentBackend' => (int)round( $time * 1000 ),
                        'hadError' => $e !== null,
                        'errorCodes' => [],
@@ -1643,33 +1641,29 @@ class ApiMain extends ApiBase {
                $logCtx = [
                        '$schema' => '/mediawiki/api/request/0.0.1',
                        'meta' => [
+                               'request_id' => WebRequest::getRequestId(),
                                'id' => UIDGenerator::newUUIDv1(),
-                               'dt' => gmdate( 'c' ),
+                               'dt' => wfTimestamp( TS_ISO_8601 ),
                                'domain' => $this->getConfig()->get( 'ServerName' ),
                                'stream' => 'mediawiki.api-request'
                        ],
                        'http' => [
                                'method' => $request->getMethod(),
-                               'client_ip' => $request->getIP(),
-                               'request_headers' => []
+                               'client_ip' => $request->getIP()
                        ],
-                       'database' => wfWikiID(),
+                       'database' => WikiMap::getCurrentWikiDbDomain()->getId(),
                        'backend_time_ms' => (int)round( $time * 1000 ),
-                       'params' => []
                ];
 
                // If set, these headers will be logged in http.request_headers.
-               // A http.request_headers entry should not be set if the header was not provided.
-               if ( $request->getHeader( 'User-agent' ) ) {
-                       $logCtx['http']['request_headers']['user-agent'] = $request->getHeader( 'User-agent' );
-               }
-               if ( $request->getHeader( 'Api-user-agent' ) ) {
-                       $logCtx['http']['request_headers']['api-user-agent'] = $request->getHeader( 'Api-user-agent' );
+               $httpRequestHeadersToLog = [ 'accept-language', 'referer', 'user-agent' ];
+               foreach ( $httpRequestHeadersToLog as $header ) {
+                       if ( $request->getHeader( $header ) ) {
+                               // Set the header in http.request_headers
+                               $logCtx['http']['request_headers'][$header] = $request->getHeader( $header );
+                       }
                }
 
-               $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 ) {