X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FWikiMap.php;h=23b0e3edb20cd0e3edeeb010a54d40ddbd1b7138;hp=8b000f2063b283aef4b28664211f498c9b922ff1;hb=616525021b3691e30a980a42b837b7ad44ecfd09;hpb=b306873222f91789e334abcf2005d4b610cfce91 diff --git a/includes/WikiMap.php b/includes/WikiMap.php index 8b000f2063..23b0e3edb2 100644 --- a/includes/WikiMap.php +++ b/includes/WikiMap.php @@ -221,19 +221,29 @@ class WikiMap { * @since 1.30 */ public static function getWikiFromUrl( $url ) { + global $wgCanonicalServer; + + if ( strpos( $url, "$wgCanonicalServer/" ) === 0 ) { + // Optimisation: Handle the the common case. + // (Duplicates self::getCanonicalServerInfoForAllWikis) + return self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() ); + } + $urlPartsCheck = wfParseUrl( $url ); if ( $urlPartsCheck === false ) { return false; } - $urlPartsCheck = array_intersect_key( $urlPartsCheck, [ 'host' => 1, 'port' => 1 ] ); + static $relevantKeys = [ 'host' => 1, 'port' => 1 ]; + $urlPartsCheck = array_intersect_key( $urlPartsCheck, $relevantKeys ); + foreach ( self::getCanonicalServerInfoForAllWikis() as $wikiId => $info ) { $urlParts = $info['parts']; if ( $urlParts === false ) { continue; // sanity } - $urlParts = array_intersect_key( $urlParts, [ 'host' => 1, 'port' => 1 ] ); + $urlParts = array_intersect_key( $urlParts, $relevantKeys ); if ( $urlParts == $urlPartsCheck ) { return $wikiId; }