From 9c83db2dac46935f6b66cac7babc44a4d4a8a074 Mon Sep 17 00:00:00 2001 From: Nick Jenkins Date: Thu, 11 Oct 2007 07:11:51 +0000 Subject: [PATCH] Tighten up the handling of $wgEmailConfirmToEdit , plus related functionality: * Bug 11620 - Added call to User::isValidEmailAddr during accout creation. * Bug 11629 - If $wgEmailConfirmToEdit is true, require people to supply an email address when registering. * adding "prefs-help-email-required" message (which says an email address is required) to complement the existing "prefs-help-email" (which says an email address is optional). The former makes sense when $wgEmailConfirmToEdit is true, whereas the latter makes sense for the default behaviour (which is for $wgEmailConfirmToEdit to be false). * Using the "prefs-help-email-required" message in Special:Userlogin and Special:Preferences when it makes sense to do so. * Removing EditPage::userNotConfirmedPage() - as far as I can tell, it is not being used internally, or by any extensions. Furthermore, its functionality is superceded by the $wgEmailConfirmToEdit global and the check on it in Title.php --- RELEASE-NOTES | 4 ++++ includes/EditPage.php | 16 ---------------- includes/SpecialPreferences.php | 9 +++++++-- includes/SpecialUserlogin.php | 15 ++++++++++++++- includes/Title.php | 2 +- includes/templates/Userlogin.php | 6 +++++- languages/messages/MessagesEn.php | 1 + 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c61d452554..f0a23a18a0 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -94,6 +94,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Do not cache category pages if using 'from' or 'until' * Created new hook getUserPermissionsErrors, to go with userCan changes. * Diff pages did not properly display css/js pages. +* (bug 11620) Add call to User::isValidEmailAddr during accout creation. +* (bug 11629) If $wgEmailConfirmToEdit is true, require people to supply an + email address when registering. + === API changes in 1.12 === diff --git a/includes/EditPage.php b/includes/EditPage.php index 3a19c45304..ad5c759f26 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1496,22 +1496,6 @@ END $wgOut->returnToMain( false, $this->mTitle ); } - /** - * Creates a basic error page which informs the user that - * they have to validate their email address before being - * allowed to edit. - */ - function userNotConfirmedPage() { - global $wgOut; - - $wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->setArticleRelated( false ); - - $wgOut->addWikiText( wfMsg( 'confirmedittext' ) ); - $wgOut->returnToMain( false, $this->mTitle ); - } - /** * Creates a basic error page which informs the user that * they have attempted to edit a nonexistant section. diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index a36be28988..851eda25f4 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -208,7 +208,7 @@ class PreferencesForm { global $wgUser, $wgOut, $wgParser; global $wgEnableUserEmail, $wgEnableEmail; global $wgEmailAuthentication; - global $wgAuth; + global $wgAuth, $wgEmailConfirmToEdit; if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) { @@ -338,6 +338,10 @@ class PreferencesForm { $error = wfMsg( 'invalidemailaddress' ); } } else { + if( $wgEmailConfirmToEdit && empty( $newadr ) ) { + $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) ); + return; + } $wgUser->setEmail( $this->mUserEmail ); $wgUser->setCookies(); $wgUser->saveSettings(); @@ -510,6 +514,7 @@ class PreferencesForm { global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress; global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication; global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth; + global $wgEmailConfirmToEdit; $wgOut->setPageTitle( wfMsg( 'preferences' ) ); $wgOut->setArticleRelated( false ); @@ -619,7 +624,7 @@ class PreferencesForm { Xml::label( wfMsg('youremail'), 'wpUserEmail' ), Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ), Xml::tags('div', array( 'class' => 'prefsectiontip' ), - wfMsgExt( 'prefs-help-email', 'parseinline' ) + wfMsgExt( $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email', 'parseinline' ) ) ) ); diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 7ddb723775..4b099f0f41 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -203,6 +203,7 @@ class LoginForm { global $wgEnableSorbs, $wgProxyWhitelist; global $wgMemc, $wgAccountCreationThrottle; global $wgAuth, $wgMinimalPasswordLength; + global $wgEmailConfirmToEdit; // If the user passes an invalid domain, something is fishy if( !$wgAuth->validDomain( $this->mDomain ) ) { @@ -268,6 +269,17 @@ class LoginForm { return false; } + # if you need a confirmed email address to edit, then obviously you need an email address. + if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) { + $this->mainLoginForm( wfMsg( 'noemailtitle' ) ); + return false; + } + + if( !empty( $this->mEmail ) && !User::isValidEmailAddr( $this->mEmail ) ) { + $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) ); + return false; + } + # Set some additional data so the AbortNewAccount hook can be # used for more than just username validation $u->setEmail( $this->mEmail ); @@ -627,7 +639,7 @@ class LoginForm { function mainLoginForm( $msg, $msgtype = 'error' ) { global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail; global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector; - global $wgAuth; + global $wgAuth, $wgEmailConfirmToEdit; if ( $this->mType == 'signup' ) { if ( !$wgUser->isAllowed( 'createaccount' ) ) { @@ -695,6 +707,7 @@ class LoginForm { $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() ); $template->set( 'userealname', $wgAllowRealName ); $template->set( 'useemail', $wgEnableEmail ); + $template->set( 'emailrequired', $wgEmailConfirmToEdit ); $template->set( 'canreset', $wgAuth->allowPasswordChange() ); $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember ); diff --git a/includes/Title.php b/includes/Title.php index 15be69bd9b..5a6226131f 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1029,7 +1029,7 @@ class Title { * @param string $action action that permission needs to be checked for * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries. * @return array Array of arrays of the arguments to wfMsg to explain permissions problems. - */ + */ public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) { $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries ); diff --git a/includes/templates/Userlogin.php b/includes/templates/Userlogin.php index e2eb19e731..ac24800af5 100644 --- a/includes/templates/Userlogin.php +++ b/includes/templates/Userlogin.php @@ -166,7 +166,11 @@ class UsercreateTemplate extends QuickTemplate { tabindex="5" value="text('email') ?>" size='20' />
- msgWiki('prefs-help-email'); ?> + data['emailrequired'] ) { + $this->msgWiki('prefs-help-email-required'); + } else { + $this->msgWiki('prefs-help-email'); + } ?>
diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 37d3803e8a..461d864ac7 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -849,6 +849,7 @@ Your account has been created. Don't forget to change your {{SITENAME}} preferen 'prefs-help-realname' => 'Real name is optional and if you choose to provide it this will be used for giving you attribution for your work.', 'loginerror' => 'Login error', 'prefs-help-email' => 'E-mail address is optional, but it enables others to contact you through your user or user_talk page without needing to reveal your identity.', +'prefs-help-email-required' => 'E-mail address is required.', 'nocookiesnew' => 'The user account was created, but you are not logged in. {{SITENAME}} uses cookies to log in users. You have cookies disabled. Please enable them, then log in with your new username and password.', 'nocookieslogin' => '{{SITENAME}} uses cookies to log in users. You have cookies disabled. Please enable them and try again.', 'noname' => 'You have not specified a valid user name.', -- 2.20.1