From 777078176f0b2a7f6f817ab4ee6a248f779bd543 Mon Sep 17 00:00:00 2001 From: csteipp Date: Thu, 28 Aug 2014 12:46:09 -0700 Subject: [PATCH] Allow extensions to indicate a username doesn't exist Provide a way for extensions to nicely handle when a username doesn't exist, during the login process. This only is obviously only for the case when we know why it doesn't exist (it was renamed, deleted, etc.) See I06b9b6322e408868f516aeabd61c6580f304e009 for CentralAuth use case. Bug: 67995 Change-Id: If48d59afa63ace68c147eca952f1d4f43acc105f --- docs/hooks.txt | 8 ++++++++ includes/specials/SpecialUserlogin.php | 18 ++++++++++++++++++ languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 4 files changed, 28 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index ad5377efb1..276d0f7b57 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -863,6 +863,14 @@ $name: name of the special page, e.g. 'Watchlist' &$join_conds: join conditions for the tables $opts: FormOptions for this request +'LoginUserMigrated': Called during login to allow extensions the opportunity to +inform a user that their username doesn't exist for a specific reason, instead +of letting the login form give the generic error message that the account does +not exist. For example, when the account has been renamed or deleted. +$user: the User object being authenticated against. +&$msg: the message identifier for abort reason, or an array to pass a message + key and parameters. + 'Collation::factory': Called if $wgCategoryCollation is an unknown collation. $collationName: Name of the collation in question &$collationObject: Null. Replace with a subclass of the Collation class that diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index afa12a018e..a34e0d828b 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -41,6 +41,7 @@ class LoginForm extends SpecialPage { const USER_BLOCKED = 11; const NEED_TOKEN = 12; const WRONG_TOKEN = 13; + const USER_MIGRATED = 14; /** * Valid error and warning messages @@ -697,6 +698,14 @@ class LoginForm extends SpecialPage { } $u = User::newFromName( $this->mUsername ); + + // Give extensions a way to indicate the username has been updated, + // rather than telling the user the account doesn't exist. + if ( !wfRunHooks( 'LoginUserMigrated', array( $u, &$msg ) ) ) { + $this->mAbortLoginErrorMsg = $msg; + return self::USER_MIGRATED; + } + if ( !( $u instanceof User ) || !User::isUsableName( $u->getName() ) ) { return self::ILLEGAL; } @@ -996,6 +1005,15 @@ class LoginForm extends SpecialPage { $this->mainLoginForm( $this->msg( $error, wfEscapeWikiText( $this->mUsername ) )->text() ); break; + case self::USER_MIGRATED: + $error = $this->mAbortLoginErrorMsg ?: 'login-migrated-generic'; + $params = array(); + if ( is_array( $error ) ) { + $error = array_shift( $this->mAbortLoginErrorMsg ); + $params = $this->mAbortLoginErrorMsg; + } + $this->mainLoginForm( $this->msg( $error, $params )->text() ); + break; default: throw new MWException( 'Unhandled case value' ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index e160327595..d358fae5a5 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -484,6 +484,7 @@ "createaccount-text": "Someone created an account for your email address on {{SITENAME}} ($4) named \"$2\", with password \"$3\".\nYou should log in and change your password now.\n\nYou may ignore this message, if this account was created in error.", "login-throttled": "You have made too many recent login attempts.\nPlease wait $1 before trying again.", "login-abort-generic": "Your login was unsuccessful - Aborted", + "login-migrated-generic": "Your account has been migrated, and your username no longer exist on this wiki.", "loginlanguagelabel": "Language: $1", "loginlanguagelinks": "* {{#language:de}}|de\n* {{#language:en}}|en\n* {{#language:eo}}|eo\n* {{#language:fr}}|fr\n* {{#language:es}}|es\n* {{#language:it}}|it\n* {{#language:nl}}|nl", "suspicious-userlogout": "Your request to log out was denied because it looks like it was sent by a broken browser or caching proxy.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index f550da6617..a8432a018e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -646,6 +646,7 @@ "createaccount-text": "Body of the email sent to the email address entered at [[Special:CreateAccount]] when one user creates an account for another and clicks the checkbox labelled:\n* {{msg-mw|Createaccountmail}}\n\nParameters:\n* $1 - (Unused) IP address\n* $2 - the name entered as username\n* $3 - a password (randomly generated)\n* $4 - a URL to the wiki ('<' + server name + script name + '>')\n* $5 - (Unused) number of days to password expiry date", "login-throttled": "Error message shown at [[Special:UserLogin]] after the user has tried to login with incorrect password too many times.\n\nThe user has to wait a certain time before trying to log in again.\n\nParameters:\n* $1 - the time to wait before the next login attempt. Automatically formatted using the following duration messages:\n** {{msg-mw|Duration-millennia}}\n** {{msg-mw|Duration-centuries}}\n** {{msg-mw|Duration-decades}}\n** {{msg-mw|Duration-years}}\n** {{msg-mw|Duration-weeks}}\n** {{msg-mw|Duration-days}}\n** {{msg-mw|Duration-hours}}\n** {{msg-mw|Duration-minutes}}\n** {{msg-mw|Duration-seconds}}\n\nThis is a protection against robots trying to find the password by trying lots of them.\nThe number of attempts and waiting time are configured via [[mw:Manual:$wgPasswordAttemptThrottle|$wgPasswordAttemptThrottle]].\nThis message is used in html.\n{{identical|Login throttled}}", "login-abort-generic": "The generic unsuccessful login message is used unless otherwise specified by hook writers", + "login-migrated-generic": "The generic unsuccessful login message when the user's account has been updated, and their username no longer exist", "loginlanguagelabel": "Used on [[Special:UserLogin]] if $wgLoginLanguageSelector is true. Parameters:\n* $1 - a pipe-separated list built from the names that appear in the message {{msg-mw|Loginlanguagelinks}}.\n{{Identical|Language}}", "loginlanguagelinks": "{{notranslate}}", "suspicious-userlogout": "Used when the logout request looks suspicious, in Special:UserLogout.", -- 2.20.1