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
9 * @author Rob Church <robchur@gmail.com>
11 class EmailConfirmation
extends UnlistedSpecialPage
{
16 public function __construct() {
17 parent
::__construct( 'Confirmemail' );
21 * Main execution point
23 * @param $code Confirmation code passed to the page
25 function execute( $code ) {
26 global $wgUser, $wgOut;
28 if( empty( $code ) ) {
29 if( $wgUser->isLoggedIn() ) {
30 if( User
::isValidEmailAddr( $wgUser->getEmail() ) ) {
31 $this->showRequestForm();
33 $wgOut->addWikiMsg( 'confirmemail_noemail' );
36 $title = SpecialPage
::getTitleFor( 'Userlogin' );
37 $skin = $wgUser->getSkin();
38 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ),
39 'returnto=' . $this->getTitle()->getPrefixedUrl() );
40 $wgOut->addHTML( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
43 $this->attemptConfirm( $code );
48 * Show a nice form for the user to request a confirmation mail
50 function showRequestForm() {
51 global $wgOut, $wgUser, $wgLang, $wgRequest;
52 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
53 $ok = $wgUser->sendConfirmationMail();
54 if ( WikiError
::isError( $ok ) ) {
55 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $ok->toString() );
57 $wgOut->addWikiMsg( 'confirmemail_sent' );
60 if( $wgUser->isEmailConfirmed() ) {
61 // date and time are separate parameters to facilitate localisation.
62 // $time is kept for backward compat reasons.
63 // 'emailauthenticated' is also used in SpecialPreferences.php
64 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
65 $d = $wgLang->date( $wgUser->mEmailAuthenticated
, true );
66 $t = $wgLang->time( $wgUser->mEmailAuthenticated
, true );
67 $wgOut->addWikiMsg( 'emailauthenticated', $time, $d, $t );
69 if( $wgUser->isEmailConfirmationPending() ) {
70 $wgOut->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">$1</div>", 'confirmemail_pending' );
72 $wgOut->addWikiMsg( 'confirmemail_text' );
73 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) );
74 $form .= Xml
::hidden( 'token', $wgUser->editToken() );
75 $form .= Xml
::submitButton( wfMsg( 'confirmemail_send' ) );
76 $form .= Xml
::closeElement( 'form' );
77 $wgOut->addHTML( $form );
82 * Attempt to confirm the user's email address and show success or failure
83 * as needed; if successful, take the user to log in
85 * @param $code Confirmation code
87 function attemptConfirm( $code ) {
88 global $wgUser, $wgOut;
89 $user = User
::newFromConfirmationCode( $code );
90 if( is_object( $user ) ) {
91 $user->confirmEmail();
92 $user->saveSettings();
93 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
94 $wgOut->addWikiMsg( $message );
95 if( !$wgUser->isLoggedIn() ) {
96 $title = SpecialPage
::getTitleFor( 'Userlogin' );
97 $wgOut->returnToMain( true, $title );
100 $wgOut->addWikiMsg( 'confirmemail_invalid' );
107 * Special page allows users to cancel an email confirmation using the e-mail
110 * @ingroup SpecialPage
112 class EmailInvalidation
extends UnlistedSpecialPage
{
114 public function __construct() {
115 parent
::__construct( 'Invalidateemail' );
118 function execute( $code ) {
120 $this->attemptInvalidate( $code );
124 * Attempt to invalidate the user's email address and show success or failure
125 * as needed; if successful, link to main page
127 * @param $code Confirmation code
129 function attemptInvalidate( $code ) {
130 global $wgUser, $wgOut;
131 $user = User
::newFromConfirmationCode( $code );
132 if( is_object( $user ) ) {
133 $user->invalidateEmail();
134 $user->saveSettings();
135 $wgOut->addWikiMsg( 'confirmemail_invalidated' );
136 if( !$wgUser->isLoggedIn() ) {
137 $wgOut->returnToMain();
140 $wgOut->addWikiMsg( 'confirmemail_invalid' );