Merge "Merge namespace aliases like we merge namespace names"
[lhc/web/wiklou.git] / includes / MediaWiki.php
index 676108c..bb0f1e4 100644 (file)
@@ -308,7 +308,7 @@ class MediaWiki {
                $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
 
                if ( $targetUrl != $request->getFullRequestURL() ) {
-                       $output->setSquidMaxage( 1200 );
+                       $output->setCdnMaxage( 1200 );
                        $output->redirect( $targetUrl, '301' );
                        return true;
                }
@@ -443,15 +443,15 @@ class MediaWiki {
                $action = Action::factory( $act, $page, $this->context );
 
                if ( $action instanceof Action ) {
-                       # Let Squid cache things if we can purge them.
+                       # Let CDN cache things if we can purge them.
                        if ( $this->config->get( 'UseSquid' ) &&
                                in_array(
-                                       // Use PROTO_INTERNAL because that's what getSquidURLs() uses
+                                       // Use PROTO_INTERNAL because that's what getCdnUrls() uses
                                        wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL ),
-                                       $requestTitle->getSquidURLs()
+                                       $requestTitle->getCdnUrls()
                                )
                        ) {
-                               $output->setSquidMaxage( $this->config->get( 'SquidMaxage' ) );
+                               $output->setCdnMaxage( $this->config->get( 'SquidMaxage' ) );
                        }
 
                        $action->show();
@@ -486,35 +486,62 @@ class MediaWiki {
                $this->doPostOutputShutdown( 'normal' );
        }
 
+       /**
+        * @see MediaWiki::preOutputCommit()
+        * @since 1.26
+        */
+       public function doPreOutputCommit() {
+               self::preOutputCommit( $this->context );
+       }
+
        /**
         * This function commits all DB changes as needed before
         * the user can receive a response (in case commit fails)
         *
-        * @since 1.26
+        * @param IContextSource $context
+        * @since 1.27
         */
-       public function doPreOutputCommit() {
+       public static function preOutputCommit( IContextSource $context ) {
                // Either all DBs should commit or none
                ignore_user_abort( true );
 
-               // Commit all changes and record ChronologyProtector positions
+               $config = $context->getConfig();
+
                $factory = wfGetLBFactory();
+               // Check if any transaction was too big
+               $limit = $config->get( 'MaxUserDBWriteDuration' );
+               $factory->forEachLB( function ( LoadBalancer $lb ) use ( $limit ) {
+                       $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $limit ) {
+                               $time = $db->pendingWriteQueryDuration();
+                               if ( $limit > 0 && $time > $limit ) {
+                                       throw new DBTransactionError(
+                                               $db,
+                                               wfMessage( 'transaction-duration-limit-exceeded', $time, $limit )->plain()
+                                       );
+                               }
+                       } );
+               } );
+               // Commit all changes
                $factory->commitMasterChanges();
+               // Record ChronologyProtector positions
                $factory->shutdown();
+               wfDebug( __METHOD__ . ': all transactions committed' );
 
-               wfDebug( __METHOD__ . ' completed; all transactions committed' );
+               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)
-               $request = $this->context->getRequest();
+               $request = $context->getRequest();
                if ( $request->wasPosted() && $factory->hasOrMadeRecentMasterChanges() ) {
-                       $expires = time() + $this->config->get( 'DataCenterUpdateStickTTL' );
-                       $request->response()->setCookie( 'UseDC', 'master', $expires );
+                       $expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
+                       $request->response()->setCookie( 'UseDC', 'master', $expires, array( 'prefix' => '' ) );
                }
 
                // Avoid letting a few seconds of slave lag cause a month of stale data
                if ( $factory->laggedSlaveUsed() ) {
-                       $maxAge = $this->config->get( 'CdnMaxageLagged' );
-                       $this->context->getOutput()->lowerCdnMaxage( $maxAge );
+                       $maxAge = $config->get( 'CdnMaxageLagged' );
+                       $context->getOutput()->lowerCdnMaxage( $maxAge );
                        $request->response()->header( "X-Database-Lagged: true" );
                        wfDebugLog( 'replication', "Lagged DB used; CDN cache TTL limited to $maxAge seconds" );
                }
@@ -531,6 +558,9 @@ class MediaWiki {
         * @since 1.26
         */
        public function doPostOutputShutdown( $mode = 'normal' ) {
+               $timing = $this->context->getTiming();
+               $timing->mark( 'requestShutdown' );
+
                // Show visible profiling data if enabled (which cannot be post-send)
                Profiler::instance()->logDataPageOutputOnly();
 
@@ -707,7 +737,7 @@ class MediaWiki {
                // Commit and close up!
                $factory = wfGetLBFactory();
                $factory->commitMasterChanges();
-               $factory->shutdown();
+               $factory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT );
 
                wfDebug( "Request ended normally\n" );
        }