MediaWiki  1.23.13
WikiMap.php
Go to the documentation of this file.
1 <?php
26 class WikiMap {
27 
34  public static function getWiki( $wikiID ) {
35  global $wgConf;
36 
37  $wgConf->loadFullData();
38 
39  list( $major, $minor ) = $wgConf->siteFromDB( $wikiID );
40  if ( $major === null ) {
41  return null;
42  }
43  $server = $wgConf->get( 'wgServer', $wikiID, $major,
44  array( 'lang' => $minor, 'site' => $major ) );
45 
46  $canonicalServer = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
47  array( 'lang' => $minor, 'site' => $major ) );
48  if ( $canonicalServer === false || $canonicalServer === null ) {
49  $canonicalServer = $server;
50  }
51 
52  $path = $wgConf->get( 'wgArticlePath', $wikiID, $major,
53  array( 'lang' => $minor, 'site' => $major ) );
54  return new WikiReference( $major, $minor, $canonicalServer, $path, $server );
55  }
56 
64  public static function getWikiName( $wikiID ) {
65  $wiki = WikiMap::getWiki( $wikiID );
66 
67  if ( $wiki ) {
68  return $wiki->getDisplayName();
69  }
70  return $wikiID;
71  }
72 
81  public static function foreignUserLink( $wikiID, $user, $text = null ) {
82  return self::makeForeignLink( $wikiID, "User:$user", $text );
83  }
84 
93  public static function makeForeignLink( $wikiID, $page, $text = null ) {
94  if ( !$text ) {
95  $text = $page;
96  }
97 
98  $url = self::getForeignURL( $wikiID, $page );
99  if ( $url === false ) {
100  return false;
101  }
102 
103  return Linker::makeExternalLink( $url, $text );
104  }
105 
113  public static function getForeignURL( $wikiID, $page ) {
114  $wiki = WikiMap::getWiki( $wikiID );
115 
116  if ( $wiki ) {
117  return $wiki->getFullUrl( $page );
118  }
119 
120  return false;
121  }
122 }
123 
128  private $mMinor;
129  private $mMajor;
131  private $mServer;
132  private $mPath;
133 
141  public function __construct( $major, $minor, $canonicalServer, $path, $server = null ) {
142  $this->mMajor = $major;
143  $this->mMinor = $minor;
144  $this->mCanonicalServer = $canonicalServer;
145  $this->mPath = $path;
146  $this->mServer = $server === null ? $canonicalServer : $server;
147  }
148 
153  public function getHostname() {
154  $prefixes = array( 'http://', 'https://' );
155  foreach ( $prefixes as $prefix ) {
156  if ( substr( $this->mCanonicalServer, 0, strlen( $prefix ) ) ) {
157  return substr( $this->mCanonicalServer, strlen( $prefix ) );
158  }
159  }
160  throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
161  }
162 
169  public function getDisplayName() {
170  $url = $this->getUrl( '' );
171  $parsed = wfParseUrl( $url );
172  if ( $parsed ) {
173  return $parsed['host'];
174  } else {
175  // Invalid URL. There's no sane thing to do here, so just return it
176  return $url;
177  }
178  }
179 
187  private function getLocalUrl( $page ) {
188  return str_replace( '$1', wfUrlEncode( str_replace( ' ', '_', $page ) ), $this->mPath );
189  }
190 
197  public function getCanonicalUrl( $page ) {
198  return $this->mCanonicalServer . $this->getLocalUrl( $page );
199  }
200 
205  public function getCanonicalServer() {
207  }
208 
214  public function getUrl( $page ) {
215  return $this->getCanonicalUrl( $page );
216  }
217 
225  public function getFullUrl( $page ) {
226  return $this->mServer .
227  $this->getLocalUrl( $page );
228  }
229 }
WikiMap\foreignUserLink
static foreignUserLink( $wikiID, $user, $text=null)
Convenience to get a link to a user page on a foreign wiki.
Definition: WikiMap.php:81
WikiReference\$mCanonicalServer
$mCanonicalServer
canonical server URL, e.g. 'https://www.mediawiki.org'
Definition: WikiMap.php:130
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
WikiMap\getForeignURL
static getForeignURL( $wikiID, $page)
Convenience to get a url to a page on a foreign wiki.
Definition: WikiMap.php:113
WikiReference\getUrl
getUrl( $page)
Alias for getCanonicalUrl(), for backwards compatibility.
Definition: WikiMap.php:214
WikiReference\$mPath
$mPath
path, '/wiki/$1'
Definition: WikiMap.php:132
Linker\makeExternalLink
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=array(), $title=null)
Make an external link.
Definition: Linker.php:1034
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Definition: GlobalFunctions.php:802
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiReference\getDisplayName
getDisplayName()
Get the the URL in a way to de displayed to the user More or less Wikimedia specific.
Definition: WikiMap.php:169
WikiReference\getHostname
getHostname()
Definition: WikiMap.php:153
WikiMap\getWiki
static getWiki( $wikiID)
Get a WikiReference object for $wikiID.
Definition: WikiMap.php:34
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
WikiReference\$mServer
$mServer
server URL, may be protocol-relative, e.g. '//www.mediawiki.org'
Definition: WikiMap.php:131
WikiReference\getCanonicalUrl
getCanonicalUrl( $page)
Get a canonical (i.e.
Definition: WikiMap.php:197
WikiMap\makeForeignLink
static makeForeignLink( $wikiID, $page, $text=null)
Convenience to get a link to a page on a foreign wiki.
Definition: WikiMap.php:93
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
WikiMap
Helper tools for dealing with other locally-hosted wikis.
Definition: WikiMap.php:26
WikiReference
Reference to a locally-hosted wiki.
Definition: WikiMap.php:127
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
WikiReference\getLocalUrl
getLocalUrl( $page)
Helper function for getUrl()
Definition: WikiMap.php:187
WikiReference\getFullUrl
getFullUrl( $page)
Get a URL based on $wgServer, like Title::getFullURL() would produce when called locally on the wiki.
Definition: WikiMap.php:225
WikiReference\getCanonicalServer
getCanonicalServer()
Get a canonical server URL.
Definition: WikiMap.php:205
WikiMap\getWikiName
static getWikiName( $wikiID)
Convenience to get the wiki's display name.
Definition: WikiMap.php:64
WikiReference\$mMajor
$mMajor
'wiki', 'wiktionary', etc
Definition: WikiMap.php:129
WikiReference\$mMinor
$mMinor
'en', 'meta', 'mediawiki', etc
Definition: WikiMap.php:128
WikiReference\__construct
__construct( $major, $minor, $canonicalServer, $path, $server=null)
Definition: WikiMap.php:141