* Truncate summary of page moves in revision comment field to avoid broken multibyte...
[mediawiki.git] / includes / specials / SpecialConfirmemail.php
blob372a574cef5946b303f05a6316bf5f7b8ded2b57
1 <?php
3 /**
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 * @ingroup SpecialPage
8 * @author Brion Vibber
9 * @author Rob Church <robchur@gmail.com>
11 class EmailConfirmation extends UnlistedSpecialPage {
13 /**
14 * Constructor
16 public function __construct() {
17 parent::__construct( 'Confirmemail' );
20 /**
21 * Main execution point
23 * @param $code Confirmation code passed to the page
25 function execute( $code ) {
26 global $wgUser, $wgOut;
27 $this->setHeaders();
28 if( empty( $code ) ) {
29 if( $wgUser->isLoggedIn() ) {
30 if( User::isValidEmailAddr( $wgUser->getEmail() ) ) {
31 $this->showRequestForm();
32 } else {
33 $wgOut->addWikiMsg( 'confirmemail_noemail' );
35 } else {
36 $title = SpecialPage::getTitleFor( 'Userlogin' );
37 $skin = $wgUser->getSkin();
38 $llink = $skin->linkKnown(
39 $title,
40 wfMsgHtml( 'loginreqlink' ),
41 array(),
42 array( 'returnto' => $this->getTitle()->getPrefixedText() )
44 $wgOut->addHTML( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
46 } else {
47 $this->attemptConfirm( $code );
51 /**
52 * Show a nice form for the user to request a confirmation mail
54 function showRequestForm() {
55 global $wgOut, $wgUser, $wgLang, $wgRequest;
56 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
57 $ok = $wgUser->sendConfirmationMail();
58 if ( WikiError::isError( $ok ) ) {
59 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $ok->toString() );
60 } else {
61 $wgOut->addWikiMsg( 'confirmemail_sent' );
63 } else {
64 if( $wgUser->isEmailConfirmed() ) {
65 // date and time are separate parameters to facilitate localisation.
66 // $time is kept for backward compat reasons.
67 // 'emailauthenticated' is also used in SpecialPreferences.php
68 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
69 $d = $wgLang->date( $wgUser->mEmailAuthenticated, true );
70 $t = $wgLang->time( $wgUser->mEmailAuthenticated, true );
71 $wgOut->addWikiMsg( 'emailauthenticated', $time, $d, $t );
73 if( $wgUser->isEmailConfirmationPending() ) {
74 $wgOut->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1</div>", 'confirmemail_pending' );
76 $wgOut->addWikiMsg( 'confirmemail_text' );
77 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) );
78 $form .= Xml::hidden( 'token', $wgUser->editToken() );
79 $form .= Xml::submitButton( wfMsg( 'confirmemail_send' ) );
80 $form .= Xml::closeElement( 'form' );
81 $wgOut->addHTML( $form );
85 /**
86 * Attempt to confirm the user's email address and show success or failure
87 * as needed; if successful, take the user to log in
89 * @param $code Confirmation code
91 function attemptConfirm( $code ) {
92 global $wgUser, $wgOut;
93 $user = User::newFromConfirmationCode( $code );
94 if( is_object( $user ) ) {
95 $user->confirmEmail();
96 $user->saveSettings();
97 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
98 $wgOut->addWikiMsg( $message );
99 if( !$wgUser->isLoggedIn() ) {
100 $title = SpecialPage::getTitleFor( 'Userlogin' );
101 $wgOut->returnToMain( true, $title );
103 } else {
104 $wgOut->addWikiMsg( 'confirmemail_invalid' );
111 * Special page allows users to cancel an email confirmation using the e-mail
112 * confirmation code
114 * @ingroup SpecialPage
116 class EmailInvalidation extends UnlistedSpecialPage {
118 public function __construct() {
119 parent::__construct( 'Invalidateemail' );
122 function execute( $code ) {
123 $this->setHeaders();
124 $this->attemptInvalidate( $code );
128 * Attempt to invalidate the user's email address and show success or failure
129 * as needed; if successful, link to main page
131 * @param $code Confirmation code
133 function attemptInvalidate( $code ) {
134 global $wgUser, $wgOut;
135 $user = User::newFromConfirmationCode( $code );
136 if( is_object( $user ) ) {
137 $user->invalidateEmail();
138 $user->saveSettings();
139 $wgOut->addWikiMsg( 'confirmemail_invalidated' );
140 if( !$wgUser->isLoggedIn() ) {
141 $wgOut->returnToMain();
143 } else {
144 $wgOut->addWikiMsg( 'confirmemail_invalid' );