4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * Special page allows users to request email confirmation message, and handles
22 * processing of the confirmation code when the link in the email is followed
24 * @ingroup SpecialPage
25 * @author Brion Vibber
26 * @author Rob Church <robchur@gmail.com>
28 class EmailConfirmation
extends UnlistedSpecialPage
{
33 public function __construct() {
34 parent
::__construct( 'Confirmemail' );
38 * Main execution point
40 * @param $code Confirmation code passed to the page
42 function execute( $code ) {
43 global $wgUser, $wgOut;
47 $wgOut->readOnlyPage();
51 if( empty( $code ) ) {
52 if( $wgUser->isLoggedIn() ) {
53 if( User
::isValidEmailAddr( $wgUser->getEmail() ) ) {
54 $this->showRequestForm();
56 $wgOut->addWikiMsg( 'confirmemail_noemail' );
59 $title = SpecialPage
::getTitleFor( 'Userlogin' );
60 $skin = $wgUser->getSkin();
61 $llink = $skin->linkKnown(
63 wfMsgHtml( 'loginreqlink' ),
65 array( 'returnto' => $this->getTitle()->getPrefixedText() )
67 $wgOut->addHTML( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
70 $this->attemptConfirm( $code );
75 * Show a nice form for the user to request a confirmation mail
77 function showRequestForm() {
78 global $wgOut, $wgUser, $wgLang, $wgRequest;
79 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
80 $ok = $wgUser->sendConfirmationMail();
81 if ( WikiError
::isError( $ok ) ) {
82 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $ok->toString() );
84 $wgOut->addWikiMsg( 'confirmemail_sent' );
87 if( $wgUser->isEmailConfirmed() ) {
88 // date and time are separate parameters to facilitate localisation.
89 // $time is kept for backward compat reasons.
90 // 'emailauthenticated' is also used in SpecialPreferences.php
91 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
92 $d = $wgLang->date( $wgUser->mEmailAuthenticated
, true );
93 $t = $wgLang->time( $wgUser->mEmailAuthenticated
, true );
94 $wgOut->addWikiMsg( 'emailauthenticated', $time, $d, $t );
96 if( $wgUser->isEmailConfirmationPending() ) {
97 $wgOut->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>", 'confirmemail_pending' );
99 $wgOut->addWikiMsg( 'confirmemail_text' );
100 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) );
101 $form .= Xml
::hidden( 'token', $wgUser->editToken() );
102 $form .= Xml
::submitButton( wfMsg( 'confirmemail_send' ) );
103 $form .= Xml
::closeElement( 'form' );
104 $wgOut->addHTML( $form );
109 * Attempt to confirm the user's email address and show success or failure
110 * as needed; if successful, take the user to log in
112 * @param $code Confirmation code
114 function attemptConfirm( $code ) {
115 global $wgUser, $wgOut;
116 $user = User
::newFromConfirmationCode( $code );
117 if( is_object( $user ) ) {
118 $user->confirmEmail();
119 $user->saveSettings();
120 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
121 $wgOut->addWikiMsg( $message );
122 if( !$wgUser->isLoggedIn() ) {
123 $title = SpecialPage
::getTitleFor( 'Userlogin' );
124 $wgOut->returnToMain( true, $title );
127 $wgOut->addWikiMsg( 'confirmemail_invalid' );
134 * Special page allows users to cancel an email confirmation using the e-mail
137 * @ingroup SpecialPage
139 class EmailInvalidation
extends UnlistedSpecialPage
{
141 public function __construct() {
142 parent
::__construct( 'Invalidateemail' );
145 function execute( $code ) {
148 if ( wfReadOnly() ) {
149 $wgOut->readOnlyPage();
153 $this->attemptInvalidate( $code );
157 * Attempt to invalidate the user's email address and show success or failure
158 * as needed; if successful, link to main page
160 * @param $code Confirmation code
162 function attemptInvalidate( $code ) {
163 global $wgUser, $wgOut;
164 $user = User
::newFromConfirmationCode( $code );
165 if( is_object( $user ) ) {
166 $user->invalidateEmail();
167 $user->saveSettings();
168 $wgOut->addWikiMsg( 'confirmemail_invalidated' );
169 if( !$wgUser->isLoggedIn() ) {
170 $wgOut->returnToMain();
173 $wgOut->addWikiMsg( 'confirmemail_invalid' );