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
8 * @subpackage Special pages
9 * @author Rob Church <robchur@gmail.com>
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
{
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 if( User
::isValidEmailAddr( $wgUser->getEmail() ) ) {
34 $this->showRequestForm();
36 $wgOut->addWikiText( wfMsg( 'confirmemail_noemail' ) );
39 $title = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
40 $self = Title
::makeTitle( NS_SPECIAL
, 'Confirmemail' );
41 $skin = $wgUser->getSkin();
42 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
43 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
46 $this->attemptConfirm( $code );
51 * Show a nice form for the user to request a confirmation mail
53 function showRequestForm() {
54 global $wgOut, $wgUser, $wgLang, $wgRequest;
55 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
56 $ok = $wgUser->sendConfirmationMail();
57 if ( WikiError
::isError( $ok ) ) {
58 $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $ok->toString() ) );
60 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
63 if( $wgUser->isEmailConfirmed() ) {
64 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
65 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
67 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
68 $self = Title
::makeTitle( NS_SPECIAL
, 'Confirmemail' );
69 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
70 $form .= wfHidden( 'token', $wgUser->editToken() );
71 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
72 $form .= wfCloseElement( 'form' );
73 $wgOut->addHtml( $form );
78 * Attempt to confirm the user's email address and show success or failure
79 * as needed; if successful, take the user to log in
81 * @param $code Confirmation code
83 function attemptConfirm( $code ) {
84 global $wgUser, $wgOut;
85 $user = User
::newFromConfirmationCode( $code );
86 if( is_object( $user ) ) {
87 if( $user->confirmEmail() ) {
88 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
89 $wgOut->addWikiText( wfMsg( $message ) );
90 if( !$wgUser->isLoggedIn() ) {
91 $title = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
92 $wgOut->returnToMain( true, $title->getPrefixedText() );
95 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
98 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );