From a0c72523c7a2c9ca16329f903ca6b269ccccb787 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 20 Feb 2014 02:30:58 +0100 Subject: [PATCH] Warn on account creation when username is adjusted MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The user name can be adjusted due to various technical restrictions: the first letter is capitalized, underscores are changed to spaces, numerous other less visible changes happen. Some of these tweaks can be unwanted by some users. Generate a warning if that happens. If the user has JavaScript enabled, the check happens entirely client-side – a little warning box is shown, the user doesn't have to do anything. Otherwise the check happens server-side and the user has to resubmit the form. The way this is done makes it trivial to also check if the username is invalid or already taken, so let's do that. It also means that we can't check for all error conditions, e.g. these enforced by extensions – that is still handled server-side. (Client-side we intentionally never say that whatever the user typed in is valid – we only warn when we know it's not.) API behavior is unchanged. Co-Authored-By: umherirrender Co-Authored-By: Bartosz Dziewoński Bug: 34447 Bug: 61416 Change-Id: Ic461a5e597ad71b854dc65bbf8a395c0f55d1fc3 --- RELEASE-NOTES-1.23 | 4 + includes/specials/SpecialUserlogin.php | 21 +++- includes/templates/Usercreate.php | 12 +- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 3 + maintenance/language/messages.inc | 1 + resources/Resources.php | 10 +- .../mediawiki.special.userlogin.signup.js | 119 +++++++++++++++++- 8 files changed, 162 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 2b91f88f88..798d59c607 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -116,6 +116,10 @@ production. creations, similar to the topOnly option. * Add mediawiki.ui.button styling to all pages so wiki content can use styled buttons. +* Special:UserLogin/signup now does AJAX checks for invalid and taken usernames, + displaying the error live. +* Special:UserLogin/signup now warns the user if their chosen username has to be + normalized. === Bug fixes in 1.23 === * (bug 41759) The "updated since last visit" markers (on history pages, recent diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index bbe56ecca3..67e33b30b6 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -223,7 +223,7 @@ class LoginForm extends SpecialPage { $status = $this->addNewAccountInternal(); if ( !$status->isGood() ) { $error = $status->getMessage(); - $this->mainLoginForm( $error->toString() ); + $this->mainLoginForm( $error->toString(), $status->isOK() ? 'warning' : 'error' ); return; } @@ -259,7 +259,7 @@ class LoginForm extends SpecialPage { $status = $this->addNewAccountInternal(); if ( !$status->isGood() ) { $error = $status->getMessage(); - $this->mainLoginForm( $error->toString() ); + $this->mainLoginForm( $error->toString(), $status->isOK() ? 'warning' : 'error' ); return false; } @@ -401,6 +401,10 @@ class LoginForm extends SpecialPage { return Status::newFatal( 'sorbs_create_account_reason' ); } + // Leading/trailing/multiple whitespace characters are never accepted in usernames and users + // know that, don't warn if someone accidentally types it. We do warn about underscores. + $name = trim( preg_replace( '/\s+/', ' ', $this->mUsername ) ); + // Normalize the name so that silly things don't cause "invalid username" errors. // User::newFromName does some rather strict checking, rejecting e.g. leading/trailing/multiple spaces. $title = Title::makeTitleSafe( NS_USER, $this->mUsername ); @@ -408,12 +412,23 @@ class LoginForm extends SpecialPage { return Status::newFatal( 'noname' ); } - # Now create a dummy user ($u) and check if it is valid + // Now create a dummy user ($u) and check if it is valid. $u = User::newFromName( $title->getText(), 'creatable' ); + if ( !is_object( $u ) ) { return Status::newFatal( 'noname' ); } elseif ( 0 != $u->idForName() ) { return Status::newFatal( 'userexists' ); + } elseif ( $name !== $u->getName() ) { + // User name was adjusted due to technical restrictions (e.g. first letter capitalized). + // This is normally handled by a client-side check, but users with JavaScript disabled get here. + $status = Status::newGood(); + $status->warning( 'createacct-normalization', $name, $u->getName() ); + + // Set the form field to the correct name, so the user can just hit the button again. + $this->mUsername = $u->getName(); + + return $status; } if ( $this->mCreateaccountMail ) { diff --git a/includes/templates/Usercreate.php b/includes/templates/Usercreate.php index 0cb83d555e..aba0d2767c 100644 --- a/includes/templates/Usercreate.php +++ b/includes/templates/Usercreate.php @@ -58,15 +58,23 @@ class UsercreateTemplate extends BaseTemplate {
html( 'header' ); /* extensions such as ConfirmEdit add form HTML here */ ?>
+ +
data['message'] ) { ?> + class="data['messagetype']; ?>box" + + style="display: none;" + + > data['message'] ) { ?> -
data['messagetype'] == 'error' ) { ?> msg( 'createacct-error' ); ?>
html( 'message' ); ?> -
+