X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMediaWiki.php;h=7b59ee93dc164cae96cfd7568eb62f2d39ee307a;hb=f629d095f0469dc9fa29143a8efdc498ee634730;hp=4df4d76f5366cc7a7ace050219771d167f6d822a;hpb=68e16c26dd58afdf58a97f18f3cc76ed3b0ad9ee;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 4df4d76f53..7b59ee93dc 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -607,8 +607,9 @@ class MediaWiki { $request->wasPosted() && $output->getRedirect() && $lbFactory->hasOrMadeRecentMasterChanges( INF ) - ) ? self::getUrlDomainDistance( $output->getRedirect(), $context ) : false; + ) ? self::getUrlDomainDistance( $output->getRedirect() ) : 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. @@ -675,34 +676,14 @@ class MediaWiki { /** * @param string $url - * @param IContextSource $context * @return string Either "local", "remote" if in the farm, "external" otherwise */ - private static function getUrlDomainDistance( $url, IContextSource $context ) { - static $relevantKeys = [ 'host' => true, 'port' => true ]; - - $infoCandidate = wfParseUrl( $url ); - if ( $infoCandidate === false ) { - return 'external'; - } - - $infoCandidate = array_intersect_key( $infoCandidate, $relevantKeys ); - $clusterHosts = array_merge( - // Local wiki host (the most common case) - [ $context->getConfig()->get( 'CanonicalServer' ) ], - // Any local/remote wiki virtual hosts for this wiki farm - $context->getConfig()->get( 'LocalVirtualHosts' ) - ); - - foreach ( $clusterHosts as $i => $clusterHost ) { - $parseUrl = wfParseUrl( $clusterHost ); - if ( !$parseUrl ) { - continue; - } - $infoHost = array_intersect_key( $parseUrl, $relevantKeys ); - if ( $infoCandidate === $infoHost ) { - return ( $i === 0 ) ? 'local' : 'remote'; - } + private static function getUrlDomainDistance( $url ) { + $clusterWiki = WikiMap::getWikiFromUrl( $url ); + if ( $clusterWiki === wfWikiID() ) { + return 'local'; // the current wiki + } elseif ( $clusterWiki !== false ) { + return 'remote'; // another wiki in this cluster/farm } return 'external'; @@ -969,7 +950,7 @@ class MediaWiki { } /** - * @param integer $n Number of jobs to try to run + * @param int $n Number of jobs to try to run * @param LoggerInterface $runJobsLogger */ private function triggerSyncJobs( $n, LoggerInterface $runJobsLogger ) { @@ -978,7 +959,7 @@ class MediaWiki { } /** - * @param integer $n Number of jobs to try to run + * @param int $n Number of jobs to try to run * @param LoggerInterface $runJobsLogger * @return bool Success */