Index: trunk/extensions/LanguageSelector/LanguageSelector.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | define( 'LANGUAGE_SELECTOR_USE_CONTENT_LANG', 0 ); #no detection |
34 | 34 | define( 'LANGUAGE_SELECTOR_PREFER_CONTENT_LANG', 1 ); #use content language if accepted by the client |
35 | 35 | define( 'LANGUAGE_SELECTOR_PREFER_CLIENT_LANG', 2 ); #use language most preferred by the client |
| 36 | +define( 'LANGUAGE_SELECTOR_ADJUST_CONTENT', 3 ); |
36 | 37 | |
37 | 38 | /** |
38 | 39 | * Language detection mode for anonymous visitors. |
— | — | @@ -89,7 +90,32 @@ |
90 | 91 | $dir = dirname(__FILE__) . '/'; |
91 | 92 | $wgExtensionMessagesFiles['LanguageSelector'] = $dir . 'LanguageSelector.i18n.php'; |
92 | 93 | $wgJSAutoloadClasses['LanguageSelector'] = 'extensions/LanguageSelector/LanguageSelector.js'; |
| 94 | +$wgHooks['BeforeInitialize'][] = 'wfLanguageSelectorAdjustContent'; |
93 | 95 | |
| 96 | +function wfLanguageSelectorAdjustContent( &$title, &$article, &$output, &$user, $request, $this ) { |
| 97 | + global $wgLanguageSelectorRequestedLanguage, $wgLanguageNames, $wgLanguageSelectorAdjustContent; |
| 98 | + if( isset($wgLanguageSelectorRequestedLanguage) && strlen($wgLanguageSelectorRequestedLanguage)>0){ |
| 99 | + if( isset($wgLanguageSelectorAdjustContent) && $wgLanguageSelectorAdjustContent=== LANGUAGE_SELECTOR_ADJUST_CONTENT){ |
| 100 | + $langstr="/".$wgLanguageSelectorRequestedLanguage; |
| 101 | + $searchstr="#/(". implode('|',array_keys($wgLanguageNames)) ."$)#"; |
| 102 | + if(preg_match($searchstr,$title->mTextform)){ |
| 103 | + $title->mTextform =preg_replace($searchstr,$langstr, $title->mTextform); |
| 104 | + $title->mUrlform =preg_replace($searchstr,$langstr, $title->mUrlform); |
| 105 | + $title->mDbkeyform =preg_replace($searchstr,$langstr, $title->mDbkeyform); |
| 106 | + $title->mUserCaseDBKey =preg_replace($searchstr,$langstr, $title->mUserCaseDBKey); |
| 107 | + }else{ |
| 108 | + if($_GET['setlang']== $wgLanguageSelectorRequestedLanguage){ |
| 109 | + $title->mTextform.=$langstr; |
| 110 | + $title->mUrlform.=$langstr; |
| 111 | + $title->mDbkeyform.=$langstr; |
| 112 | + $title->mUserCaseDBKey.=$langstr; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + return true; |
| 118 | +} |
| 119 | + |
94 | 120 | /** |
95 | 121 | * @param $parser Parser |
96 | 122 | * @return bool |
— | — | @@ -403,4 +429,3 @@ |
404 | 430 | |
405 | 431 | return $html; |
406 | 432 | } |
407 | | - |