Extension talk:Email required to sign up

The following discussion has been transferred from Meta-Wiki.
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).

$wgUserAccountEmailRequired

edit
  • MediaWiki version: 1.8.2

I was trying to require an e-mail address and thought a simple variable could be added to accommodate this need in a generic way.

  • LocalSettings.php
$wgUserAccountEmailRequired = true;
  • Mod's made to the login to require e-mail address - includes/specials/SpecialUserlogin.php:
    251                 if ( $wgUserAccountEmailRequired ) {
    252                         if (!$this->mEmail) {
    253                                 $this->mainLoginForm( wfMsg( 'noemailonsignup' ) );
    254                                 return false;
    255                         } elseif (! User::isValidEmailAddr( $this->mEmail ) ) {
    256                                 $this->mainLoginForm( wfMsg( 'invalidemailonsignup' ) );
    257                                 return false;
    258                         }
    259                 }
  • Here's the error message - languages/messages/MessagesEn.php :
    694 'noemailonsignup'       => 'An email address is required to sign up.',
    695 'invalidemailonsignup'  => 'A valid email address is required to sign up.',

Restrict a User's e-mail address by Pattern

edit

I also wanted the ability to have users create their own accounts, but limit it to certain domains. To accommodate this, I had to change the User::isValidEmailAddr method to take check to see if a variable was set. If it is, then it should be an array and it should contain regular expression to match on.

  • Here's the change I made to includes/User.php:
    365         function isValidEmailAddr ( $addr ) {
    366                 global $wgUserAccountEmailPattern;
    367                 $valid = false;
    368                 if ( $wgUserAccountEmailPattern ) {
    369                         foreach ($wgUserAccountEmailPattern as $regex) {
    370                                 $re = '/^' . "$regex" . '$/';
    371                                 $valid = preg_match( $re, strtolower($addr));
    372                                 if ( $valid ) {
    373                                         break;
    374                                 }
    375                         }
    376                 } else {
    377                         $valid = ( trim( $addr ) != '' ) && (false !== strpos( $addr, '@' ) );
    378                 }
    379 
    380                 return $valid;
    381         }
  • Example LocalSettings.php to restrict addresses to *@gmail.com & *@yahoo.com :
  $wgUserAccountEmailPattern = array( '.*@gmail\.com', '.*@yahoo\.com' );
Return to "Email required to sign up" page.