Open main menu

Confirm Email before Edit

Ambox outdated content.svg

This page is outdated.
Please see Manual:$wgEmailConfirmToEdit on MediaWiki.org for more up to date informations.

MediaWiki logo

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)

Add a variable to LocalSettings.php for easy on/offEdit

$confirmforedit = true;

Create the group when necessary in User.phpEdit

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.phpEdit

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.phpEdit

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() ) {