r107826 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107825‎ | r107826 | r107827 >
Date:12:56, 2 January 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
I18n #353: Using Special:MyPage/Page/ta will now try titles in this order: Page/<uilang>, Page/ta, Page
Modified paths:
  • /trunk/extensions/Translate/specials/SpecialMyLanguage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/specials/SpecialMyLanguage.php
@@ -24,19 +24,9 @@
2525
2626 /// Only takes arguments from $par
2727 public function execute( $par ) {
28 - global $wgOut, $wgLang;
 28+ global $wgOut;
2929
30 - $title = null;
31 - if ( strval( $par ) !== '' ) {
32 - $title = Title::newFromText( $par );
33 - if ( $title && $title->exists() && $wgLang->getCode() !== 'en' ) {
34 - $local = Title::newFromText( "$par/" . $wgLang->getCode() );
35 - if ( $local && $local->exists() ) {
36 - $title = $local;
37 - }
38 - }
39 - }
40 -
 30+ $title = $this->findTitle( $par );
4131 // Go to the main page if given invalid title.
4232 if ( !$title ) {
4333 $title = Title::newMainPage();
@@ -46,6 +36,40 @@
4737 }
4838
4939 /**
 40+ * Assuming the user's interface language is fi
 41+ * Given input Page, it returns Page/fi if it exists, otherwise Page
 42+ * Given input Page/de, it returns Page/fi if it exists, otherwise Page/de if it exists, otherwise Page
 43+ * @return Title|null
 44+ */
 45+ protected function findTitle( $par ) {
 46+ global $wgLang, $wgLanguageCode;
 47+ // base = title without language code suffix
 48+ // provided = the title as it was given
 49+ $base = $provided = Title::newFromText( $par );
 50+
 51+ if ( strpos( $par, '/' ) !== false ) {
 52+ $pos = strrpos( $par, '/' );
 53+ $basepage = substr( $par, 0, $pos );
 54+ $code = substr( $par, $pos+1 );
 55+ $codes = Language::getLanguageNames( false );
 56+ if ( isset( $codes[$code] ) ) {
 57+ $base = Title::newFromText( $basepage );
 58+ }
 59+ }
 60+
 61+ $uiCode = $wgLang->getCode();
 62+ $proposed = Title::newFromText( $base->getPrefixedText() . "/$uiCode" );
 63+ if ( $uiCode !== $wgLanguageCode && $proposed && $proposed->exists() ) {
 64+ return $proposed;
 65+ } elseif( $provided && $provided->exists() ) {
 66+ return $provided;
 67+ } else {
 68+ return $base;
 69+ }
 70+
 71+ }
 72+
 73+ /**
5074 * Make Special:MyLanguage links red if the target page doesn't exists.
5175 * A bit hacky because the core code is not so flexible.
5276 * @param $dummy

Status & tagging log