diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2006-10-11 18:12:39 +0000 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2006-10-11 18:12:39 +0000 |
commit | 183851b06bd6c52f3cae5375f433da720d410447 (patch) | |
tree | a477257decbf3360127f6739c2f9d0ec57a03d39 /includes/SpecialConfirmemail.php |
MediaWiki 1.7.1 wiederhergestellt
Diffstat (limited to 'includes/SpecialConfirmemail.php')
-rw-r--r-- | includes/SpecialConfirmemail.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/includes/SpecialConfirmemail.php b/includes/SpecialConfirmemail.php new file mode 100644 index 00000000..fd0425a8 --- /dev/null +++ b/includes/SpecialConfirmemail.php @@ -0,0 +1,97 @@ +<?php + +/** + * Special page allows users to request email confirmation message, and handles + * processing of the confirmation code when the link in the email is followed + * + * @package MediaWiki + * @subpackage Special pages + * @author Rob Church <robchur@gmail.com> + */ + +/** + * Main execution point + * + * @param $par Parameters passed to the page + */ +function wfSpecialConfirmemail( $par ) { + $form = new EmailConfirmation(); + $form->execute( $par ); +} + +class EmailConfirmation extends SpecialPage { + + /** + * Main execution point + * + * @param $code Confirmation code passed to the page + */ + function execute( $code ) { + global $wgUser, $wgOut; + if( empty( $code ) ) { + if( $wgUser->isLoggedIn() ) { + $this->showRequestForm(); + } else { + $title = Title::makeTitle( NS_SPECIAL, 'Userlogin' ); + $self = Title::makeTitle( NS_SPECIAL, 'Confirmemail' ); + $skin = $wgUser->getSkin(); + $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() ); + $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) ); + } + } else { + $this->attemptConfirm( $code ); + } + } + + /** + * Show a nice form for the user to request a confirmation mail + */ + function showRequestForm() { + global $wgOut, $wgUser, $wgLang, $wgRequest; + if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) { + $ok = $wgUser->sendConfirmationMail(); + $message = WikiError::isError( $ok ) ? 'confirmemail_sendfailed' : 'confirmemail_sent'; + $wgOut->addWikiText( wfMsg( $message ) ); + } else { + if( $wgUser->isEmailConfirmed() ) { + $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true ); + $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) ); + } + $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) ); + $self = Title::makeTitle( NS_SPECIAL, 'Confirmemail' ); + $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) ); + $form .= wfHidden( 'token', $wgUser->editToken() ); + $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) ); + $form .= wfCloseElement( 'form' ); + $wgOut->addHtml( $form ); + } + } + + /** + * Attempt to confirm the user's email address and show success or failure + * as needed; if successful, take the user to log in + * + * @param $code Confirmation code + */ + function attemptConfirm( $code ) { + global $wgUser, $wgOut; + $user = User::newFromConfirmationCode( $code ); + if( is_object( $user ) ) { + if( $user->confirmEmail() ) { + $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success'; + $wgOut->addWikiText( wfMsg( $message ) ); + if( !$wgUser->isLoggedIn() ) { + $title = Title::makeTitle( NS_SPECIAL, 'Userlogin' ); + $wgOut->returnToMain( true, $title->getPrefixedText() ); + } + } else { + $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) ); + } + } else { + $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) ); + } + } + +} + +?> |