Introduce optional (off by default) language selector bar for user login and registra...
authorRob Church <robchurch@users.mediawiki.org>
Thu, 22 Jun 2006 12:19:55 +0000 (12:19 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Thu, 22 Jun 2006 12:19:55 +0000 (12:19 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/SpecialUserlogin.php
includes/templates/Userlogin.php
languages/Messages.php
skins/MonoBook.php
skins/monobook/main.css

index f6b49f5..9a3413e 100644 (file)
@@ -537,6 +537,10 @@ Some default configuration options have changed:
 * (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 9ef31e2..053798f 100644 (file)
@@ -663,6 +663,13 @@ $wgMsgCacheExpiry  = 86400;
 # 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 6a549e2..a951d2b 100644 (file)
@@ -27,7 +27,7 @@ function wfSpecialUserlogin() {
 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 @@ class LoginForm {
                $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 @@ class LoginForm {
                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 @@ class LoginForm {
                $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 @@ class LoginForm {
 
                $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 58d9920..cc797f9 100644 (file)
@@ -31,6 +31,7 @@ class UserloginTemplate extends QuickTemplate {
        <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 @@ class UserloginTemplate extends QuickTemplate {
                        </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 @@ class UsercreateTemplate extends QuickTemplate {
        <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 @@ class UsercreateTemplate extends QuickTemplate {
                }
 
        ?>
+<?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 d855110..daa8e78 100644 (file)
@@ -2021,7 +2021,17 @@ Please confirm that really want to recreate this page.',
 # 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",
 
+);
 
 ?>
index d4c6638..67b2e38 100644 (file)
@@ -56,7 +56,7 @@ class MonoBookTemplate extends QuickTemplate {
                <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 2de20bf..9960c8f 100644 (file)
@@ -1098,7 +1098,7 @@ div#userlogin .captcha {
 }
 
 
-#userloginprompt {
+#userloginprompt, #languagelinks {
        font-size: 85%;
 }