Confirm Email before Edit

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search
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)

Contents

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

$confirmforedit = true;

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

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 );

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

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 );

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

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

Variants
Actions
Navigation
Community
Beyond the Web
Print/export
Toolbox