MediaWiki master
WikiReference.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\WikiMap;
24
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
53 public function getDisplayName() {
54 $host = parse_url( $this->mCanonicalServer, PHP_URL_HOST );
55 if ( $host ) {
56 return $host;
57 } else {
58 // Invalid server spec.
59 // There's no sensible thing to do here, so just return the canonical server name in full.
60 return $this->mCanonicalServer;
61 }
62 }
63
75 private function getLocalUrl( $page, $fragmentId = null ) {
76 $page = wfUrlencode( str_replace( ' ', '_', $page ) );
77
78 if ( is_string( $fragmentId ) && $fragmentId !== '' ) {
79 $page .= '#' . wfUrlencode( $fragmentId );
80 }
81
82 return str_replace( '$1', $page, $this->mPath );
83 }
84
93 public function getCanonicalUrl( $page, $fragmentId = null ) {
94 return $this->mCanonicalServer . $this->getLocalUrl( $page, $fragmentId );
95 }
96
101 public function getCanonicalServer() {
102 return $this->mCanonicalServer;
103 }
104
112 public function getUrl( $page, $fragmentId = null ) {
113 return $this->getCanonicalUrl( $page, $fragmentId );
114 }
115
125 public function getFullUrl( $page, $fragmentId = null ) {
126 return $this->mServer . $this->getLocalUrl( $page, $fragmentId );
127 }
128}
129
131class_alias( WikiReference::class, 'WikiReference' );
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 a canonical server URL.
getDisplayName()
Get the URL in a way to be displayed to the user More or less Wikimedia specific.
__construct(string $canonicalServer, string $path, ?string $server=null)
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.