MediaWiki  master
WikiReference.php
Go to the documentation of this file.
1 <?php
28  private $mServer;
29  private $mPath;
30 
36  public function __construct( $canonicalServer, $path, $server = null ) {
37  $this->mCanonicalServer = $canonicalServer;
38  $this->mPath = $path;
39  $this->mServer = $server ?? $canonicalServer;
40  }
41 
48  public function getDisplayName() {
49  $parsed = wfParseUrl( $this->mCanonicalServer );
50  if ( $parsed ) {
51  return $parsed['host'];
52  } else {
53  // Invalid server spec.
54  // There's no sane thing to do here, so just return the canonical server name in full.
56  }
57  }
58 
70  private function getLocalUrl( $page, $fragmentId = null ) {
71  $page = wfUrlencode( str_replace( ' ', '_', $page ) );
72 
73  if ( is_string( $fragmentId ) && $fragmentId !== '' ) {
74  $page .= '#' . wfUrlencode( $fragmentId );
75  }
76 
77  return str_replace( '$1', $page, $this->mPath );
78  }
79 
88  public function getCanonicalUrl( $page, $fragmentId = null ) {
89  return $this->mCanonicalServer . $this->getLocalUrl( $page, $fragmentId );
90  }
91 
96  public function getCanonicalServer() {
98  }
99 
107  public function getUrl( $page, $fragmentId = null ) {
108  return $this->getCanonicalUrl( $page, $fragmentId );
109  }
110 
120  public function getFullUrl( $page, $fragmentId = null ) {
121  return $this->mServer .
122  $this->getLocalUrl( $page, $fragmentId );
123  }
124 }
$mServer
server URL, may be protocol-relative, e.g. &#39;//www.mediawiki.org&#39;
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
getCanonicalUrl( $page, $fragmentId=null)
Get a canonical (i.e.
getFullUrl( $page, $fragmentId=null)
Get a URL based on $wgServer, like Title::getFullURL() would produce when called locally on the wiki...
$mCanonicalServer
canonical server URL, e.g. &#39;https://www.mediawiki.org&#39;
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness, which urlencode encodes by default.
Reference to a locally-hosted wiki.
getLocalUrl( $page, $fragmentId=null)
Helper function for getUrl()
__construct( $canonicalServer, $path, $server=null)
getUrl( $page, $fragmentId=null)
Alias for getCanonicalUrl(), for backwards compatibility.
getCanonicalServer()
Get a canonical server URL.
$mPath
path, &#39;/wiki/$1&#39;
getDisplayName()
Get the URL in a way to be displayed to the user More or less Wikimedia specific. ...