41 public static function getWiki( $wikiID ) {
42 $wikiReference = self::getWikiReferenceFromWgConf( $wikiID );
43 if ( $wikiReference ) {
44 return $wikiReference;
48 return self::getWikiWikiReferenceFromSites( $wikiID );
55 private static function getWikiReferenceFromWgConf( $wikiID ) {
60 [ $major, $minor ] =
$wgConf->siteFromDB( $wikiID );
61 if ( $major ===
null ) {
64 $server =
$wgConf->get(
'wgServer', $wikiID, $major,
65 [
'lang' => $minor,
'site' => $major ] );
67 $canonicalServer =
$wgConf->get(
'wgCanonicalServer', $wikiID, $major,
68 [
'lang' => $minor,
'site' => $major ] );
69 if ( $canonicalServer ===
false || $canonicalServer ===
null ) {
70 $canonicalServer = $server;
74 [
'lang' => $minor,
'site' => $major ] );
79 if ( !is_string( $canonicalServer ) || !is_string(
$path ) || strpos(
$path,
'$1' ) ===
false ) {
83 return new WikiReference( $canonicalServer,
$path, $server );
90 private static function getWikiWikiReferenceFromSites( $wikiID ) {
92 $site = $siteLookup->getSite( $wikiID );
100 if ( $urlParts ===
false || !isset( $urlParts[
'path'] ) || !isset( $urlParts[
'host'] ) ) {
106 $path = $urlParts[
'path'];
107 if ( isset( $urlParts[
'query'] ) ) {
108 $path .=
'?' . $urlParts[
'query'];
111 $canonicalServer = $urlParts[
'scheme'] ??
'http';
112 $canonicalServer .=
'://' . $urlParts[
'host'];
114 return new WikiReference( $canonicalServer,
$path );
126 return $wiki ? $wiki->getDisplayName() : $wikiID;
155 if ( $url ===
false ) {
159 return Linker::makeExternalLink( $url, $text );
171 public static function getForeignURL( $wikiID, $page, $fragmentId =
null ) {
175 return $wiki->getFullUrl( $page, $fragmentId );
191 return $cache->getWithSetCallback(
192 $cache->makeGlobalKey(
'wikimap',
'canonical-urls' ),
201 $infoMap[$wikiId] = [
208 if ( $wikiReference ) {
209 $url = $wikiReference->getCanonicalServer();
210 $infoMap[$wikiId] = [
'url' => $url,
'parts' =>
wfParseUrl( $url ) ];
227 if ( strpos( $url,
"$wgCanonicalServer/" ) === 0 ) {
234 if ( $urlPartsCheck ===
false ) {
238 static $relevantKeys = [
'host' => 1,
'port' => 1 ];
239 $urlPartsCheck = array_intersect_key( $urlPartsCheck, $relevantKeys );
241 foreach ( self::getCanonicalServerInfoForAllWikis() as $wikiId => $info ) {
242 $urlParts = $info[
'parts'];
243 if ( $urlParts ===
false ) {
247 $urlParts = array_intersect_key( $urlParts, $relevantKeys );
248 if ( $urlParts == $urlPartsCheck ) {
270 $domain = DatabaseDomain::newFromId( $domain );
276 if ( !in_array( $domain->getSchema(), [
null,
'mediawiki' ],
true ) ) {
280 return "{$domain->getDatabase()}-{$domain->getSchema()}-{$domain->getTablePrefix()}";
284 return strlen( $domain->getTablePrefix() )
285 ?
"{$domain->getDatabase()}-{$domain->getTablePrefix()}"
286 : (string)$domain->getDatabase();
322 return ( self::getCurrentWikiId() === $wikiId );
326class_alias( WikiMap::class,
'WikiMap' );
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
$wgConf
$wgConf hold the site configuration.
Class to handle database/schema/prefix specifications for IDatabase.
$wgDBprefix
Config variable stub for the DBprefix setting, for use by phpdoc and IDEs.
$wgLocalDatabases
Config variable stub for the LocalDatabases setting, for use by phpdoc and IDEs.
$wgDBmwschema
Config variable stub for the DBmwschema setting, for use by phpdoc and IDEs.
$wgDBname
Config variable stub for the DBname setting, for use by phpdoc and IDEs.
$wgCanonicalServer
Config variable stub for the CanonicalServer setting, for use by phpdoc and IDEs.