* @param string $selected The language code of the selected language
* @param boolean $customisedOnly If true only languages which have some content are listed
* @param string $inLanguage The ISO code of the language to display the select list in (optional)
+ * @param array $overrideAttrs Override the attributes of the select tag (since 1.20)
+ * @param Message|null $msg Label message key (since 1.20)
* @return array containing 2 items: label HTML and select list HTML
*/
- public static function languageSelector( $selected, $customisedOnly = true, $inLanguage = null ) {
+ public static function languageSelector( $selected, $customisedOnly = true, $inLanguage = null, $overrideAttrs = array(), Message $msg = null ) {
global $wgLanguageCode;
- $languages = Language::fetchLanguageNames( $inLanguage, $customisedOnly ? 'mwfile' : 'mw' );
+ $include = $customisedOnly ? 'mwfile' : 'mw';
+ $languages = Language::fetchLanguageNames( $inLanguage, $include );
- // Make sure the site language is in the list; a custom language code might not have a
- // defined name...
+ // Make sure the site language is in the list;
+ // a custom language code might not have a defined name...
if( !array_key_exists( $wgLanguageCode, $languages ) ) {
$languages[$wgLanguageCode] = $wgLanguageCode;
}
/**
* If a bogus value is set, default to the content language.
* Otherwise, no default is selected and the user ends up
- * with an Afrikaans interface since it's first in the list.
+ * with Afrikaans since it's first in the list.
*/
$selected = isset( $languages[$selected] ) ? $selected : $wgLanguageCode;
$options = "\n";
$options .= Xml::option( "$code - $name", $code, ($code == $selected) ) . "\n";
}
+ $attrs = array( 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' );
+ $attrs = array_merge( $attrs, $overrideAttrs );
+
+ if( $msg === null ) {
+ $msg = wfMessage( 'yourlanguage' );
+ }
return array(
- Xml::label( wfMsg('yourlanguage'), 'wpUserLanguage' ),
- Xml::tags( 'select',
- array( 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' ),
- $options
- )
+ Xml::label( $msg->text(), $attrs['id'] ),
+ Xml::tags( 'select', $attrs, $options )
);
}
function buildForm() {
global $wgScript;
- $languages = Language::fetchLanguageNames( null, 'mw' );
- ksort( $languages );
+ $attrs = array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' );
+ $msg = wfMessage( 'allmessages-language' );
+ $langSelect = Xml::languageSelector( $this->langcode, false, null, $attrs, $msg );
$out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
"</td>\n
</tr>
<tr>\n
- <td class=\"mw-label\">" .
- Xml::label( $this->msg( 'allmessages-language' )->text(), 'mw-allmessages-form-lang' ) .
- "</td>\n
- <td class=\"mw-input\">" .
- Xml::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
-
- foreach( $languages as $lang => $name ) {
- $selected = $lang == $this->langcode;
- $out .= Xml::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
- }
- $out .= Xml::closeElement( 'select' ) .
- "</td>\n
+ <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
+ <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
</tr>" .
'<tr>