39 public static function getWiki( $wikiID ) {
40 $wikiReference = self::getWikiReferenceFromWgConf( $wikiID );
41 if ( $wikiReference ) {
42 return $wikiReference;
46 return self::getWikiWikiReferenceFromSites( $wikiID );
53 private static function getWikiReferenceFromWgConf( $wikiID ) {
55 '@phan-var \MediaWiki\Config\SiteConfiguration $wgConf';
59 [ $major, $minor ] =
$wgConf->siteFromDB( $wikiID );
60 if ( $major ===
null ) {
63 $server =
$wgConf->get(
'wgServer', $wikiID, $major,
64 [
'lang' => $minor,
'site' => $major ] );
66 $canonicalServer =
$wgConf->get(
'wgCanonicalServer', $wikiID, $major,
67 [
'lang' => $minor,
'site' => $major ] );
68 if ( $canonicalServer ===
false || $canonicalServer ===
null ) {
69 $canonicalServer = $server;
73 [
'lang' => $minor,
'site' => $major ] );
78 if ( !is_string( $canonicalServer ) || !is_string(
$path ) || strpos(
$path,
'$1' ) ===
false ) {
82 return new WikiReference( $canonicalServer,
$path, $server );
89 private static function getWikiWikiReferenceFromSites( $wikiID ) {
91 $site = $siteLookup->getSite( $wikiID );
99 if ( $urlParts ===
false || !isset( $urlParts[
'path'] ) || !isset( $urlParts[
'host'] ) ) {
105 $path = $urlParts[
'path'];
106 if ( isset( $urlParts[
'query'] ) ) {
107 $path .=
'?' . $urlParts[
'query'];
110 $canonicalServer = $urlParts[
'scheme'] ??
'http';
111 $canonicalServer .=
'://' . $urlParts[
'host'];
112 if ( isset( $urlParts[
'port'] ) ) {
113 $canonicalServer .=
':' . $urlParts[
'port'];
116 return new WikiReference( $canonicalServer,
$path );
128 return $wiki ? $wiki->getDisplayName() : $wikiID;
157 if ( $url ===
false ) {
161 return Linker::makeExternalLink( $url, $text );
173 public static function getForeignURL( $wikiID, $page, $fragmentId =
null ) {
177 return $wiki->getFullUrl( $page, $fragmentId );
193 return $cache->getWithSetCallback(
194 $cache->makeGlobalKey(
'wikimap-canonical-urls' ),
203 $infoMap[$wikiId] = [
210 if ( $wikiReference ) {
211 $url = $wikiReference->getCanonicalServer();
212 $infoMap[$wikiId] = [
'url' => $url,
'parts' =>
wfParseUrl( $url ) ];
229 if ( strpos( $url,
"$wgCanonicalServer/" ) === 0 ) {
236 if ( $urlPartsCheck ===
false ) {
240 static $relevantKeys = [
'host' => 1,
'port' => 1 ];
241 $urlPartsCheck = array_intersect_key( $urlPartsCheck, $relevantKeys );
243 foreach ( self::getCanonicalServerInfoForAllWikis() as $wikiId => $info ) {
244 $urlParts = $info[
'parts'];
245 if ( $urlParts ===
false ) {
249 $urlParts = array_intersect_key( $urlParts, $relevantKeys );
250 if ( $urlParts == $urlPartsCheck ) {
272 $domain = DatabaseDomain::newFromId( $domain );
278 if ( !in_array( $domain->getSchema(), [
null,
'mediawiki' ],
true ) ) {
282 return "{$domain->getDatabase()}-{$domain->getSchema()}-{$domain->getTablePrefix()}";
286 return strlen( $domain->getTablePrefix() )
287 ?
"{$domain->getDatabase()}-{$domain->getTablePrefix()}"
288 : (string)$domain->getDatabase();
324 return ( self::getCurrentWikiId() === $wikiId );
331class_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.