4 * Special page allows users to request email confirmation message, and handles
5 * processing of the confirmation code when the link in the email is followed
7 * @addtogroup Special pages
8 * @author Rob Church <robchur@gmail.com>
12 * Main execution point
14 * @param $par Parameters passed to the page
16 function wfSpecialConfirmemail( $par ) {
17 $form = new EmailConfirmation();
18 $form->execute( $par );
21 class EmailConfirmation
extends SpecialPage
{
24 * Main execution point
26 * @param $code Confirmation code passed to the page
28 function execute( $code ) {
29 global $wgUser, $wgOut;
30 if( empty( $code ) ) {
31 if( $wgUser->isLoggedIn() ) {
32 if( User
::isValidEmailAddr( $wgUser->getEmail() ) ) {
33 $this->showRequestForm();
35 $wgOut->addWikiText( wfMsg( 'confirmemail_noemail' ) );
38 $title = SpecialPage
::getTitleFor( 'Userlogin' );
39 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
40 $skin = $wgUser->getSkin();
41 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
42 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
45 $this->attemptConfirm( $code );
50 * Show a nice form for the user to request a confirmation mail
52 function showRequestForm() {
53 global $wgOut, $wgUser, $wgLang, $wgRequest;
54 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
55 $ok = $wgUser->sendConfirmationMail();
56 if ( WikiError
::isError( $ok ) ) {
57 $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $ok->toString() ) );
59 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
62 if( $wgUser->isEmailConfirmed() ) {
63 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
64 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
66 if( $wgUser->isEmailConfirmationPending() ) {
67 $wgOut->addWikiText( wfMsg( 'confirmemail_pending' ) );
69 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
70 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
71 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
72 $form .= wfHidden( 'token', $wgUser->editToken() );
73 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
74 $form .= wfCloseElement( 'form' );
75 $wgOut->addHtml( $form );
80 * Attempt to confirm the user's email address and show success or failure
81 * as needed; if successful, take the user to log in
83 * @param $code Confirmation code
85 function attemptConfirm( $code ) {
86 global $wgUser, $wgOut;
87 $user = User
::newFromConfirmationCode( $code );
88 if( is_object( $user ) ) {
89 if( $user->confirmEmail() ) {
90 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
91 $wgOut->addWikiText( wfMsg( $message ) );
92 if( !$wgUser->isLoggedIn() ) {
93 $title = SpecialPage
::getTitleFor( 'Userlogin' );
94 $wgOut->returnToMain( true, $title->getPrefixedText() );
97 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
100 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );