Add more preOutputCommit() comments
[lhc/web/wiklou.git] / includes / MediaWiki.php
index 3b5a1b1..0e3a734 100644 (file)
@@ -458,7 +458,6 @@ class MediaWiki {
         * @param Title $requestTitle The original title, before any redirects were applied
         */
        private function performAction( Page $page, Title $requestTitle ) {
-
                $request = $this->context->getRequest();
                $output = $this->context->getOutput();
                $title = $this->context->getTitle();
@@ -471,10 +470,16 @@ class MediaWiki {
                }
 
                $act = $this->getAction();
-
                $action = Action::factory( $act, $page, $this->context );
 
                if ( $action instanceof Action ) {
+                       // Narrow DB query expectations for this HTTP request
+                       $trxLimits = $this->config->get( 'TrxProfilerLimits' );
+                       $trxProfiler = Profiler::instance()->getTransactionProfiler();
+                       if ( $request->wasPosted() && !$action->doesWrites() ) {
+                               $trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
+                       }
+
                        # Let CDN cache things if we can purge them.
                        if ( $this->config->get( 'UseSquid' ) &&
                                in_array(
@@ -494,7 +499,6 @@ class MediaWiki {
                        $output->setStatusCode( 404 );
                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                }
-
        }
 
        /**
@@ -562,15 +566,19 @@ class MediaWiki {
                DeferredUpdates::doUpdates( 'enqueue', DeferredUpdates::PRESEND );
                wfDebug( __METHOD__ . ': pre-send deferred updates completed' );
 
-               // Set a cookie to tell all CDN edge nodes to "stick" the user to the
-               // DC that handles this POST request (e.g. the "master" data center)
+               // Set a cookie to tell all CDN edge nodes to "stick" the user to the DC that handles this
+               // POST request (e.g. the "master" data center). Also have the user briefly bypass CDN so
+               // ChronologyProtector works for cacheable URLs.
                $request = $context->getRequest();
                if ( $request->wasPosted() && $factory->hasOrMadeRecentMasterChanges() ) {
                        $expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
-                       $request->response()->setCookie( 'UseDC', 'master', $expires, array( 'prefix' => '' ) );
+                       $options = array( 'prefix' => '' );
+                       $request->response()->setCookie( 'UseDC', 'master', $expires, $options );
+                       $request->response()->setCookie( 'UseCDNCache', 'false', $expires, $options );
                }
 
-               // Avoid letting a few seconds of slave lag cause a month of stale data
+               // Avoid letting a few seconds of slave lag cause a month of stale data. This logic is
+               // also intimately related to the value of $wgCdnReboundPurgeDelay.
                if ( $factory->laggedSlaveUsed() ) {
                        $maxAge = $config->get( 'CdnMaxageLagged' );
                        $context->getOutput()->lowerCdnMaxage( $maxAge );
@@ -623,7 +631,7 @@ class MediaWiki {
        }
 
        private function main() {
-               global $wgTitle, $wgTrxProfilerLimits;
+               global $wgTitle;
 
                $request = $this->context->getRequest();
 
@@ -647,13 +655,14 @@ class MediaWiki {
                $action = $this->getAction();
                $wgTitle = $title;
 
+               // Set DB query expectations for this HTTP request
+               $trxLimits = $this->config->get( 'TrxProfilerLimits' );
                $trxProfiler = Profiler::instance()->getTransactionProfiler();
                $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
-
                if ( $request->wasPosted() ) {
-                       $trxProfiler->setExpectations( $wgTrxProfilerLimits['POST'], __METHOD__ );
+                       $trxProfiler->setExpectations( $trxLimits['POST'], __METHOD__ );
                } else {
-                       $trxProfiler->setExpectations( $wgTrxProfilerLimits['GET'], __METHOD__ );
+                       $trxProfiler->setExpectations( $trxLimits['GET'], __METHOD__ );
                }
 
                // If the user has forceHTTPS set to true, or if the user
@@ -664,8 +673,10 @@ class MediaWiki {
                if (
                        $request->getProtocol() == 'http' &&
                        (
+                               $request->getSession()->shouldForceHTTPS() ||
+                               // Check the cookie manually, for paranoia
                                $request->getCookie( 'forceHTTPS', '' ) ||
-                               // check for prefixed version for currently logged in users
+                               // check for prefixed version that was used for a time in older MW versions
                                $request->getCookie( 'forceHTTPS' ) ||
                                // Avoid checking the user and groups unless it's enabled.
                                (