MediaWiki r14901 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r14900‎ | r14901 (on ViewVC)‎ | r14902 >
Date:12:19, 22 June 2006
Author:robchurch
Status:old
Tags:
Comment:
Introduce optional (off by default) language selector bar for user login and registration.Customisable via the "loginlanguagelinks" message, the links will preserve "returnto" values. If the user creates an account while using such a link, then the language in use will be saved as their language preference.
Modified paths:

Diff [purge]

Index: trunk/phase3/skins/monobook/main.css
===================================================================
--- trunk/phase3/skins/monobook/main.css	(revision 14900)
+++ trunk/phase3/skins/monobook/main.css	(revision 14901)
@@ -1098,7 +1098,7 @@
 }
 
 
-#userloginprompt {
+#userloginprompt, #languagelinks {
 	font-size: 85%;
 }
 
Index: trunk/phase3/skins/MonoBook.php
===================================================================
--- trunk/phase3/skins/MonoBook.php	(revision 14900)
+++ trunk/phase3/skins/MonoBook.php	(revision 14901)
@@ -56,7 +56,7 @@
 		<meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
 		<?php $this->html('headlinks') ?>
 		<title><?php $this->text('pagetitle') ?></title>
-		<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/main.css?7"; /*]]>*/</style>
+		<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/main.css?8"; /*]]>*/</style>
 		<link rel="stylesheet" type="text/css" <?php if(empty($this->data['printable']) ) { ?>media="print"<?php } ?> href="<?php $this->text('stylepath') ?>/common/commonPrint.css" />
 		<!--[if lt IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE50Fixes.css";</style><![endif]-->
 		<!--[if IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE55Fixes.css";</style><![endif]-->
Index: trunk/phase3/includes/SpecialUserlogin.php
===================================================================
--- trunk/phase3/includes/SpecialUserlogin.php	(revision 14900)
+++ trunk/phase3/includes/SpecialUserlogin.php	(revision 14901)
@@ -27,7 +27,7 @@
 class LoginForm {
 	var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
 	var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
-	var $mLoginattempt, $mRemember, $mEmail, $mDomain;
+	var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
 
 	/**
 	 * Constructor
@@ -53,6 +53,7 @@
 		$this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
 		$this->mAction = $request->getVal( 'action' );
 		$this->mRemember = $request->getCheck( 'wpRemember' );
+		$this->mLanguage = $request->getText( 'uselang' );
 
 		if( $wgEnableEmail ) {
 			$this->mEmail = $request->getText( 'wpEmail' );
@@ -141,6 +142,12 @@
 		if( $u == NULL )
 			return;
 			
+		# If we showed up language selection links, and one was in use, be
+		# smart (and sensible) and save that language as the user's preference
+		global $wgLoginLanguageSelector;
+		if( $wgLoginLanguageSelector && $this->mLanguage )
+			$u->setOption( 'language', $this->mLanguage );
+		
 		# Save user settings and send out an email authentication message if needed
 		$u->saveSettings();
 		if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) )
@@ -533,6 +540,13 @@
 		$template->set( 'userealname', $wgAllowRealName );
 		$template->set( 'useemail', $wgEnableEmail );
 		$template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember  );
+				
+		global $wgLoginLanguageSelector;
+		if( $wgLoginLanguageSelector ) {
+			$template->set( 'languages', $this->makeLanguageSelector() );
+			if( $this->mLanguage )
+				$template->set( 'uselang', $this->mLanguage );
+		}
 		
 		// Give authentication and captcha plugins a chance to modify the form
 		$wgAuth->modifyUITemplate( $template );
@@ -609,5 +623,40 @@
 
 		$wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
 	}
+	
+	/**
+	 * Produce a bar of links which allow the user to select another language
+	 * during login/registration but retain "returnto" and certain form values
+	 *
+	 * @return string
+	 */
+	function makeLanguageSelector() {
+		$msg = wfMsgForContent( 'loginlanguagelinks' );
+		if( $msg != '' && $msg != '&lt;loginlanguagelinks&gt;' ) {
+			$langs = explode( "\n", $msg );
+			$links = array();
+			foreach( $langs as $lang ) {
+				$lang = trim( $lang, '* ' );
+				$parts = explode( '|', $lang );
+				$links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
+			}
+			return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
+		} else {
+			return '';
+		}
+	}
+	
+	function makeLanguageSelectorLink( $text, $lang ) {
+		global $wgUser;
+		$self = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
+		$attr[] = 'uselang=' . $lang;
+		if( $this->mType == 'signup' )
+			$attr[] = 'type=signup';
+		if( $this->mReturnTo )
+			$attr[] = 'returnto=' . $this->mReturnTo;
+		$skin =& $wgUser->getSkin();
+		return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
+	}
+	
 }
 ?>
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 14900)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 14901)
@@ -663,6 +663,13 @@
 # Whether to enable language variant conversion.
 $wgDisableLangConversion = false;
 
