Index: trunk/extensions/Translate/specials/SpecialMyLanguage.php |
— | — | @@ -24,19 +24,9 @@ |
25 | 25 | |
26 | 26 | /// Only takes arguments from $par |
27 | 27 | public function execute( $par ) { |
28 | | - global $wgOut, $wgLang; |
| 28 | + global $wgOut; |
29 | 29 | |
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 ); |
41 | 31 | // Go to the main page if given invalid title. |
42 | 32 | if ( !$title ) { |
43 | 33 | $title = Title::newMainPage(); |
— | — | @@ -46,6 +36,40 @@ |
47 | 37 | } |
48 | 38 | |
49 | 39 | /** |
| 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 | + /** |
50 | 74 | * Make Special:MyLanguage links red if the target page doesn't exists. |
51 | 75 | * A bit hacky because the core code is not so flexible. |
52 | 76 | * @param $dummy |