MediaWiki
1.34.0
SpecialMyLanguage.php
Go to the documentation of this file.
1
<?php
26
use
MediaWiki\MediaWikiServices
;
27
37
class
SpecialMyLanguage
extends
RedirectSpecialArticle
{
38
public
function
__construct
() {
39
parent::__construct(
'MyLanguage'
);
40
}
41
49
public
function
getRedirect
( $subpage ) {
50
$title
= $this->
findTitle
( $subpage );
51
// Go to the main page if given invalid title.
52
if
( !
$title
) {
53
$title
=
Title::newMainPage
();
54
}
55
return
$title
;
56
}
57
67
public
function
findTitle
( $subpage ) {
68
// base = title without language code suffix
69
// provided = the title as it was given
70
$base
= $provided =
null
;
71
if
( $subpage !==
null
) {
72
$provided =
Title::newFromText
( $subpage );
73
$base
= $provided;
74
75
if
( $provided && strpos( $subpage,
'/'
) !==
false
) {
76
$pos = strrpos( $subpage,
'/'
);
77
$basepage = substr( $subpage, 0, $pos );
78
$code = substr( $subpage, $pos + 1 );
79
if
( strlen( $code ) &&
Language::isKnownLanguageTag
( $code ) ) {
80
$base
=
Title::newFromText
( $basepage );
81
}
82
}
83
}
84
85
if
( !
$base
) {
86
// No subpage provided or base page does not exist
87
return
null
;
88
}
89
90
if
(
$base
->isRedirect() ) {
91
$page =
new
WikiPage
(
$base
);
92
$base
= $page->getRedirectTarget();
93
}
94
95
$uiLang = $this->
getLanguage
();
96
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
97
98
if
( $uiLang->equals( $contLang ) ) {
99
// Short circuit when the current UI language is the
100
// wiki's default language to avoid unnecessary page lookups.
101
return
$base
;
102
}
103
104
// Check for a subpage in current UI language
105
$proposed =
$base
->getSubpage( $uiLang->getCode() );
106
if
( $proposed && $proposed->exists() ) {
107
return
$proposed;
108
}
109
110
if
( $provided !==
$base
&& $provided->exists() ) {
111
// Explicit language code given and the page exists
112
return
$provided;
113
}
114
115
// Check for fallback languages specified by the UI language
116
$possibilities = $uiLang->getFallbackLanguages();
117
foreach
( $possibilities as
$lang
) {
118
if
(
$lang
!== $contLang->getCode() ) {
119
$proposed =
$base
->getSubpage(
$lang
);
120
if
( $proposed && $proposed->exists() ) {
121
return
$proposed;
122
}
123
}
124
}
125
126
// When all else has failed, return the base page
127
return
$base
;
128
}
129
137
public
function
personallyIdentifiableTarget
() {
138
return
true
;
139
}
140
}
SpecialMyLanguage\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
Definition:
SpecialMyLanguage.php:49
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:316
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition:
MediaWikiServices.php:117
$lang
if(!isset( $args[0])) $lang
Definition:
testCompression.php:33
WikiPage
Class representing a MediaWiki article and history.
Definition:
WikiPage.php:47
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition:
Title.php:649
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition:
SpecialPage.php:749
$base
$base
Definition:
generateLocalAutoload.php:11
Language\isKnownLanguageTag
static isKnownLanguageTag( $tag)
Returns true if a language code is an IETF tag known to MediaWiki.
Definition:
Language.php:415
SpecialMyLanguage\findTitle
findTitle( $subpage)
Assuming the user's interface language is fi.
Definition:
SpecialMyLanguage.php:67
$title
$title
Definition:
testCompression.php:34
SpecialMyLanguage\__construct
__construct()
Definition:
SpecialMyLanguage.php:38
RedirectSpecialArticle
Superclass for any RedirectSpecialPage which redirects the user to a particular article (as opposed t...
Definition:
RedirectSpecialArticle.php:87
SpecialMyLanguage\personallyIdentifiableTarget
personallyIdentifiableTarget()
Target can identify a specific user's language preference.
Definition:
SpecialMyLanguage.php:137
SpecialMyLanguage
Unlisted special page just to redirect the user to the translated version of a page,...
Definition:
SpecialMyLanguage.php:37
includes
specials
SpecialMyLanguage.php
Generated on Thu Dec 19 2019 14:54:59 for MediaWiki by
1.8.16