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;
30 $wgOut->readOnlyPage();
34 if( empty( $code ) ) {
35 if( $wgUser->isLoggedIn() ) {
36 if( User
::isValidEmailAddr( $wgUser->getEmail() ) ) {
37 $this->showRequestForm();
39 $wgOut->addWikiMsg( 'confirmemail_noemail' );
42 $title = SpecialPage
::getTitleFor( 'Userlogin' );
43 $skin = $wgUser->getSkin();
44 $llink = $skin->linkKnown(
46 wfMsgHtml( 'loginreqlink' ),
48 array( 'returnto' => $this->getTitle()->getPrefixedText() )
50 $wgOut->addHTML( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
53 $this->attemptConfirm( $code );
58 * Show a nice form for the user to request a confirmation mail
60 function showRequestForm() {
61 global $wgOut, $wgUser, $wgLang, $wgRequest;
62 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
63 $ok = $wgUser->sendConfirmationMail();
64 if ( WikiError
::isError( $ok ) ) {
65 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $ok->toString() );
67 $wgOut->addWikiMsg( 'confirmemail_sent' );
70 if( $wgUser->isEmailConfirmed() ) {
71 // date and time are separate parameters to facilitate localisation.
72 // $time is kept for backward compat reasons.
73 // 'emailauthenticated' is also used in SpecialPreferences.php
74 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
75 $d = $wgLang->date( $wgUser->mEmailAuthenticated
, true );
76 $t = $wgLang->time( $wgUser->mEmailAuthenticated
, true );
77 $wgOut->addWikiMsg( 'emailauthenticated', $time, $d, $t );
79 if( $wgUser->isEmailConfirmationPending() ) {
80 $wgOut->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1</div>", 'confirmemail_pending' );
82 $wgOut->addWikiMsg( 'confirmemail_text' );
83 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) );
84 $form .= Xml
::hidden( 'token', $wgUser->editToken() );
85 $form .= Xml
::submitButton( wfMsg( 'confirmemail_send' ) );
86 $form .= Xml
::closeElement( 'form' );
87 $wgOut->addHTML( $form );
92 * Attempt to confirm the user's email address and show success or failure
93 * as needed; if successful, take the user to log in
95 * @param $code Confirmation code
97 function attemptConfirm( $code ) {
98 global $wgUser, $wgOut;
99 $user = User
::newFromConfirmationCode( $code );
100 if( is_object( $user ) ) {
101 $user->confirmEmail();
102 $user->saveSettings();
103 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
104 $wgOut->addWikiMsg( $message );
105 if( !$wgUser->isLoggedIn() ) {
106 $title = SpecialPage
::getTitleFor( 'Userlogin' );
107 $wgOut->returnToMain( true, $title );
110 $wgOut->addWikiMsg( 'confirmemail_invalid' );
117 * Special page allows users to cancel an email confirmation using the e-mail
120 * @ingroup SpecialPage
122 class EmailInvalidation
extends UnlistedSpecialPage
{
124 public function __construct() {
125 parent
::__construct( 'Invalidateemail' );
128 function execute( $code ) {
131 if ( wfReadOnly() ) {
132 $wgOut->readOnlyPage();
136 $this->attemptInvalidate( $code );
140 * Attempt to invalidate the user's email address and show success or failure
141 * as needed; if successful, link to main page
143 * @param $code Confirmation code
145 function attemptInvalidate( $code ) {
146 global $wgUser, $wgOut;
147 $user = User
::newFromConfirmationCode( $code );
148 if( is_object( $user ) ) {
149 $user->invalidateEmail();
150 $user->saveSettings();
151 $wgOut->addWikiMsg( 'confirmemail_invalidated' );
152 if( !$wgUser->isLoggedIn() ) {
153 $wgOut->returnToMain();
156 $wgOut->addWikiMsg( 'confirmemail_invalid' );