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 SpecialPage
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 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
38 $skin = $wgUser->getSkin();
39 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->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 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
62 $wgOut->addWikiMsg( 'emailauthenticated', $time );
64 if( $wgUser->isEmailConfirmationPending() ) {
65 $wgOut->addWikiMsg( 'confirmemail_pending' );
67 $wgOut->addWikiMsg( 'confirmemail_text' );
68 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
69 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
70 $form .= wfHidden( 'token', $wgUser->editToken() );
71 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
72 $form .= wfCloseElement( 'form' );
73 $wgOut->addHtml( $form );
78 * Attempt to confirm the user's email address and show success or failure
79 * as needed; if successful, take the user to log in
81 * @param $code Confirmation code
83 function attemptConfirm( $code ) {
84 global $wgUser, $wgOut;
85 $user = User
::newFromConfirmationCode( $code );
86 if( is_object( $user ) ) {
87 $user->confirmEmail();
88 $user->saveSettings();
89 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
90 $wgOut->addWikiMsg( $message );
91 if( !$wgUser->isLoggedIn() ) {
92 $title = SpecialPage
::getTitleFor( 'Userlogin' );
93 $wgOut->returnToMain( true, $title );
96 $wgOut->addWikiMsg( 'confirmemail_invalid' );
103 * Special page allows users to cancel an email confirmation using the e-mail
106 * @addtogroup SpecialPage
108 class EmailInvalidation
extends UnlistedSpecialPage
{
110 public function __construct() {
111 parent
::__construct( 'Invalidateemail' );
114 function execute( $code ) {
116 $this->attemptInvalidate( $code );
120 * Attempt to invalidate the user's email address and show success or failure
121 * as needed; if successful, link to main page
123 * @param $code Confirmation code
125 function attemptInvalidate( $code ) {
126 global $wgUser, $wgOut;
127 $user = User
::newFromConfirmationCode( $code );
128 if( is_object( $user ) ) {
129 $user->invalidateEmail();
130 $user->saveSettings();
131 $wgOut->addWikiMsg( 'confirmemail_invalidated' );
132 if( !$wgUser->isLoggedIn() ) {
133 $wgOut->returnToMain();
136 $wgOut->addWikiMsg( 'confirmemail_invalid' );