MediaWiki  1.33.0
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 }
WikiReference\__construct
__construct( $canonicalServer, $path, $server=null)
Definition: WikiReference.php:36
WikiReference\getUrl
getUrl( $page, $fragmentId=null)
Alias for getCanonicalUrl(), for backwards compatibility.
Definition: WikiReference.php:107
WikiReference\getFullUrl
getFullUrl( $page, $fragmentId=null)
Get a URL based on $wgServer, like Title::getFullURL() would produce when called locally on the wiki.
Definition: WikiReference.php:120
WikiReference\$mCanonicalServer
$mCanonicalServer
canonical server URL, e.g. 'https://www.mediawiki.org'
Definition: WikiReference.php:27
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:333
WikiReference\$mPath
$mPath
path, '/wiki/$1'
Definition: WikiReference.php:29
WikiReference\getLocalUrl
getLocalUrl( $page, $fragmentId=null)
Helper function for getUrl()
Definition: WikiReference.php:70
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Definition: GlobalFunctions.php:817
WikiReference\getDisplayName
getDisplayName()
Get the URL in a way to be displayed to the user More or less Wikimedia specific.
Definition: WikiReference.php:48
WikiReference\$mServer
$mServer
server URL, may be protocol-relative, e.g. '//www.mediawiki.org'
Definition: WikiReference.php:28
WikiReference\getCanonicalUrl
getCanonicalUrl( $page, $fragmentId=null)
Get a canonical (i.e.
Definition: WikiReference.php:88
WikiReference
Reference to a locally-hosted wiki.
Definition: WikiReference.php:26
$path
$path
Definition: NoLocalSettings.php:25
WikiReference\getCanonicalServer
getCanonicalServer()
Get a canonical server URL.
Definition: WikiReference.php:96