MediaWiki REL1_40
MediaWikiSite.php
Go to the documentation of this file.
1<?php
23
33class MediaWikiSite extends Site {
35 public const PATH_FILE = 'file_path';
37 public const PATH_PAGE = 'page_path';
38
43 public function __construct( $type = self::TYPE_MEDIAWIKI ) {
44 parent::__construct( $type );
45 }
46
54 public function toDBKey( $title ) {
55 return str_replace( ' ', '_', $title );
56 }
57
83 public function normalizePageName( $pageName, $followRedirect = MediaWikiPageNameNormalizer::FOLLOW_REDIRECT ) {
84 if ( defined( 'MW_PHPUNIT_TEST' ) || defined( 'MW_DEV_ENV' ) ) {
85 // If the code is under test, don't call out to other sites, just
86 // normalize locally.
87 // Note: this may cause results to be inconsistent with the actual
88 // normalization used by the respective remote site!
89
90 $t = Title::newFromText( $pageName );
91 return $t->getPrefixedText();
92 } else {
93 static $mediaWikiPageNameNormalizer = null;
94
95 if ( $mediaWikiPageNameNormalizer === null ) {
96 $mediaWikiPageNameNormalizer = new MediaWikiPageNameNormalizer();
97 }
98
99 return $mediaWikiPageNameNormalizer->normalizePageName(
100 $pageName,
101 $this->getFileUrl( 'api.php' ),
102 $followRedirect
103 );
104 }
105 }
106
117 public function getLinkPathType() {
118 return self::PATH_PAGE;
119 }
120
127 public function getRelativePagePath() {
128 return parse_url( $this->getPath( self::PATH_PAGE ), PHP_URL_PATH );
129 }
130
137 public function getRelativeFilePath() {
138 return parse_url( $this->getPath( self::PATH_FILE ), PHP_URL_PATH );
139 }
140
147 public function setPagePath( $path ) {
148 $this->setPath( self::PATH_PAGE, $path );
149 }
150
157 public function setFilePath( $path ) {
158 $this->setPath( self::PATH_FILE, $path );
159 }
160
174 public function getPageUrl( $pageName = false ) {
175 $url = $this->getLinkPath();
176
177 if ( $url === null ) {
178 return null;
179 }
180
181 if ( $pageName !== false ) {
182 $pageName = $this->toDBKey( trim( $pageName ) );
183 $url = str_replace( '$1', wfUrlencode( $pageName ), $url );
184 }
185
186 return $url;
187 }
188
201 public function getFileUrl( $path = false ) {
202 $filePath = $this->getPath( self::PATH_FILE );
203 if ( $filePath === null ) {
204 throw new RuntimeException( "getFileUrl called for {$this->getGlobalId()} while PATH_FILE is unset" );
205 }
206
207 if ( $path !== false ) {
208 $filePath = str_replace( '$1', $path, $filePath );
209 } else {
210 wfDeprecatedMsg( __METHOD__ . ': omitting $path is deprecated', '1.40' );
211 }
212
213 return $filePath;
214 }
215}
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Class representing a MediaWiki site.
const PATH_FILE
The script path of a site, e.g.
normalizePageName( $pageName, $followRedirect=MediaWikiPageNameNormalizer::FOLLOW_REDIRECT)
Get the normalized form of the given page title.
getRelativePagePath()
Get the article path, as relative path only (without server).
setFilePath( $path)
Set the script path.
getLinkPathType()
Get the constant for getting or setting the script path.
toDBKey( $title)
Get the database form of the given title.
getFileUrl( $path=false)
Get the full URL to an entry point under a wiki's script path.
__construct( $type=self::TYPE_MEDIAWIKI)
getPageUrl( $pageName=false)
Get the full URL for the given page on the site.
getRelativeFilePath()
Get the script script, as relative path only (without server).
setPagePath( $path)
Set the article path.
const PATH_PAGE
The article path of a site, e.g.
Service for normalizing a page name via a MediaWiki action API.
Represents a title within MediaWiki.
Definition Title.php:82
Represents a single site.
Definition Site.php:32
getPath( $pathType)
Returns the path of the provided type or null if there is no such path.
Definition Site.php:586
setPath( $pathType, string $fullUrl)
Set the path used to construct links with.
Definition Site.php:569
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition Site.php:311