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 );
93 if ( !$site instanceof MediaWikiSite ) {
99 if ( $urlParts ===
null || !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;
159 if (
$url ===
false ) {
164 return $linkRenderer->makeExternalLink(
180 public static function getForeignURL( $wikiID, $page, $fragmentId =
null ) {
184 return $wiki->getFullUrl( $page, $fragmentId );
200 return $cache->getWithSetCallback(
201 $cache->makeGlobalKey(
'wikimap-canonical-urls' ),
210 $infoMap[$wikiId] = [
217 if ( $wikiReference ) {
218 $url = $wikiReference->getCanonicalServer();
236 if ( strpos(
$url,
"$wgCanonicalServer/" ) === 0 ) {
243 if ( $urlPartsCheck ===
null ) {
247 static $relevantKeys = [
'host' => 1,
'port' => 1 ];
248 $urlPartsCheck = array_intersect_key( $urlPartsCheck, $relevantKeys );
250 foreach ( self::getCanonicalServerInfoForAllWikis() as $wikiId => $info ) {
251 $urlParts = $info[
'parts'];
252 if ( $urlParts ===
false ) {
256 $urlParts = array_intersect_key( $urlParts, $relevantKeys );
257 if ( $urlParts == $urlPartsCheck ) {
279 $domain = DatabaseDomain::newFromId( $domain );
285 if ( !in_array( $domain->getSchema(), [
null,
'mediawiki' ],
true ) ) {
289 return "{$domain->getDatabase()}-{$domain->getSchema()}-{$domain->getTablePrefix()}";
293 return strlen( $domain->getTablePrefix() )
294 ?
"{$domain->getDatabase()}-{$domain->getTablePrefix()}"
295 : (string)$domain->getDatabase();
331 return ( self::getCurrentWikiId() === $wikiId );
336class_alias( WikiMap::class,
'WikiMap' );
$wgConf
$wgConf hold the site configuration.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgTitle
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
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.