MediaWiki  master
WikiReference.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\WikiMap;
24 
29  private $mCanonicalServer;
30  private $mServer;
31  private $mPath;
32 
38  public function __construct( $canonicalServer, $path, $server = null ) {
39  $this->mCanonicalServer = $canonicalServer;
40  $this->mPath = $path;
41  $this->mServer = $server ?? $canonicalServer;
42  }
43 
50  public function getDisplayName() {
51  $parsed = wfParseUrl( $this->mCanonicalServer );
52  if ( $parsed ) {
53  return $parsed['host'];
54  } else {
55  // Invalid server spec.
56  // There's no sensible thing to do here, so just return the canonical server name in full.
57  return $this->mCanonicalServer;
58  }
59  }
60 
72  private function getLocalUrl( $page, $fragmentId = null ) {
73  $page = wfUrlencode( str_replace( ' ', '_', $page ) );
74 
75  if ( is_string( $fragmentId ) && $fragmentId !== '' ) {
76  $page .= '#' . wfUrlencode( $fragmentId );
77  }
78 
79  return str_replace( '$1', $page, $this->mPath );
80  }
81 
90  public function getCanonicalUrl( $page, $fragmentId = null ) {
91  return $this->mCanonicalServer . $this->getLocalUrl( $page, $fragmentId );
92  }
93 
98  public function getCanonicalServer() {
99  return $this->mCanonicalServer;
100  }
101 
109  public function getUrl( $page, $fragmentId = null ) {
110  return $this->getCanonicalUrl( $page, $fragmentId );
111  }
112 
122  public function getFullUrl( $page, $fragmentId = null ) {
123  return $this->mServer . $this->getLocalUrl( $page, $fragmentId );
124  }
125 }
126 
127 class_alias( WikiReference::class, 'WikiReference' );
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Reference to a locally-hosted wiki.
getCanonicalServer()
Get a canonical server URL.
getDisplayName()
Get the URL in a way to be displayed to the user More or less Wikimedia specific.
getFullUrl( $page, $fragmentId=null)
Get a URL based on $wgServer, like Title::getFullURL() would produce when called locally on the wiki.
getUrl( $page, $fragmentId=null)
Alias for getCanonicalUrl(), for backwards compatibility.
getCanonicalUrl( $page, $fragmentId=null)
Get a canonical (i.e.
__construct( $canonicalServer, $path, $server=null)