* (bug 7405) Make Linker methods static. Patch by Dan Li.
[lhc/web/wiklou.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 * @package MediaWiki
8 * @subpackage Special pages
9 * @author Rob Church <robchur@gmail.com>
10 */
11
12 /**
13 * Main execution point
14 *
15 * @param $par Parameters passed to the page
16 */
17 function wfSpecialConfirmemail( $par ) {
18 $form = new EmailConfirmation();
19 $form->execute( $par );
20 }
21
22 class EmailConfirmation extends SpecialPage {
23
24 /**
25 * Main execution point
26 *
27 * @param $code Confirmation code passed to the page
28 */
29 function execute( $code ) {
30 global $wgUser, $wgOut;
31 if( empty( $code ) ) {
32 if( $wgUser->isLoggedIn() ) {
33 if( User::isValidEmailAddr( $wgUser->getEmail() ) ) {
34 $this->showRequestForm();
35 } else {
36 $wgOut->addWikiText( wfMsg( 'confirmemail_noemail' ) );
37 }
38 } else {
39 $title = SpecialPage::getTitleFor( 'Userlogin' );
40 $self = SpecialPage::getTitleFor( 'Confirmemail' );
41 $llink = Linker::makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
42 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
43 }
44 } else {
45 $this->attemptConfirm( $code );
46 }
47 }
48
49 /**
50 * Show a nice form for the user to request a confirmation mail
51 */
52 function showRequestForm() {
53 global $wgOut, $wgUser, $wgLang, $wgRequest;
54 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
55 $ok = $wgUser->sendConfirmationMail();
56 if ( WikiError::isError( $ok ) ) {
57 $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $ok->toString() ) );
58 } else {
59 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
60 }
61 } else {
62 if( $wgUser->isEmailConfirmed() ) {
63 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
64 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
65 }
66 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
67 $self = SpecialPage::getTitleFor( 'Confirmemail' );
68 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
69 $form .= wfHidden( 'token', $wgUser->editToken() );
70 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
71 $form .= wfCloseElement( 'form' );
72 $wgOut->addHtml( $form );
73 }
74 }
75
76 /**
77 * Attempt to confirm the user's email address and show success or failure
78 * as needed; if successful, take the user to log in
79 *
80 * @param $code Confirmation code
81 */
82 function attemptConfirm( $code ) {
83 global $wgUser, $wgOut;
84 $user = User::newFromConfirmationCode( $code );
85 if( is_object( $user ) ) {
86 if( $user->confirmEmail() ) {
87 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
88 $wgOut->addWikiText( wfMsg( $message ) );
89 if( !$wgUser->isLoggedIn() ) {
90 $title = SpecialPage::getTitleFor( 'Userlogin' );
91 $wgOut->returnToMain( true, $title->getPrefixedText() );
92 }
93 } else {
94 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
95 }
96 } else {
97 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );
98 }
99 }
100
101 }
102
103 ?>