MediaWiki  1.29.2
MediaWikiSite.php
Go to the documentation of this file.
1 <?php
2 
4 
38 class MediaWikiSite extends Site {
39  const PATH_FILE = 'file_path';
40  const PATH_PAGE = 'page_path';
41 
49  public function __construct( $type = self::TYPE_MEDIAWIKI ) {
50  parent::__construct( $type );
51  }
52 
62  public function toDBKey( $title ) {
63  return str_replace( ' ', '_', $title );
64  }
65 
87  public function normalizePageName( $pageName ) {
88  if ( defined( 'MW_PHPUNIT_TEST' ) ) {
89  // If the code is under test, don't call out to other sites, just
90  // normalize locally.
91  // Note: this may cause results to be inconsistent with the actual
92  // normalization used by the respective remote site!
93 
94  $t = Title::newFromText( $pageName );
95  return $t->getPrefixedText();
96  } else {
97  static $mediaWikiPageNameNormalizer = null;
98 
99  if ( $mediaWikiPageNameNormalizer === null ) {
100  $mediaWikiPageNameNormalizer = new MediaWikiPageNameNormalizer();
101  }
102 
103  return $mediaWikiPageNameNormalizer->normalizePageName(
104  $pageName,
105  $this->getFileUrl( 'api.php' )
106  );
107  }
108  }
109 
118  public function getLinkPathType() {
119  return self::PATH_PAGE;
120  }
121 
129  public function getRelativePagePath() {
130  return parse_url( $this->getPath( self::PATH_PAGE ), PHP_URL_PATH );
131  }
132 
140  public function getRelativeFilePath() {
141  return parse_url( $this->getPath( self::PATH_FILE ), PHP_URL_PATH );
142  }
143 
151  public function setPagePath( $path ) {
152  $this->setPath( self::PATH_PAGE, $path );
153  }
154 
162  public function setFilePath( $path ) {
163  $this->setPath( self::PATH_FILE, $path );
164  }
165 
180  public function getPageUrl( $pageName = false ) {
181  $url = $this->getLinkPath();
182 
183  if ( $url === false ) {
184  return false;
185  }
186 
187  if ( $pageName !== false ) {
188  $pageName = $this->toDBKey( trim( $pageName ) );
189  $url = str_replace( '$1', wfUrlencode( $pageName ), $url );
190  }
191 
192  return $url;
193  }
194 
206  public function getFileUrl( $path = false ) {
207  $filePath = $this->getPath( self::PATH_FILE );
208 
209  if ( $filePath !== false ) {
210  $filePath = str_replace( '$1', $path, $filePath );
211  }
212 
213  return $filePath;
214  }
215 }
MediaWikiSite\toDBKey
toDBKey( $title)
Returns the database form of the given title.
Definition: MediaWikiSite.php:62
MediaWikiSite\getFileUrl
getFileUrl( $path=false)
Returns the full file path (ie site url + relative file path).
Definition: MediaWikiSite.php:206
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:265
MediaWikiSite\getRelativeFilePath
getRelativeFilePath()
Returns the relative file path.
Definition: MediaWikiSite.php:140
MediaWikiSite\getRelativePagePath
getRelativePagePath()
Returns the relative page path.
Definition: MediaWikiSite.php:129
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:371
Site\getPath
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition: Site.php:609
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
Site\$type
string $type
Definition: Site.php:63
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
MediaWikiSite\setPagePath
setPagePath( $path)
Sets the relative page path.
Definition: MediaWikiSite.php:151
MediaWikiSite\getLinkPathType
getLinkPathType()
Definition: MediaWikiSite.php:118
MediaWikiSite\setFilePath
setFilePath( $path)
Sets the relative file path.
Definition: MediaWikiSite.php:162
MediaWikiSite\PATH_FILE
const PATH_FILE
Definition: MediaWikiSite.php:39
Site
Definition: Site.php:29
MediaWiki\Site\MediaWikiPageNameNormalizer
Service for normalizing a page name using a MediaWiki api.
Definition: MediaWikiPageNameNormalizer.php:35
Site\setPath
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition: Site.php:588
MediaWikiSite\__construct
__construct( $type=self::TYPE_MEDIAWIKI)
Constructor.
Definition: MediaWikiSite.php:49
MediaWikiSite\getPageUrl
getPageUrl( $pageName=false)
Definition: MediaWikiSite.php:180
MediaWikiSite\PATH_PAGE
const PATH_PAGE
Definition: MediaWikiSite.php:40
MediaWikiSite\normalizePageName
normalizePageName( $pageName)
Returns the normalized form of the given page title, using the normalization rules of the given site.
Definition: MediaWikiSite.php:87
$path
$path
Definition: NoLocalSettings.php:26
MediaWikiSite
Class representing a MediaWiki site.
Definition: MediaWikiSite.php:38
$t
$t
Definition: testCompression.php:67
Site\getLinkPath
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition: Site.php:336