MediaWiki master
WikiReference.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\WikiMap;
8
16 private string $mCanonicalServer;
18 private string $mServer;
20 private string $mPath;
21
27 public function __construct( string $canonicalServer, string $path, ?string $server = null ) {
28 $this->mCanonicalServer = $canonicalServer;
29 $this->mPath = $path;
30 $this->mServer = $server ?? $canonicalServer;
31 }
32
38 public function getCanonicalServer() {
39 return $this->mCanonicalServer;
40 }
41
47 public function getDisplayName() {
48 // If the server spec is invalid, there's no sensible thing to do here,
49 // so just return the canonical server as-is.
50 return parse_url( $this->mCanonicalServer, PHP_URL_HOST ) ?: $this->mCanonicalServer;
51 }
52
60 public function getCanonicalUrl( $page, $fragmentId = null ) {
61 return $this->mCanonicalServer . $this->getLocalUrl( $page, $fragmentId );
62 }
63
71 public function getUrl( $page, $fragmentId = null ) {
72 return $this->getCanonicalUrl( $page, $fragmentId );
73 }
74
86 public function getFullUrl( $page, $fragmentId = null ) {
87 return $this->mServer . $this->getLocalUrl( $page, $fragmentId );
88 }
89
100 private function getLocalUrl( $page, $fragmentId = null ) {
101 $page = wfUrlencode( str_replace( ' ', '_', $page ) );
102
103 if ( is_string( $fragmentId ) && $fragmentId !== '' ) {
104 $page .= '#' . wfUrlencode( $fragmentId );
105 }
106
107 return str_replace( '$1', $page, $this->mPath );
108 }
109}
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Reference to a locally-hosted wiki.
getCanonicalServer()
Get the canonical server (i.e.
getDisplayName()
Extract the server name from wgCanonicalServer.
__construct(string $canonicalServer, string $path, ?string $server=null)
getFullUrl( $page, $fragmentId=null)
Create a full URL like Title::getFullURL() to a page, based on $wgServer.
getUrl( $page, $fragmentId=null)
Alias for getCanonicalUrl(), for backwards compatibility.
getCanonicalUrl( $page, $fragmentId=null)
Create a full canonical URL to a page on the given wiki.