MediaWiki  REL1_24
SpecialMyLanguage.php
Go to the documentation of this file.
00001 <?php
00035 class SpecialMyLanguage extends RedirectSpecialArticle {
00036     public function __construct() {
00037         parent::__construct( 'MyLanguage' );
00038     }
00039 
00047     public function getRedirect( $par ) {
00048         $title = $this->findTitle( $par );
00049         // Go to the main page if given invalid title.
00050         if ( !$title ) {
00051             $title = Title::newMainPage();
00052         }
00053         return $title;
00054     }
00055 
00065     public function findTitle( $par ) {
00066         // base = title without language code suffix
00067         // provided = the title as it was given
00068         $base = $provided = Title::newFromText( $par );
00069 
00070         if ( $base && strpos( $par, '/' ) !== false ) {
00071             $pos = strrpos( $par, '/' );
00072             $basepage = substr( $par, 0, $pos );
00073             $code = substr( $par, $pos + 1 );
00074             if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
00075                 $base = Title::newFromText( $basepage );
00076             }
00077         }
00078 
00079         if ( !$base ) {
00080             return null;
00081         }
00082 
00083         $uiCode = $this->getLanguage()->getCode();
00084         $proposed = $base->getSubpage( $uiCode );
00085         if ( $uiCode !== $this->getConfig()->get( 'LanguageCode' ) && $proposed && $proposed->exists() ) {
00086             return $proposed;
00087         } elseif ( $provided && $provided->exists() ) {
00088             return $provided;
00089         } else {
00090             return $base;
00091         }
00092     }
00093 }