Type check the APC value in LoadBalancer::doWait()
[mediawiki.git] / includes / specials / SpecialMyLanguage.php
blob9cb6d4b52911c52c6adcaf7ef04e7c77619e402c
1 <?php
2 /**
3 * Implements Special:MyLanguage
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Niklas Laxström
22 * @author Siebrand Mazeland
23 * @copyright Copyright © 2010-2013 Niklas Laxström, Siebrand Mazeland
26 /**
27 * Unlisted special page just to redirect the user to the translated version of
28 * a page, if it exists.
30 * Usage: [[Special:MyLanguage/Page name|link text]]
32 * @since 1.24
33 * @ingroup SpecialPage
35 class SpecialMyLanguage extends RedirectSpecialArticle {
36 public function __construct() {
37 parent::__construct( 'MyLanguage' );
40 /**
41 * If the special page is a redirect, then get the Title object it redirects to.
42 * False otherwise.
44 * @param string|null $subpage
45 * @return Title
47 public function getRedirect( $subpage ) {
48 $title = $this->findTitle( $subpage );
49 // Go to the main page if given invalid title.
50 if ( !$title ) {
51 $title = Title::newMainPage();
53 return $title;
56 /**
57 * Assuming the user's interface language is fi. Given input Page, it
58 * returns Page/fi if it exists, otherwise Page. Given input Page/de,
59 * it returns Page/fi if it exists, otherwise Page/de if it exists,
60 * otherwise Page.
62 * @param string|null $subpage
63 * @return Title|null
65 public function findTitle( $subpage ) {
66 // base = title without language code suffix
67 // provided = the title as it was given
68 $base = $provided = null;
69 if ( $subpage !== null ) {
70 $provided = Title::newFromText( $subpage );
71 $base = $provided;
74 if ( $provided && strpos( $subpage, '/' ) !== false ) {
75 $pos = strrpos( $subpage, '/' );
76 $basepage = substr( $subpage, 0, $pos );
77 $code = substr( $subpage, $pos + 1 );
78 if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
79 $base = Title::newFromText( $basepage );
83 if ( !$base ) {
84 return null;
87 if ( $base->isRedirect() ) {
88 $page = new WikiPage( $base );
89 $base = $page->getRedirectTarget();
92 $uiCode = $this->getLanguage()->getCode();
93 $proposed = $base->getSubpage( $uiCode );
94 if ( $proposed && $proposed->exists() && $uiCode !== $base->getPageLanguage()->getCode() ) {
95 return $proposed;
96 } elseif ( $provided && $provided->exists() ) {
97 return $provided;
98 } else {
99 return $base;
104 * Target can identify a specific user's language preference.
106 * @see T109724
107 * @since 1.27
108 * @return bool
110 public function personallyIdentifiableTarget() {
111 return true;