$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.
$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' => '' ];
// 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.
/**
* @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';
}
/**
- * @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 ) {
}
/**
- * @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
*/