* (bug 6029) Improvement to German localisation (de)
[mediawiki.git] / includes / SpecialConfirmemail.php
blobe07ed004ca7d90f16266f99780df701ef49cfa38
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 * @package MediaWiki
8 * @subpackage Special pages
9 * @author Rob Church <robchur@gmail.com>
12 /**
13 * Main execution point
15 * @param $par Parameters passed to the page
17 function wfSpecialConfirmemail( $par ) {
18 $form = new EmailConfirmation();
19 $form->execute( $par );
22 class EmailConfirmation extends SpecialPage {
24 /**
25 * Main execution point
27 * @param $code Confirmation code passed to the page
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 ) );
41 } else {
42 $this->attemptConfirm( $code );
46 /**
47 * Show a nice form for the user to request a confirmation mail
49 function showRequestForm() {
50 global $wgOut, $wgUser, $wgLang, $wgRequest;
51 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
52 $message = $wgUser->sendConfirmationMail() ? 'confirmemail_sent' : 'confirmemail_sendfailed';
53 $wgOut->addWikiText( wfMsg( $message ) );
54 } else {
55 if( $wgUser->isEmailConfirmed() ) {
56 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
57 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
59 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
60 $self = Title::makeTitle( NS_SPECIAL, 'Confirmemail' );
61 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
62 $form .= wfHidden( 'token', $wgUser->editToken() );
63 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
64 $form .= wfCloseElement( 'form' );
65 $wgOut->addHtml( $form );
69 /**
70 * Attempt to confirm the user's email address and show success or failure
71 * as needed; if successful, take the user to log in
73 * @param $code Confirmation code
75 function attemptConfirm( $code ) {
76 global $wgUser, $wgOut;
77 $user = User::newFromConfirmationCode( $code );
78 if( is_object( $user ) ) {
79 if( $user->confirmEmail() ) {
80 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
81 $wgOut->addWikiText( wfMsg( $message ) );
82 if( !$wgUser->isLoggedIn() ) {
83 $title = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
84 $wgOut->returnToMain( true, $title->getPrefixedText() );
86 } else {
87 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
89 } else {
90 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );