3 * Implements Special:Confirmemail and Special:Invalidateemail
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Special page allows users to request email confirmation message, and handles
26 * processing of the confirmation code when the link in the email is followed
28 * @ingroup SpecialPage
29 * @author Brion Vibber
30 * @author Rob Church <robchur@gmail.com>
32 class EmailConfirmation
extends UnlistedSpecialPage
{
37 public function __construct() {
38 parent
::__construct( 'Confirmemail' );
42 * Main execution point
44 * @param $code Confirmation code passed to the page
46 function execute( $code ) {
49 $this->checkReadOnly();
51 if( $code === null ||
$code === '' ) {
52 if( $this->getUser()->isLoggedIn() ) {
53 if( Sanitizer
::validateEmail( $this->getUser()->getEmail() ) ) {
54 $this->showRequestForm();
56 $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
59 $llink = Linker
::linkKnown(
60 SpecialPage
::getTitleFor( 'Userlogin' ),
61 $this->msg( 'loginreqlink' )->escaped(),
63 array( 'returnto' => $this->getTitle()->getPrefixedText() )
65 $this->getOutput()->addHTML( $this->msg( 'confirmemail_needlogin' )->rawParams( $llink )->parse() );
68 $this->attemptConfirm( $code );
73 * Show a nice form for the user to request a confirmation mail
75 function showRequestForm() {
76 $user = $this->getUser();
77 $out = $this->getOutput();
78 if( $this->getRequest()->wasPosted() && $user->matchEditToken( $this->getRequest()->getText( 'token' ) ) ) {
79 $status = $user->sendConfirmationMail();
80 if ( $status->isGood() ) {
81 $out->addWikiMsg( 'confirmemail_sent' );
83 $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
86 if( $user->isEmailConfirmed() ) {
87 // date and time are separate parameters to facilitate localisation.
88 // $time is kept for backward compat reasons.
89 // 'emailauthenticated' is also used in SpecialPreferences.php
90 $lang = $this->getLanguage();
91 $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
92 $time = $lang->userTimeAndDate( $emailAuthenticated, $user );
93 $d = $lang->userDate( $emailAuthenticated, $user );
94 $t = $lang->userTime( $emailAuthenticated, $user );
95 $out->addWikiMsg( 'emailauthenticated', $time, $d, $t );
97 if( $user->isEmailConfirmationPending() ) {
98 $out->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>", 'confirmemail_pending' );
100 $out->addWikiMsg( 'confirmemail_text' );
101 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) );
102 $form .= Html
::hidden( 'token', $user->getEditToken() );
103 $form .= Xml
::submitButton( $this->msg( 'confirmemail_send' )->text() );
104 $form .= Xml
::closeElement( 'form' );
105 $out->addHTML( $form );
110 * Attempt to confirm the user's email address and show success or failure
111 * as needed; if successful, take the user to log in
113 * @param $code string Confirmation code
115 function attemptConfirm( $code ) {
116 $user = User
::newFromConfirmationCode( $code );
117 if( is_object( $user ) ) {
118 $user->confirmEmail();
119 $user->saveSettings();
120 $message = $this->getUser()->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
121 $this->getOutput()->addWikiMsg( $message );
122 if( !$this->getUser()->isLoggedIn() ) {
123 $title = SpecialPage
::getTitleFor( 'Userlogin' );
124 $this->getOutput()->returnToMain( true, $title );
127 $this->getOutput()->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 throw new ReadOnlyError
;
152 $this->attemptInvalidate( $code );
156 * Attempt to invalidate the user's email address and show success or failure
157 * as needed; if successful, link to main page
159 * @param $code string Confirmation code
161 function attemptInvalidate( $code ) {
162 $user = User
::newFromConfirmationCode( $code );
163 if( is_object( $user ) ) {
164 $user->invalidateEmail();
165 $user->saveSettings();
166 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
167 if( !$this->getUser()->isLoggedIn() ) {
168 $this->getOutput()->returnToMain();
171 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );