Extension:ConfirmUsersEmail

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Confirm Users Email

Release status: stable

Implementation User identity, Special page
Description Allows bureaucrats to set other users as emailconfirmed
Author(s) Ryan Schmidt (Skizzerz Talk)
Version 2.0
MediaWiki 1.9+, may work for earlier versions
Download Download
Usage
Added rights confirmusersemail, setemail

Contents

[edit] What can this extension do?

This extension allows anyone with the confirmusersemail permission (Bureaucrat by default) to set other users emailconfirmed while not revealing said user's email address. This is not logged, but an email is sent to the user being emailconfirmed. Also, if you set the setemail right, users with that right can use this form to view and set email addresses as well.

[edit] Usage

Visit Special:ConfirmUsersEmail, type in a username, click the confirm button, and you've just confirmed their email! Easy as that. If they don't have an email specified or if they already have a confirmed email address, you will be shown an error message (unless you have the setemail right, in which case you can set the email address).

[edit] Download instructions

Please copy and paste the code found below into three new php text files (named accordingly), then place them in $IP/extension/ConfirmUsersEmail/ConfirmUsersEmail.php, $IP/extension/ConfirmUsersEmail/ConfirmUsersEmail.page.php, and $IP/extension/ConfirmUsersEmail/ConfirmUsersEmail.i18n.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/ConfirmUsersEmail/ConfirmUsersEmail.php");

[edit] User rights

confirmuseremail is the permission used to control access to the special page. By default, it is given to bureaucrats. If you wish to change this, please modify the $wgGroupPermissions line in ConfirmUsersEmail.php and change the 'bureaucrat' to another group.

setemail is the permissions used to control whether or not one can view and change email addresses. By default, nobody has this, but you can uncomment the line in ConfirmUsersEmail.php to give it to bureaucrats (or change 'bureaucrat' to another group).

[edit] Code

[edit] ConfirmUsersEmail.php

<?php
 
/**
* Special page to confirm a user's email address
* The user must have an email address specified for this to work
* (really this should only be used in lieu of the link in the email when the email isn't getting through)
* No logging is performed. Instead, an email is sent to that user notifying them of the confirmation.
*/
 
if( !defined( 'MEDIAWIKI' ) ) {
        echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
        die( 1 );
}
 
$wgExtensionCredits['specialpage'][] = array(
'name' => 'Confirm Users Email',
'author' => 'Ryan Schmidt',
'url' => 'http://www.mediawiki.org/wiki/Extension:ConfirmUsersEmail',
'version' => '2.0',
'description' => 'Allows bureaucrats to set other users as emailconfirmed',
);
$wgAutoloadClasses['ConfirmUsersEmail'] = dirname( __FILE__ ) . '/ConfirmUsersEmail.page.php';
$wgSpecialPages['ConfirmUsersEmail'] = 'ConfirmUsersEmail';
$wgAvailableRights[] = 'confirmusersemail';
 
$wgExtensionFunctions[] = 'efConfirmUsersEmail';
 
/**
* Determines who can use the extension; as a default, bureaucrats are permitted
*/
$wgGroupPermissions['bureaucrat']['confirmusersemail'] = true;
//Allows other users to set and change (and view) email addresses of other users
#$wgGroupPermissions['bureaucrat']['setemail'] = true;
 
/**
* Populate the message cache and register the special page
*/
function efConfirmUsersEmail() {
        global $wgMessageCache;
        require_once( dirname( __FILE__ ) . '/ConfirmUsersEmail.i18n.php' );
        foreach( efConfirmUsersEmailMessages() as $lang => $messages )
        $wgMessageCache->addMessages( $messages, $lang );
}

[edit] ConfirmUsersEmail.page.php

<?php
 
/**
* Class definition for the ConfirmUsersEmail special page
*/
 
class ConfirmUsersEmail extends SpecialPage {
        var $target = '';
 
        /**
        * Constructor
        */
        function ConfirmUsersEmail() {
                SpecialPage::SpecialPage( 'ConfirmUsersEmail', 'confirmusersemail' );
        }
 
