From: Aaron Schulz Date: Sat, 22 Jul 2017 02:17:40 +0000 (-0700) Subject: Check headers_sent() before sending cpPosTime headers X-Git-Tag: 1.31.0-rc.0~2635^2 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=6b982c7978b7a9b66855211d36b7901b3c7ca257;p=lhc%2Fweb%2Fwiklou.git Check headers_sent() before sending cpPosTime headers Some entry points stream output and flush their own headers. This avoids "headers already send" warnings in some cases. Change-Id: Ifb232d4575486749bbbccba88f3f688972fe9c20 --- diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 4df4d76f53..4e471844d8 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -609,6 +609,7 @@ class MediaWiki { $lbFactory->hasOrMadeRecentMasterChanges( INF ) ) ? self::getUrlDomainDistance( $output->getRedirect(), $context ) : false; + $allowHeaders = !( $output->isDisabled() || headers_sent() ); if ( $urlDomainDistance === 'local' || $urlDomainDistance === 'remote' ) { // OutputPage::output() will be fast; $postCommitWork will not be useful for // masking the latency of syncing DB positions accross all datacenters synchronously. @@ -616,7 +617,7 @@ class MediaWiki { $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC; $cpPosTime = microtime( true ); // Client's next request should see 1+ positions with this DBMasterPos::asOf() time - if ( $urlDomainDistance === 'local' ) { + if ( $urlDomainDistance === 'local' && $allowHeaders ) { // Client will stay on this domain, so set an unobtrusive cookie $expires = time() + ChronologyProtector::POSITION_TTL; $options = [ 'prefix' => '' ]; @@ -633,7 +634,7 @@ class MediaWiki { // OutputPage::output() is fairly slow; run it in $postCommitWork to mask // the latency of syncing DB positions accross all datacenters synchronously $flags = $lbFactory::SHUTDOWN_CHRONPROT_SYNC; - if ( $lbFactory->hasOrMadeRecentMasterChanges( INF ) ) { + if ( $lbFactory->hasOrMadeRecentMasterChanges( INF ) && $allowHeaders ) { $cpPosTime = microtime( true ); // Set a cookie in case the DB position store cannot sync accross datacenters. // This will at least cover the common case of the user staying on the domain.