e428d6ca6293e2dd0d3c9b37d023bcdab1240b9b
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 = SpecialPage
::getTitleFor( 'Userlogin' );
40 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
41 $llink = Linker
::makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
42 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
45 $this->attemptConfirm( $code );
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() ) );
59 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
62 if( $wgUser->isEmailConfirmed() ) {
63 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated
, true );
64 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
66 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
67 $self = SpecialPage
::getTitleFor( 'Confirmemail' );
68 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
69 $form .= wfHidden( 'token', $wgUser->editToken() );
70 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
71 $form .= wfCloseElement( 'form' );
72 $wgOut->addHtml( $form );
77 * Attempt to confirm the user's email address and show success or failure
78 * as needed; if successful, take the user to log in
80 * @param $code Confirmation code
82 function attemptConfirm( $code ) {
83 global $wgUser, $wgOut;
84 $user = User
::newFromConfirmationCode( $code );
85 if( is_object( $user ) ) {
86 if( $user->confirmEmail() ) {
87 $message = $wgUser->isLoggedIn() ?
'confirmemail_loggedin' : 'confirmemail_success';
88 $wgOut->addWikiText( wfMsg( $message ) );
89 if( !$wgUser->isLoggedIn() ) {
90 $title = SpecialPage
::getTitleFor( 'Userlogin' );
91 $wgOut->returnToMain( true, $title->getPrefixedText() );
94 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
97 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );