MediaWiki REL1_39
MediaWikiSite.php
Go to the documentation of this file.
1<?php
2
4
38class MediaWikiSite extends Site {
39 public const PATH_FILE = 'file_path';
40 public const PATH_PAGE = 'page_path';
41
47 public function __construct( $type = self::TYPE_MEDIAWIKI ) {
48 parent::__construct( $type );
49 }
50
60 public function toDBKey( $title ) {
61 return str_replace( ' ', '_', $title );
62 }
63
92 public function normalizePageName( $pageName, $followRedirect = MediaWikiPageNameNormalizer::FOLLOW_REDIRECT ) {
93 if ( defined( 'MW_PHPUNIT_TEST' ) || defined( 'MW_DEV_ENV' ) ) {
94 // If the code is under test, don't call out to other sites, just
95 // normalize locally.
96 // Note: this may cause results to be inconsistent with the actual
97 // normalization used by the respective remote site!
98
99 $t = Title::newFromText( $pageName );
100 return $t->getPrefixedText();
101 } else {
102 static $mediaWikiPageNameNormalizer = null;
103
104 if ( $mediaWikiPageNameNormalizer === null ) {
105 $mediaWikiPageNameNormalizer = new MediaWikiPageNameNormalizer();
106 }
107
108 return $mediaWikiPageNameNormalizer->normalizePageName(
109 $pageName,
110 $this->getFileUrl( 'api.php' ),
111 $followRedirect
112 );
113 }
114 }
115
124 public function getLinkPathType() {
125 return self::PATH_PAGE;
126 }
127
135 public function getRelativePagePath() {
136 return parse_url( $this->getPath( self::PATH_PAGE ), PHP_URL_PATH );
137 }
138
146 public function getRelativeFilePath() {
147 return parse_url( $this->getPath( self::PATH_FILE ), PHP_URL_PATH );
148 }
149
157 public function setPagePath( $path ) {
158 $this->setPath( self::PATH_PAGE, $path );
159 }
160
168 public function setFilePath( $path ) {
169 $this->setPath( self::PATH_FILE, $path );
170 }
171
186 public function getPageUrl( $pageName = false ) {
187 $url = $this->getLinkPath();
188
189 if ( $url === null ) {
190 return null;
191 }
192
193 if ( $pageName !== false ) {
194 $pageName = $this->toDBKey( trim( $pageName ) );
195 $url = str_replace( '$1', wfUrlencode( $pageName ), $url );
196 }
197
198 return $url;
199 }
200
212 public function getFileUrl( $path = false ) {
213 $filePath = $this->getPath( self::PATH_FILE );
214
215 if ( $filePath !== false ) {
216 $filePath = str_replace( '$1', $path, $filePath );
217 }
218
219 return $filePath;
220 }
221}
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Class representing a MediaWiki site.
normalizePageName( $pageName, $followRedirect=MediaWikiPageNameNormalizer::FOLLOW_REDIRECT)
Returns the normalized form of the given page title, using the normalization rules of the given site.
getRelativePagePath()
Returns the relative page path.
setFilePath( $path)
Sets the relative file path.
toDBKey( $title)
Returns the database form of the given title.
getFileUrl( $path=false)
Returns the full file path (ie site url + relative file path).
__construct( $type=self::TYPE_MEDIAWIKI)
getPageUrl( $pageName=false)
getRelativeFilePath()
Returns the relative file path.
setPagePath( $path)
Sets the relative page path.
Service for normalizing a page name using a MediaWiki api.
Definition Site.php:33
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition Site.php:605
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition Site.php:626
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition Site.php:344