r107002 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107001‎ | r107002 | r107003 >
Date:22:54, 21 December 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
follow-up to r106912, making change to correct branch this time
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -208,21 +208,39 @@
209209 }
210210
211211 /**
212 - *
213 - * @param $selected string The language code of the selected language
214 - * @param $customisedOnly bool 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
216218 */
217 - public static function languageSelector( $selected, $customisedOnly = true ) {
 219+ public static function languageSelector( $selected, $customisedOnly = true, $language = NULL ) {
218220 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...
224241 if( !array_key_exists( $wgLanguageCode, $languages ) ) {
225242 $languages[$wgLanguageCode] = $wgLanguageCode;
226243 }
 244+
227245 ksort( $languages );
228246
229247 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r107003MFT r106903, r107002awjrichards22:57, 21 December 2011
r111615Followup r107002...reedy02:52, 16 February 2012
r112479Combine getLanguageNames and getTranslatedLanguageNames into one function whi...robin11:59, 27 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106912adding CLDR support to XML::languageSelector()kaldari01:14, 21 December 2011

Comments

#Comment by Reedy (talk | contribs)   02:51, 16 February 2012

This should really be done in the extension via a hook... Not going to be overly straightforward though

#Comment by SPQRobin (talk | contribs)   12:49, 27 February 2012

Did this in a better way: r112479 (a new hook would've made it even messier)

Status & tagging log