37 public static function getWiki( $wikiID ) {
38 $wikiReference = self::getWikiReferenceFromWgConf( $wikiID );
39 if ( $wikiReference ) {
40 return $wikiReference;
44 return self::getWikiWikiReferenceFromSites( $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 ) {
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 );
188 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
190 return $cache->getWithSetCallback(
191 $cache->makeGlobalKey(
'wikimap',
'canonical-urls' ),
199 $wikiId = self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() );
200 $infoMap[$wikiId] = [
206 $wikiReference = self::getWiki( $wikiId );
207 if ( $wikiReference ) {
208 $url = $wikiReference->getCanonicalServer();
209 $infoMap[$wikiId] = [
'url' => $url,
'parts' =>
wfParseUrl( $url ) ];
226 if ( strpos( $url,
"$wgCanonicalServer/" ) === 0 ) {
229 return self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() );
233 if ( $urlPartsCheck ===
false ) {
237 static $relevantKeys = [
'host' => 1,
'port' => 1 ];
238 $urlPartsCheck = array_intersect_key( $urlPartsCheck, $relevantKeys );
240 foreach ( self::getCanonicalServerInfoForAllWikis() as $wikiId => $info ) {
241 $urlParts = $info[
'parts'];
242 if ( $urlParts ===
false ) {
246 $urlParts = array_intersect_key( $urlParts, $relevantKeys );
247 if ( $urlParts == $urlPartsCheck ) {
269 $domain = DatabaseDomain::newFromId( $domain );
275 if ( !in_array( $domain->getSchema(), [
null,
'mediawiki' ],
true ) ) {
279 return "{$domain->getDatabase()}-{$domain->getSchema()}-{$domain->getTablePrefix()}";
283 return strlen( $domain->getTablePrefix() )
284 ?
"{$domain->getDatabase()}-{$domain->getTablePrefix()}"
285 : (string)$domain->getDatabase();
304 return self::getCurrentWikiDbDomain()->equals( $domain );
313 return ( self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() ) === $wikiId );
$wgDBprefix
Current wiki database table name prefix.
$wgDBmwschema
Current wiki database schema name.
$wgDBname
Current wiki database name.
$wgConf
wgConf hold the site configuration.
$wgCanonicalServer
Canonical URL of the server, to use in IRC feeds and notification e-mails.
string[] $wgLocalDatabases
Other wikis on this site, can be administered from a single developer account.
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Helper tools for dealing with other locally-hosted wikis.
static getWikiWikiReferenceFromSites( $wikiID)
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 getWikiIdFromDbDomain( $domain)
Get the wiki ID of a database domain.
static getWiki( $wikiID)
Get a WikiReference object for $wikiID.
static isCurrentWikiId( $wikiId)
static getWikiReferenceFromWgConf( $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.