Cripple the wiki text stuff for now. It doesn't SEEM dangerous but I haven't tested...
[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 $this->showRequestForm();
34 } else {
35 $title = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
36 $self = Title::makeTitle( NS_SPECIAL, 'Confirmemail' );
37 $skin = $wgUser->getSkin();
38 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
39 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
40 }
41 } else {
42 $this->attemptConfirm( $code );
43 }
44 }
45
46 /**
47 * Show a nice form for the user to request a confirmation mail
48 */
49 function showRequestForm() {
50 global $wgOut, $wgUser, $wgLang, $wgRequest;
51 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
52 $ok = $wgUser->sendConfirmationMail();
53 $message = WikiError::isError( $ok ) ? 'confirmemail_sendfailed' : 'confirmemail_sent';
54 $wgOut->addWikiText( wfMsg( $message ) );
55 } else {
56 if( $wgUser->isEmailConfirmed() ) {
57 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
58 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
59 }
60 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
61 $self = Title::makeTitle( NS_SPECIAL, 'Confirmemail' );
62 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
63 $form .= wfHidden( 'token', $wgUser->editToken() );
64 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
65 $form .= wfCloseElement( 'form' );
66 $wgOut->addHtml( $form );
67 }
68 }
69
70 /**
71 * Attempt to confirm the user's email address and show success or failure
72 * as needed; if successful, take the user to log in
73 *
74 * @param $code Confirmation code
75 */
76 function attemptConfirm( $code ) {
77 global $wgUser, $wgOut;
78 $user = User::newFromConfirmationCode( $code );
79 if( is_object( $user ) ) {
80 if( $user->confirmEmail() ) {
81 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
82 $wgOut->addWikiText( wfMsg( $message ) );
83 if( !$wgUser->isLoggedIn() ) {
84 $title = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
85 $wgOut->returnToMain( true, $title->getPrefixedText() );
86 }
87 } else {
88 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
89 }
90 } else {
91 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );
92 }
93 }
94
95 }
96
97 ?>