MediaWiki
master
Toggle main menu visibility
MediaWikiSite.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\Site;
8
9
use MediaWiki\Title\Title;
10
use RuntimeException;
11
21
class
MediaWikiSite
extends
Site
{
23
public
const
PATH_FILE
=
'file_path'
;
25
public
const
PATH_PAGE
=
'page_path'
;
26
31
public
function
__construct
(
$type
= self::TYPE_MEDIAWIKI ) {
32
parent::__construct(
$type
);
33
}
34
42
public
function
toDBKey
( $title ) {
43
return
str_replace(
' '
,
'_'
, $title );
44
}
45
71
public
function
normalizePageName
( $pageName, $followRedirect =
MediaWikiPageNameNormalizer::FOLLOW_REDIRECT
) {
72
if
( defined(
'MW_PHPUNIT_TEST'
) || defined(
'MW_DEV_ENV'
) ) {
73
// If the code is under test, don't call out to other sites, just
74
// normalize locally.
75
// Note: this may cause results to be inconsistent with the actual
76
// normalization used by the respective remote site!
77
78
$t = Title::newFromText( $pageName );
79
return
$t->getPrefixedText();
80
}
else
{
81
static
$mediaWikiPageNameNormalizer =
null
;
82
$mediaWikiPageNameNormalizer ??=
new
MediaWikiPageNameNormalizer
();
83
84
return
$mediaWikiPageNameNormalizer->normalizePageName(
85
$pageName,
86
$this->
getFileUrl
(
'api.php'
),
87
$followRedirect
88
);
89
}
90
}
91
102
public
function
getLinkPathType
() {
103
return
self::PATH_PAGE;
104
}
105
112
public
function
getRelativePagePath
() {
113
return
parse_url( $this->
getPath
( self::PATH_PAGE ), PHP_URL_PATH );
114
}
115
122
public
function
getRelativeFilePath
() {
123
return
parse_url( $this->
getPath
( self::PATH_FILE ), PHP_URL_PATH );
124
}
125
132
public
function
setPagePath
(
$path
) {
133
$this->
setPath
( self::PATH_PAGE,
$path
);
134
}
135
142
public
function
setFilePath
(
$path
) {
143
$this->
setPath
( self::PATH_FILE,
$path
);
144
}
145
159
public
function
getPageUrl
( $pageName =
false
) {
160
$url
= $this->
getLinkPath
();
161
162
if
(
$url
===
null
) {
163
return
null
;
164
}
165
166
if
( $pageName !==
false
) {
167
$pageName = $this->
toDBKey
( trim( $pageName ) );
168
$url
= str_replace(
'$1'
,
wfUrlencode
( $pageName ),
$url
);
169
}
170
171
return
$url
;
172
}
173
186
public
function
getFileUrl
(
$path
=
false
) {
187
$filePath = $this->
getPath
( self::PATH_FILE );
188
if
( $filePath ===
null
) {
189
throw
new
RuntimeException(
"getFileUrl called for {$this->getGlobalId()} while PATH_FILE is unset"
);
190
}
191
192
if
(
$path
!==
false
) {
193
$filePath = str_replace(
'$1'
,
$path
, $filePath );
194
}
else
{
195
wfDeprecatedMsg
( __METHOD__ .
': omitting $path is deprecated'
,
'1.40'
);
196
}
197
198
return
$filePath;
199
}
200
}
201
203
class_alias( MediaWikiSite::class,
'MediaWikiSite'
);
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition
GlobalFunctions.php:201
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition
GlobalFunctions.php:494
$path
$path
Definition
NoLocalSettings.php:14
MediaWiki\Site\MediaWikiPageNameNormalizer
Service for normalizing a page name via a MediaWiki action API.
Definition
MediaWikiPageNameNormalizer.php:24
MediaWiki\Site\MediaWikiPageNameNormalizer\FOLLOW_REDIRECT
const FOLLOW_REDIRECT
Definition
MediaWikiPageNameNormalizer.php:26
MediaWiki\Site\MediaWikiSite
Class representing a MediaWiki site.
Definition
MediaWikiSite.php:21
MediaWiki\Site\MediaWikiSite\setPagePath
setPagePath( $path)
Set the article path.
Definition
MediaWikiSite.php:132
MediaWiki\Site\MediaWikiSite\getRelativeFilePath
getRelativeFilePath()
Get the script script, as relative path only (without server).
Definition
MediaWikiSite.php:122
MediaWiki\Site\MediaWikiSite\__construct
__construct( $type=self::TYPE_MEDIAWIKI)
Definition
MediaWikiSite.php:31
MediaWiki\Site\MediaWikiSite\normalizePageName
normalizePageName( $pageName, $followRedirect=MediaWikiPageNameNormalizer::FOLLOW_REDIRECT)
Get the normalized form of the given page title.
Definition
MediaWikiSite.php:71
MediaWiki\Site\MediaWikiSite\getLinkPathType
getLinkPathType()
Get the constant for getting or setting the script path.
Definition
MediaWikiSite.php:102
MediaWiki\Site\MediaWikiSite\getRelativePagePath
getRelativePagePath()
Get the article path, as relative path only (without server).
Definition
MediaWikiSite.php:112
MediaWiki\Site\MediaWikiSite\toDBKey
toDBKey( $title)
Get the database form of the given title.
Definition
MediaWikiSite.php:42
MediaWiki\Site\MediaWikiSite\PATH_FILE
const PATH_FILE
The script path of a site, e.g.
Definition
MediaWikiSite.php:23
MediaWiki\Site\MediaWikiSite\setFilePath
setFilePath( $path)
Set the script path.
Definition
MediaWikiSite.php:142
MediaWiki\Site\MediaWikiSite\PATH_PAGE
const PATH_PAGE
The article path of a site, e.g.
Definition
MediaWikiSite.php:25
MediaWiki\Site\MediaWikiSite\getFileUrl
getFileUrl( $path=false)
Get the full URL to an entry point under a wiki's script path.
Definition
MediaWikiSite.php:186
MediaWiki\Site\MediaWikiSite\getPageUrl
getPageUrl( $pageName=false)
Get the full URL for the given page on the site.
Definition
MediaWikiSite.php:159
MediaWiki\Site\Site
Represents a single site.
Definition
Site.php:20
MediaWiki\Site\Site\getLinkPath
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition
Site.php:298
MediaWiki\Site\Site\setPath
setPath( $pathType, string $fullUrl)
Set the path used to construct links with.
Definition
Site.php:546
MediaWiki\Site\Site\$type
string $type
Definition
Site.php:54
MediaWiki\Site\Site\getPath
getPath( $pathType)
Returns the path of the provided type or null if there is no such path.
Definition
Site.php:559
$url
$url
Definition
opensearch_desc.php:25
includes
Site
MediaWikiSite.php
Generated on
for MediaWiki by
1.18.0