        /**
        * Main execution function
        */
        function execute( $par ) {
                global $wgRequest, $wgOut, $wgUser;
 
                if( !$wgUser->isAllowed( 'confirmusersemail' ) ) {
                        $wgOut->permissionRequired( 'confirmusersemail' );
                        return;
                }
 
                $this->setHeaders();
 
                $this->target = $par
                                                ? $par
                                                : $wgRequest->getText( 'username', '' );
 
                $wgOut->addWikiText( wfMsg( 'confirmusersemail-header' ) );
                $wgOut->addHtml( $this->makeGrantForm() );
 
                if( $this->target != '' ) {
                        $wgOut->addHtml( wfElement( 'p', NULL, NULL ) );
                        $user = User::newFromName( $this->target );
                        if( is_object( $user ) && !is_null( $user ) ) {
                                $user->load();
                                # Valid username, check existence
                                if( $user->getID() ) {
                                        if($wgRequest->getCheck('setemail') && $wgUser->isAllowed('setemail') && $wgUser->isValidEmailAddr($wgRequest->getText('email', ''))) {
                                                $user->setEmail($wgRequest->getText('email', ''));
                                                $user->confirmEmail();
                                                $user->sendMail( wfMsg( 'confirmusersemail-sendsubject' ), wfMsg( 'confirmusersemail-sendbody', $wgUser->getName() ) );
                                                $wgOut->addWikiText( wfMsg( 'confirmusersemail-success', $user->getName() ) );
                                        }
                                        # Exists; check to see if they have an email address
                                        if( $user->getEmail() ) {
                                                # They do; check to see if they are already emailconfirmed
                                                if( !$user->isAllowed( 'emailconfirmed' ) ) {
                                                        #They aren't; confirm email address
                                                        $user->confirmEmail();
                                                        $user->sendMail( wfMsg( 'confirmusersemail-sendsubject' ), wfMsg( 'confirmusersemail-sendbody', $wgUser->getName() ) );
                                                        $wgOut->addWikiText( wfMsg( 'confirmusersemail-success', $user->getName() ) );
                                                } else {
                                                        #already confirmed, can we set a new one?
                                                        if($wgUser->isAllowed('setemail')) {
                                                                $wgOut->addWikiText( wfMsg( 'confirmusersemail-setconfirmed', $user->getEmail() ) );
                                                                $wgOut->addHtml( $this->makeSetForm() );
                                                        } else {
                                                                $wgOut->addWikiText( wfMsg( 'confirmusersemail-alreadyconfirmed', $user->getName() ) );
                                                        }
                                                }
                                        } else {
                                                # No email specified, does the user have the ability to set a new one?
                                                if($wgUser->isAllowed('setemail')) {
                                                        $wgOut->addWikiText( wfMsg( 'confirmusersemail-setemail' ) );
                                                        $wgOut->addHtml( $this->makeSetForm() );
                                                } else {
                                                        $wgOut->addWikiText( wfMsg( 'confirmusersemail-noemail', $user->getName() ) );
                                                }
                                        }
                                } else {
                                        # Doesn't exist
                                        $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $this->target ) ) );
                                }
                        } else {
                                # Invalid username
                                $wgOut->addWikiText( wfMsg( 'noname' ) );
                        }
                }
        }
 
        /**
        * Produce a form to allow for entering a user and confirming their email address
        */
        function makeGrantForm() {
                $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
                $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
                $form .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'confirmusersemail-username' ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'username', 'id' => 'username', 'value' => $this->target ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'submit', 'name' => 'confirm', 'value' => wfMsg( 'confirmusersemail-confirm' ) ) );
                $form .= wfCloseElement( 'form' );
                return $form;
        }
 
        /**
        * Produce a form to allow setting a user's email address
        */
 
        function makeSetForm() {
                $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
                $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
                $form .= wfElement( 'label', array( 'for' => 'email' ), wfMsg( 'confirmusersemail-email' ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'email', 'id' => 'email', 'value' => $this->email ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'username', 'id' => 'username', 'value' => $this->target ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'submit', 'name' => 'setemail', 'value' => wfMsg( 'confirmusersemail-set' ) ) );
                $form .= wfCloseElement( 'form' );
                return $form;
        }
}

[edit] ConfirmUsersEmail.i18n.php

<?php
 
/**
* Internationalisation file for the ConfirmUsersEmail extension
* If you are good at translating messages, please contact me :)
*/
 
function efConfirmUsersEmailMessages() {
$messages = array(
 
/* English (Ryan Schmidt) */
'en' => array(
'confirmusersemail' => 'Confirm Email Addresses',
'confirmusersemail-header' => 'You may use this form to confirm a user\'s email address. Actions here are not logged publicly, but the user will be notified via email that their address got confirmed.',
'confirmusersemail-username' => 'Username',
'confirmusersemail-confirm' => 'Confirm Email',
'confirmusersemail-sendsubject' => 'Email Address Confirmed',
'confirmusersemail-sendbody' => 'Your email address was confirmed by $1.',
'confirmusersemail-success' => 'Email address for [[User:$1|$1]] successfully confirmed',
'confirmusersemail-alreadyconfirmed' => '[[User:$1|$1]] already has a confirmed email address',
'confirmusersemail-setconfirmed' => 'This user already has a confirmed email address ($1), you may use the form below to change it',
'confirmusersemail-noemail' => '[[User:$1|$1]] has not specified an email address in their Preferences',
'confirmusersemail-setemail' => 'This user does not currently have an email address specified. If you wish to set one, you may do so using the form below.',
'confirmusersemail-email' => 'Email address',
'confirmusersemail-set' => 'Set and Confirm Email',
),
 
/* deutsch (Thilo Graf) */
'de' => array(
'confirmusersemail' => 'e-Mail bestätigen',
'confirmusersemail-header' => 'Sie können dieses Formular verwenden, um die E-Mail-Adresse der Nutzer zu bestätigen. Dies erfolgt nicht öffentlich, sondern der Benutzer wird per E-Mail benachrichtigt, dass die Adresse  bestätigt wurde.',
'confirmusersemail-username' => 'Benutzername',
'confirmusersemail-confirm' => 'bestätige Email',
'confirmusersemail-sendsubject' => 'Email-Adresse bestätigt',
'confirmusersemail-sendbody' => 'Ihre Email Addresse wurde bestätigt für $1.',
'confirmusersemail-success' => 'Email Addresse für [[User:$1|$1]] erfolgreich bestätigt',
'confirmusersemail-alreadyconfirmed' => '[[User:$1|$1]] hat seine Email-Adresse bereits bestätigt',
'confirmusersemail-setconfirmed' => 'Dieser Benutzer hat bereits eine Email-Adresse bestätigt ($1), Sie können das Formular dazu verwenden, um Änderungen vorzunehmen',
'confirmusersemail-noemail' => '[[User:$1|$1]] hat keine E-Mail-Adresse in seinen Einstellungen angegeben',
'confirmusersemail-setemail' => 'Dieser Benutzer hat bisher keine E-Mail-Adresse in seinen Einstellungen angegeben. Wenn Sie möchten, können Sie dies mit dem unten stehenden Formular tun.',
'confirmusersemail-email' => 'Email Adresse',
'confirmusersemail-set' => 'Angeben und bestätigen der E-Mail-Adresse',
), 
 
);
 
return $messages;
 
}
Personal tools