MediaWiki master
WikiReference.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\WikiMap;
22
30 private string $mCanonicalServer;
32 private string $mServer;
34 private string $mPath;
35
41 public function __construct( string $canonicalServer, string $path, ?string $server = null ) {
42 $this->mCanonicalServer = $canonicalServer;
43 $this->mPath = $path;
44 $this->mServer = $server ?? $canonicalServer;
45 }
46
52 public function getCanonicalServer() {
53 return $this->mCanonicalServer;
54 }
55
61 public function getDisplayName() {
62 // If the server spec is invalid, there's no sensible thing to do here,
63 // so just return the canonical server as-is.
64 return parse_url( $this->mCanonicalServer, PHP_URL_HOST ) ?: $this->mCanonicalServer;
65 }
66
74 public function getCanonicalUrl( $page, $fragmentId = null ) {
75 return $this->mCanonicalServer . $this->getLocalUrl( $page, $fragmentId );
76 }
77
85 public function getUrl( $page, $fragmentId = null ) {
86 return $this->getCanonicalUrl( $page, $fragmentId );
87 }
88
100 public function getFullUrl( $page, $fragmentId = null ) {
101 return $this->mServer . $this->getLocalUrl( $page, $fragmentId );
102 }
103
114 private function getLocalUrl( $page, $fragmentId = null ) {
115 $page = wfUrlencode( str_replace( ' ', '_', $page ) );
116
117 if ( is_string( $fragmentId ) && $fragmentId !== '' ) {
118 $page .= '#' . wfUrlencode( $fragmentId );
119 }
120
121 return str_replace( '$1', $page, $this->mPath );
122 }
123}
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.