6 * @param $par Parameters passed to the page
8 function wfSpecialConfirmemail( $par ) {
9 $form = new EmailConfirmation();
10 $form->execute( $par );
14 * Special page allows users to request email confirmation message, and handles
15 * processing of the confirmation code when the link in the email is followed
17 * @addtogroup SpecialPage
18 * @author Rob Church <robchur@gmail.com>
20 class EmailConfirmation
extends SpecialPage
{
23 * Main execution point
25 * @param $code Confirmation code passed to the page
27 function execute( $code ) {
28 global $wgUser, $wgOut;
29 if( empty( $code ) ) {
30 if( $wgUser->isLoggedIn() ) {
31 if( User
::isValidEmailAddr( $wgUser->getEmail() ) ) {
32 $this->showRequestForm();
34 $wgOut->addWikiText( wfMsg( 'confirmemail_noemail' ) );
37 $title = SpecialPage
::getTitleFor( 'Userlogin' );
38 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
39 $skin = $wgUser->getSkin();
40 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
41 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
44 $this->attemptConfirm( $code );
49 * Show a nice form for the user to request a confirmation mail
51 function showRequestForm() {
52 global $wgOut, $wgUser, $wgLang, $wgRequest;
53 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
54 $ok = $wgUser->sendConfirmationMail();
55 if ( WikiError
::isError( $ok ) ) {
56 $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $ok->toString() ) );
58 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
61 if( $wgUser->isEmailConfirmed() ) {
62 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
63 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
65 if( $wgUser->isEmailConfirmationPending() ) {
66 $wgOut->addWikiText( wfMsg( 'confirmemail_pending' ) );
68 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
69 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
70 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
71 $form .= wfHidden( 'token', $wgUser->editToken() );
72 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
73 $form .= wfCloseElement( 'form' );
74 $wgOut->addHtml( $form );
79 * Attempt to confirm the user's email address and show success or failure
80 * as needed; if successful, take the user to log in
82 * @param $code Confirmation code
84 function attemptConfirm( $code ) {
85 global $wgUser, $wgOut;
86 $user = User
::newFromConfirmationCode( $code );
87 if( is_object( $user ) ) {
88 if( $user->confirmEmail() ) {
89 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
90 $wgOut->addWikiText( wfMsg( $message ) );
91 if( !$wgUser->isLoggedIn() ) {
92 $title = SpecialPage
::getTitleFor( 'Userlogin' );
93 $wgOut->returnToMain( true, $title->getPrefixedText() );
96 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
99 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );