37 public static function getWiki( $wikiID ) {
38 $wikiReference = self::getWikiReferenceFromWgConf( $wikiID );
39 if ( $wikiReference ) {
40 return $wikiReference;
44 return self::getWikiWikiReferenceFromSites( $wikiID );
51 private static function getWikiReferenceFromWgConf( $wikiID ) {
56 list( $major, $minor ) =
$wgConf->siteFromDB( $wikiID );
57 if ( $major ===
null ) {
60 $server =
$wgConf->get(
'wgServer', $wikiID, $major,
61 [
'lang' => $minor,
'site' => $major ] );
63 $canonicalServer =
$wgConf->get(
'wgCanonicalServer', $wikiID, $major,
64 [
'lang' => $minor,
'site' => $major ] );
65 if ( $canonicalServer ===
false || $canonicalServer ===
null ) {
66 $canonicalServer = $server;
70 [
'lang' => $minor,
'site' => $major ] );
75 if ( !is_string( $canonicalServer ) || !is_string(
$path ) || strpos(
$path,
'$1' ) ===
false ) {
86 private static function getWikiWikiReferenceFromSites( $wikiID ) {
87 $siteLookup = MediaWikiServices::getInstance()->getSiteLookup();
88 $site = $siteLookup->getSite( $wikiID );
96 if ( $urlParts ===
false || !isset( $urlParts[
'path'] ) || !isset( $urlParts[
'host'] ) ) {
102 $path = $urlParts[
'path'];
103 if ( isset( $urlParts[
'query'] ) ) {
104 $path .=
'?' . $urlParts[
'query'];
107 $canonicalServer = $urlParts[
'scheme'] ??
'http';
108 $canonicalServer .=
'://' . $urlParts[
'host'];
121 $wiki = self::getWiki( $wikiID );
124 return $wiki->getDisplayName();
138 return self::makeForeignLink( $wikiID,
"User:$user", $text );
154 $url = self::getForeignURL( $wikiID, $page );
155 if ( $url ===
false ) {
171 public static function getForeignURL( $wikiID, $page, $fragmentId =
null ) {
172 $wiki = self::getWiki( $wikiID );
175 return $wiki->getFullUrl( $page, $fragmentId );
189 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
191 return $cache->getWithSetCallback(
192 $cache->makeGlobalKey(
'wikimap',
'canonical-urls' ),
200 $wikiId = self::getCurrentWikiId();
201 $infoMap[$wikiId] = [
207 $wikiReference = self::getWiki( $wikiId );
208 if ( $wikiReference ) {
209 $url = $wikiReference->getCanonicalServer();
210 $infoMap[$wikiId] = [
'url' => $url,
'parts' =>
wfParseUrl( $url ) ];
227 if ( strpos( $url,
"$wgCanonicalServer/" ) === 0 ) {
230 return self::getCurrentWikiId();
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();
304 return self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() );
313 return self::getCurrentWikiDbDomain()->equals( $domain );
322 return ( self::getCurrentWikiId() === $wikiId );
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
$wgConf
$wgConf hold the site configuration.
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Helper tools for dealing with other locally-hosted wikis.
static makeForeignLink( $wikiID, $page, $text=null)
Convenience to get a link to a page on a foreign wiki.
static getCanonicalServerInfoForAllWikis()
Get canonical server info for all local wikis in the map that have one.
static getCurrentWikiId()
static getWikiIdFromDbDomain( $domain)
Get the wiki ID of a database domain.
static getWiki( $wikiID)
Get a WikiReference object for $wikiID.
static isCurrentWikiId( $wikiId)
static getWikiName( $wikiID)
Convenience to get the wiki's display name.
static getCurrentWikiDbDomain()
static foreignUserLink( $wikiID, $user, $text=null)
Convenience to get a link to a user page on a foreign wiki.
static getWikiFromUrl( $url)
static getForeignURL( $wikiID, $page, $fragmentId=null)
Convenience to get a url to a page on a foreign wiki.
static isCurrentWikiDbDomain( $domain)
Reference to a locally-hosted wiki.
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.