Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 588e31a..a77136d 100644 (file)
@@ -148,7 +148,7 @@ class ApiMain extends ApiBase {
        private $mContinuationManager;
        private $mAction;
        private $mEnableWrite;
-       private $mInternalMode, $mSquidMaxage;
+       private $mInternalMode, $mCdnMaxAge;
        /** @var ApiBase */
        private $mModule;
 
@@ -288,7 +288,7 @@ class ApiMain extends ApiBase {
                $this->mContinuationManager = null;
                $this->mEnableWrite = $enableWrite;
 
-               $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
+               $this->mCdnMaxAge = -1; // flag for executeActionWithErrorHandling()
                $this->mCommit = false;
        }
 
@@ -916,32 +916,20 @@ class ApiMain extends ApiBase {
                        return;
                }
 
-               $useKeyHeader = $config->get( 'UseKeyHeader' );
                if ( $this->mCacheMode == 'anon-public-user-private' ) {
                        $out->addVaryHeader( 'Cookie' );
                        $response->header( $out->getVaryHeader() );
-                       if ( $useKeyHeader ) {
-                               $response->header( $out->getKeyHeader() );
-                               if ( $out->haveCacheVaryCookies() ) {
-                                       // Logged in, mark this request private
-                                       $response->header( "Cache-Control: $privateCache" );
-                                       return;
-                               }
-                               // Logged out, send normal public headers below
-                       } elseif ( MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() ) {
+                       if ( MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() ) {
                                // Logged in or otherwise has session (e.g. anonymous users who have edited)
                                // Mark request private
                                $response->header( "Cache-Control: $privateCache" );
 
                                return;
-                       } // else no Key and anonymous, send public headers below
+                       } // else anonymous, send public headers below
                }
 
                // Send public headers
                $response->header( $out->getVaryHeader() );
-               if ( $useKeyHeader ) {
-                       $response->header( $out->getKeyHeader() );
-               }
 
                // If nobody called setCacheMaxAge(), use the (s)maxage parameters
                if ( !isset( $this->mCacheControl['s-maxage'] ) ) {
@@ -1368,18 +1356,20 @@ class ApiMain extends ApiBase {
                                                $ts->format( 'D M j H:i:s Y' ) === $value ||
                                                $ts->format( 'D M  j H:i:s Y' ) === $value
                                        ) {
+                                               $config = $this->getConfig();
                                                $lastMod = $module->getConditionalRequestData( 'last-modified' );
                                                if ( $lastMod !== null ) {
                                                        // Mix in some MediaWiki modification times
                                                        $modifiedTimes = [
                                                                'page' => $lastMod,
                                                                'user' => $this->getUser()->getTouched(),
-                                                               'epoch' => $this->getConfig()->get( 'CacheEpoch' ),
+                                                               'epoch' => $config->get( 'CacheEpoch' ),
                                                        ];
-                                                       if ( $this->getConfig()->get( 'UseSquid' ) ) {
+
+                                                       if ( $config->get( 'UseCdn' ) ) {
                                                                // T46570: the core page itself may not change, but resources might
                                                                $modifiedTimes['sepoch'] = wfTimestamp(
-                                                                       TS_MW, time() - $this->getConfig()->get( 'SquidMaxage' )
+                                                                       TS_MW, time() - $config->get( 'CdnMaxAge' )
                                                                );
                                                        }
                                                        Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes, $this->getOutput() ] );
@@ -1627,24 +1617,17 @@ class ApiMain extends ApiBase {
         */
        protected function logRequest( $time, $e = null ) {
                $request = $this->getRequest();
-               $legacyLogCtx = [
-                       'ts' => time(),
-                       'ip' => $request->getIP(),
-                       'userAgent' => $this->getUserAgent(),
-                       'wiki' => WikiMap::getCurrentWikiDbDomain()->getId(),
-                       'timeSpentBackend' => (int)round( $time * 1000 ),
-                       'hadError' => $e !== null,
-                       'errorCodes' => [],
-                       'params' => [],
-               ];
 
                $logCtx = [
+                       // https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/event-schemas/+/master/jsonschema/mediawiki/api/request
                        '$schema' => '/mediawiki/api/request/0.0.1',
                        'meta' => [
                                'request_id' => WebRequest::getRequestId(),
-                               'id' => UIDGenerator::newUUIDv1(),
+                               'id' => UIDGenerator::newUUIDv4(),
                                'dt' => wfTimestamp( TS_ISO_8601 ),
                                'domain' => $this->getConfig()->get( 'ServerName' ),
+                               // If using the EventBus extension (as intended) with this log channel,
+                               // this stream name will map to a Kafka topic.
                                'stream' => 'mediawiki.api-request'
                        ],
                        'http' => [
@@ -1667,7 +1650,6 @@ class ApiMain extends ApiBase {
                if ( $e ) {
                        $logCtx['api_error_codes'] = [];
                        foreach ( $this->errorMessagesFromException( $e ) as $msg ) {
-                               $legacyLogCtx['errorCodes'][] = $msg->getApiCode();
                                $logCtx['api_error_codes'][] = $msg->getApiCode();
                        }
                }
@@ -1675,8 +1657,8 @@ class ApiMain extends ApiBase {
                // Construct space separated message for 'api' log channel
                $msg = "API {$request->getMethod()} " .
                        wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) .
-                       " {$legacyLogCtx['ip']} " .
-                       "T={$legacyLogCtx['timeSpentBackend']}ms";
+                       " {$logCtx['http']['client_ip']} " .
+                       "T={$logCtx['backend_time_ms']}ms";
 
                $sensitive = array_flip( $this->getSensitiveParams() );
                foreach ( $this->getParamsUsed() as $name ) {
@@ -1695,16 +1677,14 @@ class ApiMain extends ApiBase {
                                $encValue = $this->encodeRequestLogValue( $value );
                        }
 
-                       $legacyLogCtx['params'][$name] = $value;
                        $logCtx['params'][$name] = $value;
                        $msg .= " {$name}={$encValue}";
                }
 
+               // Log an unstructured message to the api channel.
                wfDebugLog( 'api', $msg, 'private' );
-               // 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 );
+
+               // The api-request channel a structured data log channel.
                wfDebugLog( 'api-request', '', 'private', $logCtx );
        }
 
@@ -1838,7 +1818,7 @@ class ApiMain extends ApiBase {
         */
        protected function printResult( $httpCode = 0 ) {
                if ( $this->getConfig()->get( 'DebugAPI' ) !== false ) {
-                       $this->addWarning( 'apiwarn-wgDebugAPI' );
+                       $this->addWarning( 'apiwarn-wgdebugapi' );
                }
 
                $printer = $this->mPrinter;