Index: trunk/extensions/Babel/Babel.class.php |
— | — | @@ -126,16 +126,22 @@ |
127 | 127 | } |
128 | 128 | // Try splitting the paramter in to language and level, split on last hyphen. |
129 | 129 | $lastSplit = strrpos( $parameter, '-' ); |
130 | | - if ( $lastSplit === false ) return false; |
| 130 | + if ( $lastSplit === false ) { |
| 131 | + return false; |
| 132 | + } |
131 | 133 | $code = substr( $parameter, 0, $lastSplit ); |
132 | 134 | $level = substr( $parameter, $lastSplit + 1 ); |
133 | 135 | |
134 | 136 | // Validate code. |
135 | 137 | $return['code'] = BabelLanguageCodes::getCode( $code ); |
136 | | - if ( !$return['code'] ) return false; |
| 138 | + if ( !$return['code'] ) { |
| 139 | + return false; |
| 140 | + } |
137 | 141 | // Validate level. |
138 | 142 | $intLevel = (int) $level; |
139 | | - if ( ( $intLevel < 0 || $intLevel > 5 ) && $level !== 'N' ) return false; |
| 143 | + if ( ( $intLevel < 0 || $intLevel > 5 ) && $level !== 'N' ) { |
| 144 | + return false; |
| 145 | + } |
140 | 146 | $return['level'] = $level; |
141 | 147 | |
142 | 148 | return $return; |
— | — | @@ -146,6 +152,7 @@ |
147 | 153 | * |
148 | 154 | * @param $code String: Language code to use. |
149 | 155 | * @param $level String or Integer: Level of ability to use. |
| 156 | + * @return String: A single babel box, in wikitext format. |
150 | 157 | */ |
151 | 158 | protected function mGenerateBox( $code, $level ) { |
152 | 159 | $header = "[[{$this->mAddFixes( $code,'portal' )}|" . wfBCP47( $code ) . "]]<span class=\"mw-babel-box-level-$level\">-$level</span>"; |
— | — | @@ -177,10 +184,10 @@ |
178 | 185 | * @return String: Text for display, in wikitext format. |
179 | 186 | */ |
180 | 187 | protected function mGetText( $name, $language, $level ) { |
181 | | - global $wgTitle, $wgBabelUseLevelZeroCategory; |
| 188 | + global $wgTitle, $wgBabelUseLevelZeroCategory, $wgBabelCategoryNames; |
182 | 189 | |
183 | | - $categoryLevel = ":Category:{$this->mAddFixes( "$language-$level",'category' )}"; |
184 | | - $categorySuper = ":Category:{$this->mAddFixes( $language,'category' )}"; |
| 190 | + $categoryLevel = ':Category:' . $this->mReplaceCategoryVariables( $wgBabelCategoryNames[$level], $language ); |
| 191 | + $categorySuper = ':Category:' . $this->mReplaceCategoryVariables( $wgBabelCategoryNames['main'], $language ); |
185 | 192 | |
186 | 193 | if ( !$wgBabelUseLevelZeroCategory && $level === '0' ) { |
187 | 194 | $categoryLevel = $wgTitle->getFullText(); |
— | — | @@ -211,23 +218,47 @@ |
212 | 219 | * |
213 | 220 | * @param $code String: Language code to use. |
214 | 221 | * @param $level String or Integer: Level of ability to use. |
| 222 | + * @return String: Wikitext to add categories. |
215 | 223 | */ |
216 | 224 | protected function mGenerateCategories( $code, $level ) { |
217 | 225 | global $wgBabelUseMainCategories, $wgBabelUseLevelZeroCategory, |
218 | | - $wgBabelUseSimpleCategories; |
| 226 | + $wgBabelUseSimpleCategories, $wgBabelCategoryNames, $wgLanguageCode; |
219 | 227 | |
220 | 228 | $r = ''; |
221 | 229 | |
222 | 230 | if ( $wgBabelUseMainCategories && ( $level === 'N' || ( $wgBabelUseLevelZeroCategory && $level === '0' ) || $level > 0 ) ) { |
223 | | - $r .= "[[Category:{$this->mAddFixes( $code,'category' )}|$level]]"; |
224 | | - BabelAutoCreate::create( $this->mAddFixes( "$code", 'category' ), BabelLanguageCodes::getName( $code ) ); |
| 231 | + $category = $this->mReplaceCategoryVariables( $wgBabelCategoryNames['main'], $code ); |
| 232 | + $r .= "[[Category:$category|$level]]"; |
| 233 | + BabelAutoCreate::create( $category, BabelLanguageCodes::getName( $code, $wgLanguageCode ) ); |
225 | 234 | } |
226 | 235 | |
227 | 236 | if ( !$wgBabelUseSimpleCategories && ( $level === 'N' || ( $wgBabelUseLevelZeroCategory && $level === '0' ) || $level > 0 ) ) { |
228 | | - $r .= "[[Category:{$this->mAddFixes( "$code-$level",'category' )}]]"; |
229 | | - BabelAutoCreate::create( $this->mAddFixes( "$code-$level", 'category' ), $level, BabelLanguageCodes::getName( $code ) ); |
| 237 | + $category = $this->mReplaceCategoryVariables( $wgBabelCategoryNames[$level], $code ); |
| 238 | + $r .= "[[Category:$category]]"; |
| 239 | + BabelAutoCreate::create( $category, BabelLanguageCodes::getName( $code, $wgLanguageCode ), $level ); |
230 | 240 | } |
231 | 241 | |
232 | 242 | return $r; |
233 | 243 | } |
| 244 | + |
| 245 | + /** |
| 246 | + * Replace the placeholder variables from the category names configurtion |
| 247 | + * array with actual values. |
| 248 | + * |
| 249 | + * @param $category String: Category name (containing variables). |
| 250 | + * @param $code String: Language code of category. |
| 251 | + * @return String: Category name with variables replaced. |
| 252 | + */ |
| 253 | + protected function mReplaceCategoryVariables( $category, $code ) { |
| 254 | + global $wgLanguageCode; |
| 255 | + $vars = array( |
| 256 | + '%code%' => $code, |
| 257 | + '%wikiname%' => BabelLanguageCodes::getName( $code, $wgLanguageCode ), |
| 258 | + '%nativename%' => BabelLanguageCodes::getName( $code ) |
| 259 | + ); |
| 260 | + foreach ( $vars as $find => $replace ) { |
| 261 | + $category = str_replace( $find, $replace, $category ); |
| 262 | + } |
| 263 | + return $category; |
| 264 | + } |
234 | 265 | } |
Index: trunk/extensions/Babel/BabelLanguageCodes.class.php |
— | — | @@ -38,9 +38,11 @@ |
39 | 39 | * - Names constant database. |
40 | 40 | * |
41 | 41 | * @param $code String: Code to get name for. |
| 42 | + * @param $language String: Code of language to attempt to get name in, |
| 43 | + * defaults to language of code. |
42 | 44 | * @return String (name of language) or false (invalid language code). |
43 | 45 | */ |
44 | | - public static function getName( $code ) { |
| 46 | + public static function getName( $code, $language = null ) { |
45 | 47 | $cacheType = 'name'; |
46 | 48 | // Get correct code, even though it should already be correct. |
47 | 49 | $code = self::getCode( $code ); |
— | — | @@ -48,9 +50,13 @@ |
49 | 51 | return false; |
50 | 52 | } |
51 | 53 | |
| 54 | + if ( $language === null ) { |
| 55 | + $language = $code; |
| 56 | + } |
| 57 | + |
52 | 58 | // Try CLDR extension, then MediaWiki native. |
53 | 59 | if ( class_exists( 'LanguageNames' ) ) { |
54 | | - $names = LanguageNames::getNames( $code, LanguageNames::FALLBACK_NORMAL, LanguageNames::LIST_MW_AND_CLDR ); |
| 60 | + $names = LanguageNames::getNames( $language, LanguageNames::FALLBACK_NORMAL, LanguageNames::LIST_MW_AND_CLDR ); |
55 | 61 | } else { |
56 | 62 | $names = Language::getLanguageNames(); |
57 | 63 | } |
Index: trunk/extensions/Babel/Babel.i18n.php |
— | — | @@ -43,8 +43,6 @@ |
44 | 44 | |
45 | 45 | 'babel-box-cellspacing' => '0', # Do not translate or duplicate this message to other languages. |
46 | 46 | |
47 | | - 'babel-category-prefix' => '', # Do not translate or duplicate this message to other languages. |
48 | | - 'babel-category-suffix' => '', # Do not translate or duplicate this message to other languages. |
49 | 47 | 'babel-portal-prefix' => '', # Do not translate or duplicate this message to other languages. |
50 | 48 | 'babel-portal-suffix' => '', # Do not translate or duplicate this message to other languages. |
51 | 49 | 'babel-template-prefix' => '', # Do not translate or duplicate this message to other languages. |
— | — | @@ -55,7 +53,6 @@ |
56 | 54 | |
57 | 55 | /** Message documentation (Message documentation) |
58 | 56 | * @author Lloffiwr |
59 | | - * @author MinuteElectron |
60 | 57 | * @author Purodha |
61 | 58 | * @author Raimond Spekking |
62 | 59 | * @author Raymond |
Index: trunk/extensions/Babel/Babel.php |
— | — | @@ -49,6 +49,17 @@ |
50 | 50 | // Language names and codes constant database files, the defaults should suffice. |
51 | 51 | $wgBabelLanguageCodesCdb = $dir . '/codes.cdb'; |
52 | 52 | $wgBabelLanguageNamesCdb = $dir . '/names.cdb'; |
| 53 | +// Format of category names - variables: %code% %wikiname% %nativename% |
| 54 | +$wgBabelCategoryNames = array( |
| 55 | + 0 => '%code%-0', |
| 56 | + 1 => '%code%-1', |
| 57 | + 2 => '%code%-2', |
| 58 | + 3 => '%code%-3', |
| 59 | + 4 => '%code%-4', |
| 60 | + 5 => '%code%-5', |
| 61 | + 'N' => '%code%-N', |
| 62 | + 'main' => '%code%' |
| 63 | +); |
53 | 64 | |
54 | 65 | /* Other settings, to be made in-wiki: |
55 | 66 | MediaWiki:Babel-template-prefix and MediaWiki:Babel-template-suffix |
Index: trunk/extensions/Babel/codes.txt |
— | — | @@ -679,6 +679,7 @@ |
680 | 680 | - bgx "Balkan Gagauz Turkish" |
681 | 681 | - bgy "Benggoi" |
682 | 682 | - bgz "Banggai" |
| 683 | +bh - "Bihari" |
683 | 684 | - bha "Bharia" |
684 | 685 | - bhb "Bhili" |
685 | 686 | - bhc "Biga" |
— | — | @@ -4105,6 +4106,7 @@ |
4106 | 4107 | - moi "Mboi" |
4107 | 4108 | - moj "Monzombo" |
4108 | 4109 | - mok "Morori" |
| 4110 | +mo mol "Moldavian" |
4109 | 4111 | - mom "Mangue" |
4110 | 4112 | mn mon "Mongolian" |
4111 | 4113 | - moo "Monom" |
Index: trunk/extensions/Babel/BabelAutoCreate.class.php |
— | — | @@ -17,6 +17,10 @@ |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Create category. |
| 21 | + * |
| 22 | + * @param $category String: Name of category to create. |
| 23 | + * @param $language String: Name of language that the category is for. |
| 24 | + * @param $level String: Level that the category is for. |
21 | 25 | */ |
22 | 26 | public static function create( $category, $language, $level = null ) { |
23 | 27 | $category = strip_tags( $category ); |
— | — | @@ -27,14 +31,16 @@ |
28 | 32 | if ( $level === null ) { |
29 | 33 | $text = wfMsgForContent( 'babel-autocreate-text-main', $language ); |
30 | 34 | } else { |
31 | | - $text = wfMsgForContent( 'babel-autocreate-text-levels', $language, $level ); |
| 35 | + $text = wfMsgForContent( 'babel-autocreate-text-levels', $level, $language ); |
32 | 36 | } |
33 | 37 | $article = new Article( $title ); |
34 | | - $article->doEdit( $text, wfMsgForContent( 'babel-autocreate-reason', wfMsgForContent( 'babel-url' ) ), EDIT_SUPPRESS_RC, false, self::user() ); |
| 38 | + $article->doEdit( $text, wfMsgForContent( 'babel-autocreate-reason', wfMsgForContent( 'babel-url' ) ), EDIT_FORCE_BOT, false, self::user() ); |
35 | 39 | } |
36 | 40 | |
37 | 41 | /** |
38 | 42 | * Get user object. |
| 43 | + * |
| 44 | + * @return User object: User object for autocreate user. |
39 | 45 | */ |
40 | 46 | public static function user() { |
41 | 47 | if ( !self::$user ) { |