Fix invalid ORDER BY
[mediawiki.git] / includes / SpecialConfirmemail.php
blobd20d9c6b96813ef34ded773015eeecfad00c860e
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 * @addtogroup Special pages
8 * @author Rob Church <robchur@gmail.com>
9 */
11 /**
12 * Main execution point
14 * @param $par Parameters passed to the page
16 function wfSpecialConfirmemail( $par ) {
17 $form = new EmailConfirmation();
18 $form->execute( $par );
21 class EmailConfirmation extends SpecialPage {
23 /**
24 * Main execution point
26 * @param $code Confirmation code passed to the page
28 function execute( $code ) {
29 global $wgUser, $wgOut;
30 if( empty( $code ) ) {
31 if( $wgUser->isLoggedIn() ) {
32 if( User::isValidEmailAddr( $wgUser->getEmail() ) ) {
33 $this->showRequestForm();
34 } else {
35 $wgOut->addWikiText( wfMsg( 'confirmemail_noemail' ) );
37 } else {
38 $title = SpecialPage::getTitleFor( 'Userlogin' );
39 $self = SpecialPage::getTitleFor( 'Confirmemail' );
40 $skin = $wgUser->getSkin();
41 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
42 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
44 } else {
45 $this->attemptConfirm( $code );
49 /**
50 * Show a nice form for the user to request a confirmation mail
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' ) );
61 } else {
62 if( $wgUser->isEmailConfirmed() ) {
63 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
64 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
66 if( $wgUser->isEmailConfirmationPending() ) {
67 $wgOut->addWikiText( wfMsg( 'confirmemail_pending' ) );
69 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
70 $self = SpecialPage::getTitleFor( 'Confirmemail' );
71 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
72 $form .= wfHidden( 'token', $wgUser->editToken() );
73 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
74 $form .= wfCloseElement( 'form' );
75 $wgOut->addHtml( $form );
79 /**
80 * Attempt to confirm the user's email address and show success or failure
81 * as needed; if successful, take the user to log in
83 * @param $code Confirmation code
85 function attemptConfirm( $code ) {
86 global $wgUser, $wgOut;
87 $user = User::newFromConfirmationCode( $code );
88 if( is_object( $user ) ) {
89 if( $user->confirmEmail() ) {
90 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
91 $wgOut->addWikiText( wfMsg( $message ) );
92 if( !$wgUser->isLoggedIn() ) {
93 $title = SpecialPage::getTitleFor( 'Userlogin' );
94 $wgOut->returnToMain( true, $title->getPrefixedText() );
96 } else {
97 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
99 } else {
100 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );