Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / resources / src / mediawiki.special.userlogin.signup.js
index 777f5e9..2469381 100644 (file)
@@ -9,7 +9,7 @@
                        originalText = $emailLabel.text(),
                        requiredText = mw.message( 'createacct-emailrequired' ).text(),
                        $createByMailCheckbox = $( '#wpCreateaccountMail' ),
-                       $beforePwds = $( '.mw-row-password:first' ).prev(),
+                       $beforePwds = $( '.mw-row-password' ).first().prev(),
                        $pwds;
 
                function updateForCheckbox() {
@@ -30,7 +30,7 @@
                updateForCheckbox();
        } );
 
-       // Check if the username is invalid or already taken
+       // Check if the username is invalid or already taken; show username normalisation warning
        mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
                var $usernameInput = $root.find( '#wpName2' ),
                        $passwordInput = $root.find( '#wpPassword2' ),
                        // We could just use .then() if we didn't have to pass on .abort()…
                        var d, apiPromise;
 
+                       // Leading/trailing/multiple whitespace characters are always stripped in usernames,
+                       // this should not require a warning. We do warn about underscores.
+                       username = username.replace( / +/g, ' ' ).trim();
+
                        d = $.Deferred();
                        apiPromise = api.get( {
                                action: 'query',
                                                                return m.html;
                                                        } ) : []
                                                } );
+                                       } else if ( userinfo.name !== username ) {
+                                               d.resolve( { valid: true, messages: [
+                                                       mw.message( 'createacct-normalization', username, userinfo.name ).parseDom()
+                                               ] } );
                                        } else {
                                                d.resolve( { valid: true, messages: [] } );
                                        }