]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/SpecialConfirmemail.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / includes / SpecialConfirmemail.php
1 <?php
2
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
6  *
7  * @addtogroup SpecialPage
8  * @author Brion Vibber
9  * @author Rob Church <robchur@gmail.com>
10  */
11 class EmailConfirmation extends UnlistedSpecialPage {
12         
13         /**
14          * Constructor
15          */
16         public function __construct() {
17                 parent::__construct( 'Confirmemail' );
18         }
19         
20         /**
21          * Main execution point
22          *
23          * @param $code Confirmation code passed to the page
24          */
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->addWikiText( wfMsg( 'confirmemail_noemail' ) );
34                                 }
35                         } else {
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 ) );
41                         }
42                 } else {
43                         $this->attemptConfirm( $code );
44                 }
45         }
46         
47         /**
48          * Show a nice form for the user to request a confirmation mail
49          */
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->addWikiText( wfMsg( 'confirmemail_sendfailed', $ok->toString() ) );
56                         } else {
57                                 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
58                         }
59                 } else {
60                         if( $wgUser->isEmailConfirmed() ) {
61                                 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
62                                 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
63                         }
64                         if( $wgUser->isEmailConfirmationPending() ) {
65                                 $wgOut->addWikiText( wfMsg( 'confirmemail_pending' ) );
66                         }
67                         $wgOut->addWikiText( wfMsg( '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 );
74                 }                               
75         }
76         
77         /**
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
80          *
81          * @param $code Confirmation code
82          */
83         function attemptConfirm( $code ) {
84                 global $wgUser, $wgOut;
85                 $user = User::newFromConfirmationCode( $code );
86                 if( is_object( $user ) ) {
87                         if( $user->confirmEmail() ) {
88                                 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
89                                 $wgOut->addWikiText( wfMsg( $message ) );
90                                 if( !$wgUser->isLoggedIn() ) {
91                                         $title = SpecialPage::getTitleFor( 'Userlogin' );
92                                         $wgOut->returnToMain( true, $title->getPrefixedText() );
93                                 }
94                         } else {
95                                 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
96                         }
97                 } else {
98                         $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );
99                 }
100         }
101         
102 }
103
104