Confirm Email before Edit

From Meta, a Wikimedia project coordination wiki

I received a question about forcing a user to confirm their email before allowing them to edit, so I created this hack. It adds the user to the group "unconfirmed" and checks that group before allowing them to edit. Once they click the confirmation link in their email, the user is removed from the "unconfirmed" group. --MHart 15:24, 14 August 2006 (UTC)[reply]

Add a variable to LocalSettings.php for easy on/off[edit]

$confirmforedit = true;

Create the group when necessary in User.php[edit]

Find

function sendConfirmationMail() {

then find the OLD code:

global $wgContLang;
$url = $this->confirmationTokenUrl( $expiration );

and replace with this NEW code:

global $wgContLang;
# BEGIN added section
global $confirmforedit;
if ($confirmforedit) {
    if (in_array('unconfirmed',$this->mGroups)) {
    } else {
        $this->addGroup('unconfirmed');  
    }
}
# END added section
$url = $this->confirmationTokenUrl( $expiration );

Check for the group when editing in User.php[edit]

Find

function isAllowed($action='') {

then find the OLD code:

$this->loadFromDatabase();
return in_array( $action , $this->mRights );

and replace with this NEW code:

$this->loadFromDatabase();
# BEGIN added section
global $confirmforedit;
if ($confirmforedit) {
    if (in_array('unconfirmed',$this->mGroups))
    {
        if ($action == 'edit')             
            return false;
    }
}
# END added section
return in_array( $action , $this->mRights );

Reset the group once the email has been confirmed in SpecialConfirmemail.php[edit]

Find

function attemptConfirm( $code ) { 

then find the OLD code:

if( $user->confirmEmail() ) {
       $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
       $wgOut->addWikiText( wfMsg( $message ) );
       if( !$wgUser->isLoggedIn() ) {

and replace with this NEW code:

if( $user->confirmEmail() ) {
       $wgUser->setLoaded( false );     # ADDED LINE
       $wgUser->loadFromDatabase();     # ADDED LINE (without these two first lines,
                                        # saveSettings in removeGroup erase the mail confirmation timestamp Thetiti42 14:09, 30 March 2007 (UTC))
       $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
       $wgOut->addWikiText( wfMsg( $message ) );
       $wgUser->removeGroup('unconfirmed');     # ADDED LINE
       if( !$wgUser->isLoggedIn() ) {[reply]