MediaWiki REL1_30
MediaWikiSite.php
Go to the documentation of this file.
1<?php
2
4
38class MediaWikiSite extends Site {
39 const PATH_FILE = 'file_path';
40 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
85 public function normalizePageName( $pageName ) {
86 if ( defined( 'MW_PHPUNIT_TEST' ) ) {
87 // If the code is under test, don't call out to other sites, just
88 // normalize locally.
89 // Note: this may cause results to be inconsistent with the actual
90 // normalization used by the respective remote site!
91
92 $t = Title::newFromText( $pageName );
93 return $t->getPrefixedText();
94 } else {
95 static $mediaWikiPageNameNormalizer = null;
96
97 if ( $mediaWikiPageNameNormalizer === null ) {
98 $mediaWikiPageNameNormalizer = new MediaWikiPageNameNormalizer();
99 }
100
101 return $mediaWikiPageNameNormalizer->normalizePageName(
102 $pageName,
103 $this->getFileUrl( 'api.php' )
104 );
105 }
106 }
107
116 public function getLinkPathType() {
117 return self::PATH_PAGE;
118 }
119
127 public function getRelativePagePath() {
128 return parse_url( $this->getPath( self::PATH_PAGE ), PHP_URL_PATH );
129 }
130
138 public function getRelativeFilePath() {
139 return parse_url( $this->getPath( self::PATH_FILE ), PHP_URL_PATH );
140 }
141
149 public function setPagePath( $path ) {
150 $this->setPath( self::PATH_PAGE, $path );
151 }
152
160 public function setFilePath( $path ) {
161 $this->setPath( self::PATH_FILE, $path );
162 }
163
178 public function getPageUrl( $pageName = false ) {
179 $url = $this->getLinkPath();
180
181 if ( $url === false ) {
182 return false;
183 }
184
185 if ( $pageName !== false ) {
186 $pageName = $this->toDBKey( trim( $pageName ) );
187 $url = str_replace( '$1', wfUrlencode( $pageName ), $url );
188 }
189
190 return $url;
191 }
192
204 public function getFileUrl( $path = false ) {
205 $filePath = $this->getPath( self::PATH_FILE );
206
207 if ( $filePath !== false ) {
208 $filePath = str_replace( '$1', $path, $filePath );
209 }
210
211 return $filePath;
212 }
213}
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Class representing a MediaWiki 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).
normalizePageName( $pageName)
Returns the normalized form of the given page title, using the normalization rules of the given site.
__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:29
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition Site.php:586
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition Site.php:607
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition Site.php:334