MediaWiki r55711 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r55710‎ | r55711 (on ViewVC)‎ | r55712 >
Date:15:52, 1 September 2009
Author:daniel
Status:deferred
Tags:
Comment:
sort options by code, optionally show code (use wgLanguageSelectorShowCode)
Modified paths:

Diff [purge]

Index: trunk/extensions/LanguageSelector/LanguageSelector.php
===================================================================
--- trunk/extensions/LanguageSelector/LanguageSelector.php	(revision 55710)
+++ trunk/extensions/LanguageSelector/LanguageSelector.php	(revision 55711)
@@ -50,6 +50,11 @@
 */
 $wgLanguageSelectorLanguages = NULL;
 
+/**
+* Determine if language codes are shown in the selector, in addition to names;
+*/
+$wgLanguageSelectorShowCode = false;
+
 define( 'LANGUAGE_SELECTOR_MANUAL',    0 ); #don't place anywhere
 define( 'LANGUAGE_SELECTOR_AT_TOP_OF_TEXT', 1 ); #put at the top of page content
 define( 'LANGUAGE_SELECTOR_IN_TOOLBOX',  2 ); #put into toolbox
@@ -96,6 +101,7 @@
 	
 	if ( $wgLanguageSelectorLanguages === NULL ) {
 		$wgLanguageSelectorLanguages = array_keys( Language::getLanguageNames( true ) );
+		ksort( $wgLanguageSelectorLanguages );
 	}
 
 	$setlang = $wgRequest->getVal( 'setlang' );
@@ -199,13 +205,21 @@
 	$class = @$args['class'];
 	$selectorstyle = @$args['selectorstyle'];
 	$buttonstyle = @$args['buttonstyle'];
+	$showcode = @$args['showcode'];
 
 	if ($style) $style = htmlspecialchars($style);
 	if ($class) $class = htmlspecialchars($class);
 	if ($selectorstyle) $selectorstyle = htmlspecialchars($selectorstyle);
 	if ($buttonstyle) $buttonstyle = htmlspecialchars($buttonstyle);
 
-	return wfLanguageSelectorHTML( $style, $class, $selectorstyle, $buttonstyle );
+	if ($showcode) {
+	    $showcode = strtolower($showcode);
+	    if ($showcode == "true" || $showcode == "yes" || $showcode == "on") $showcode = true;
+	    else if ($showcode == "false" || $showcode == "no" || $showcode == "off") $showcode = false;
+	    else $showcode = NULL;
+	} else $showcode = NULL;
+
+	return wfLanguageSelectorHTML( $style, $class, $selectorstyle, $buttonstyle, $showcode );
 }
 
 function wfLanguageSelectorSkinTemplateOutputPageBeforeExec( &$skin, &$tpl ) {
@@ -329,9 +343,11 @@
 	return true;
 }
 
-function wfLanguageSelectorHTML( $style = NULL, $class = NULL, $selectorstyle = NULL, $buttonstyle = NULL ) {
-	global $wgLanguageSelectorLanguages, $wgTitle, $wgLang, $wgContLang, $wgScript;
+function wfLanguageSelectorHTML( $style = NULL, $class = NULL, $selectorstyle = NULL, $buttonstyle = NULL, $showCode = NULL ) {
+	global $wgLanguageSelectorLanguages, $wgTitle, $wgLang, $wgContLang, $wgScript, $wgLanguageSelectorShowCode;
 
+	if ($showCode === NULL) $showCode = $wgLanguageSelectorShowCode;
+
 	static $id = 0;
 	$id += 1;
 
@@ -344,7 +360,10 @@
 	$html .= Xml::openElement('select', array('name' => 'setlang', 'id' => 'languageselector-select-'.$id, 'style' => $selectorstyle));
 
 	foreach ($wgLanguageSelectorLanguages as $ln) {
-		$html .= Xml::option($wgContLang->getLanguageName($ln), $ln, $ln == $code);
+		$name = $wgContLang->getLanguageName($ln);
+		if ($showCode) $name = wfBCP47($ln) . ' - ' . $name;
+
+		$html .= Xml::option($name, $ln, $ln == $code);
 	}
 
 	$html .= Xml::closeElement('select');

Status & tagging log

  • 00:20, 14 September 2011 Meno25 (Talk | contribs) changed the status of r55711 [removed: old added: deferred]
  • 14:27, 24 October 2010 Reedy (Talk | contribs) changed the status of r55711 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox