Expand templates: Use editfont on wikitext inputs
[lhc/web/wiklou.git] / includes / MediaWiki.php
index 7b59ee9..beb9de5 100644 (file)
@@ -26,6 +26,7 @@ use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\ChronologyProtector;
 use Wikimedia\Rdbms\LBFactory;
 use Wikimedia\Rdbms\DBConnectionError;
+use Liuggio\StatsdClient\Sender\SocketSender;
 
 /**
  * The MediaWiki class is the helper class for the index.php entry point.
@@ -367,7 +368,7 @@ class MediaWiki {
                        }
                        throw new HttpError( 500, $message );
                }
-               $output->setSquidMaxage( 1200 );
+               $output->setCdnMaxage( 1200 );
                $output->redirect( $targetUrl, '301' );
                return true;
        }
@@ -712,10 +713,11 @@ class MediaWiki {
                        MWExceptionHandler::rollbackMasterChangesAndLog( $e );
                }
 
+               $blocksHttpClient = true;
                // Defer everything else if possible...
-               $callback = function () use ( $mode ) {
+               $callback = function () use ( $mode, &$blocksHttpClient ) {
                        try {
-                               $this->restInPeace( $mode );
+                               $this->restInPeace( $mode, $blocksHttpClient );
                        } catch ( Exception $e ) {
                                // If this is post-send, then displaying errors can cause broken HTML
                                MWExceptionHandler::rollbackMasterChangesAndLog( $e );
@@ -725,9 +727,11 @@ class MediaWiki {
                if ( function_exists( 'register_postsend_function' ) ) {
                        // https://github.com/facebook/hhvm/issues/1230
                        register_postsend_function( $callback );
+                       $blocksHttpClient = false;
                } else {
                        if ( function_exists( 'fastcgi_finish_request' ) ) {
                                fastcgi_finish_request();
+                               $blocksHttpClient = false;
                        } else {
                                // Either all DB and deferred updates should happen or none.
                                // The latter should not be cancelled due to client disconnect.
@@ -870,8 +874,9 @@ class MediaWiki {
        /**
         * Ends this task peacefully
         * @param string $mode Use 'fast' to always skip job running
+        * @param bool $blocksHttpClient Whether this blocks an HTTP response to a client
         */
-       public function restInPeace( $mode = 'fast' ) {
+       public function restInPeace( $mode = 'fast', $blocksHttpClient = true ) {
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                // Assure deferred updates are not in the main transaction
                $lbFactory->commitMasterChanges( __METHOD__ );
@@ -880,15 +885,17 @@ class MediaWiki {
                $trxProfiler = Profiler::instance()->getTransactionProfiler();
                $trxProfiler->resetExpectations();
                $trxProfiler->setExpectations(
-                       $this->config->get( 'TrxProfilerLimits' )['PostSend'],
+                       $this->context->getRequest()->hasSafeMethod()
+                               ? $this->config->get( 'TrxProfilerLimits' )['PostSend-GET']
+                               : $this->config->get( 'TrxProfilerLimits' )['PostSend-POST'],
                        __METHOD__
                );
 
                // Important: this must be the last deferred update added (T100085, T154425)
                DeferredUpdates::addCallableUpdate( [ JobQueueGroup::class, 'pushLazyJobs' ] );
 
-               // Do any deferred jobs
-               DeferredUpdates::doUpdates( 'enqueue' );
+               // Do any deferred jobs; preferring to run them now if a client will not wait on them
+               DeferredUpdates::doUpdates( $blocksHttpClient ? 'enqueue' : 'run' );
 
                // Now that everything specific to this request is done,
                // try to occasionally run jobs (if enabled) from the queues
@@ -906,6 +913,34 @@ class MediaWiki {
                wfDebug( "Request ended normally\n" );
        }
 
+       /**
+        * Send out any buffered statsd data according to sampling rules
+        *
+        * @param IBufferingStatsdDataFactory $stats
+        * @param Config $config
+        * @throws ConfigException
+        * @since 1.31
+        */
+       public static function emitBufferedStatsdData(
+               IBufferingStatsdDataFactory $stats, Config $config
+       ) {
+               if ( $config->get( 'StatsdServer' ) && $stats->hasData() ) {
+                       try {
+                               $statsdServer = explode( ':', $config->get( 'StatsdServer' ) );
+                               $statsdHost = $statsdServer[0];
+                               $statsdPort = isset( $statsdServer[1] ) ? $statsdServer[1] : 8125;
+                               $statsdSender = new SocketSender( $statsdHost, $statsdPort );
+                               $statsdClient = new SamplingStatsdClient( $statsdSender, true, false );
+                               $statsdClient->setSamplingRates( $config->get( 'StatsdSamplingRates' ) );
+                               $statsdClient->send( $stats->getData() );
+
+                               $stats->clearData(); // empty buffer for the next round
+                       } catch ( Exception $ex ) {
+                               MWExceptionHandler::logException( $ex );
+                       }
+               }
+       }
+
        /**
         * Potentially open a socket and sent an HTTP request back to the server
         * to run a specified number of jobs. This registers a callback to cleanup