+/**
+ * Show a bar of language selection links in the user login and user
+ * registration forms; edit the "loginlanguagelinks" message to
+ * customise these
+ */
+$wgLoginLanguageSelector = false;
+
 # Whether to use zhdaemon to perform Chinese text processing
 # zhdaemon is under developement, so normally you don't want to
 # use it unless for testing
Index: trunk/phase3/includes/templates/Userlogin.php
===================================================================
--- trunk/phase3/includes/templates/Userlogin.php	(revision 14900)
+++ trunk/phase3/includes/templates/Userlogin.php	(revision 14901)
@@ -31,6 +31,7 @@
 	<h2><?php $this->msg('login') ?></h2>
 	<p id="userloginlink"><?php $this->html('link') ?></p>
 	<div id="userloginprompt"><?php  $this->msgWiki('loginprompt') ?></div>
+	<?php if( @$this->haveData( 'languages' ) ) { ?><div id="languagelinks"><p><?php $this->html( 'languages' ); ?></p></div><?php } ?>
 	<table>
 		<tr>
 			<td align='right'><label for='wpName1'><?php $this->msg('yourname') ?>:</label></td>
@@ -79,6 +80,7 @@
 			</td>
 		</tr>
 	</table>
+<?php if( @$this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->html( 'uselang' ); ?>" /><?php } ?>
 </form>
 </div>
 <div id="loginend"><?php $this->msgWiki( 'loginend' ); ?></div>
@@ -105,6 +107,7 @@
 	<h2><?php $this->msg('createaccount') ?></h2>
 	<p id="userloginlink"><?php $this->html('link') ?></p>
 	<?php $this->html('header'); /* pre-table point for form plugins... */ ?>
+	<?php if( @$this->haveData( 'languages' ) ) { ?><div id="languagelinks"><p><?php $this->html( 'languages' ); ?></p></div><?php } ?>
 	<table>
 		<tr>
 			<td align='right'><label for='wpName2'><?php $this->msg('yourname') ?>:</label></td>
@@ -200,6 +203,7 @@
 		}
 
 	?>
+<?php if( @$this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?>
 </form>
 </div>
 <div id="signupend"><?php $this->msgWiki( 'signupend' ); ?></div>
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 14900)
+++ trunk/phase3/RELEASE-NOTES	(revision 14901)
@@ -537,6 +537,10 @@
 * (bug 6392) Fix misbehaving <br /> in preferences form
 * Add translated magic words to Hebrew localization
 * (bug 6396) Change name for Chuvash language
+* Introduce optional (off by default) language selector bar for user login and registration.
+  Customisable via the "loginlanguagelinks" message, the links will preserve "returnto"
+  values. If the user creates an account while using such a link, then the language in use
+  will be saved as their language preference.
 
 == Compatibility ==
 
Index: trunk/phase3/languages/Messages.php
===================================================================
--- trunk/phase3/languages/Messages.php	(revision 14900)
+++ trunk/phase3/languages/Messages.php	(revision 14901)
@@ -2021,7 +2021,17 @@
 # Please don't localise this
 'catseparator' => '|',
 
+'loginlanguagelabel' => 'Language: $1',
+
+# Don't duplicate this in translations; defaults should remain consistent
+'loginlanguagelinks' => "* Deutsch|de
+* English|en
+* Esperanto|eo
+* Français|fr
+* Español|es
+* Italiano|it
+* Nederlands|nl",
+
 );
 
-
 ?>

Status & tagging log

  • 01:58, 13 October 2010 ^demon (Talk | contribs) changed the status of r14901 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox