Index: branches/fundraising/vendors/mediawiki/current/includes/Xml.php |
— | — | @@ -208,21 +208,39 @@ |
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | | - * |
213 | | - * @param $selected The language code of the selected language |
214 | | - * @param $customisedOnly If true only languages which have some content are listed |
215 | | - * @return array of label and select |
| 212 | + * Construct a language selector appropriate for use in a form or preferences |
| 213 | + * |
| 214 | + * @param string $selected The language code of the selected language |
| 215 | + * @param boolean $customisedOnly If true only languages which have some content are listed |
| 216 | + * @param string $language The ISO code of the language to display the select list in (optional) |
| 217 | + * @return array containing 2 items: label HTML and select list HTML |
216 | 218 | */ |
217 | | - public static function languageSelector( $selected, $customisedOnly = true ) { |
| 219 | + public static function languageSelector( $selected, $customisedOnly = true, $language = NULL ) { |
218 | 220 | global $wgLanguageCode; |
219 | | - /** |
220 | | - * Make sure the site language is in the list; a custom language code |
221 | | - * might not have a defined name... |
222 | | - */ |
223 | | - $languages = Language::getLanguageNames( $customisedOnly ); |
| 221 | + |
| 222 | + // If a specific language was requested and CLDR is installed, use it |
| 223 | + if ( $language && is_callable( array( 'LanguageNames', 'getNames' ) ) ) { |
| 224 | + if ( $customisedOnly ) { |
| 225 | + $listType = LanguageNames::LIST_MW_SUPPORTED; // Only pull names that have localisation in MediaWiki |
| 226 | + } else { |
| 227 | + $listType = LanguageNames::LIST_MW; // Pull all languages that are in Names.php |
| 228 | + } |
| 229 | + // Retrieve the list of languages in the requested language (via CLDR) |
| 230 | + $languages = LanguageNames::getNames( |
| 231 | + $language, // Code of the requested language |
| 232 | + LanguageNames::FALLBACK_NORMAL, // Use fallback chain |
| 233 | + $listType |
| 234 | + ); |
| 235 | + } else { |
| 236 | + $languages = Language::getLanguageNames( $customisedOnly ); |
| 237 | + } |
| 238 | + |
| 239 | + // Make sure the site language is in the list; a custom language code might not have a |
| 240 | + // defined name... |
224 | 241 | if( !array_key_exists( $wgLanguageCode, $languages ) ) { |
225 | 242 | $languages[$wgLanguageCode] = $wgLanguageCode; |
226 | 243 | } |
| 244 | + |
227 | 245 | ksort( $languages ); |
228 | 246 | |
229 | 247 | /** |