- 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