SpecialMyLanguage.php

Go to the documentation of this file.
00001 <?php
00020 class SpecialMyLanguage extends UnlistedSpecialPage {
00021     public function __construct() {
00022         parent::__construct( 'MyLanguage' );
00023     }
00024 
00026     public function execute( $par ) {
00027         $title = $this->findTitle( $par );
00028         // Go to the main page if given invalid title.
00029         if ( !$title ) {
00030             $title = Title::newMainPage();
00031         }
00032 
00033         $this->getOutput()->redirect( $title->getLocalURL() );
00034     }
00035 
00044     protected function findTitle( $par ) {
00045         global $wgLanguageCode;
00046         // base = title without language code suffix
00047         // provided = the title as it was given
00048         $base = $provided = Title::newFromText( $par );
00049 
00050         if ( strpos( $par, '/' ) !== false ) {
00051             $pos = strrpos( $par, '/' );
00052             $basepage = substr( $par, 0, $pos );
00053             $code = substr( $par, $pos + 1 );
00054             $codes = Language::getLanguageNames( false );
00055             if ( isset( $codes[$code] ) ) {
00056                 $base = Title::newFromText( $basepage );
00057             }
00058         }
00059 
00060         if ( !$base ) {
00061             return null;
00062         }
00063 
00064         $uiCode = $this->getLanguage()->getCode();
00065         $proposed = Title::newFromText( $base->getPrefixedText() . "/$uiCode" );
00066         if ( $uiCode !== $wgLanguageCode && $proposed && $proposed->exists() ) {
00067             return $proposed;
00068         } elseif ( $provided && $provided->exists() ) {
00069             return $provided;
00070         } else {
00071             return $base;
00072         }
00073     }
00074 
00087     public static function linkfix( $dummy, $target, &$html, &$customAttribs,
00088         &$query, &$options, &$ret
00089     ) {
00090         if ( $target->getNamespace() == NS_SPECIAL ) {
00091             list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $target->getDBkey() );
00092             if ( $name === 'MyLanguage' ) {
00093                 $realTarget = Title::newFromText( $subpage );
00094                 if ( !$realTarget || !$realTarget->exists() ) {
00095                     $options[] = 'broken';
00096                     $index = array_search( 'known', $options, true );
00097                     if ( $index !== false ) {
00098                         unset( $options[$index] );
00099                     }
00100 
00101                     $index = array_search( 'noclasses', $options, true );
00102                     if ( $index !== false ) {
00103                         unset( $options[$index] );
00104                     }
00105                 }
00106             }
00107         }
00108 
00109         return true;
00110     }
00111 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3