3 * Entry point to confirm a user's e-mail address.
4 * When a new address is entered, a random unique code is generated and
5 * mailed to the user. A clickable link to this page is provided.
8 * @subpackage SpecialPage
11 function wfSpecialConfirmemail( $code ) {
12 $form = new ConfirmationForm();
16 class ConfirmationForm
{
17 function show( $code ) {
18 if( empty( $code ) ) {
19 $this->showEmpty( $this->checkAndSend() );
21 $this->showCode( $code );
25 function showCode( $code ) {
26 $user = User
::newFromConfirmationCode( $code );
27 if( is_null( $user ) ) {
28 $this->showInvalidCode();
30 $this->confirmAndShow( $user );
35 function confirmAndShow( $user ) {
36 if( $user->confirmEmail() ) {
43 function checkAndSend() {
44 global $wgUser, $wgRequest;
45 if( $wgRequest->wasPosted() &&
46 $wgUser->isLoggedIn() &&
47 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
48 $result = $wgUser->sendConfirmationMail();
49 if( WikiError
::isError( $result ) ) {
50 return 'confirmemail_sendfailed';
52 return 'confirmemail_sent';
60 function showEmpty( $err ) {
61 require_once( 'templates/Confirmemail.php' );
62 global $wgOut, $wgUser;
64 $tpl = new ConfirmemailTemplate();
65 $tpl->set( 'error', $err );
66 $tpl->set( 'edittoken', $wgUser->editToken() );
68 $title = Title
::makeTitle( NS_SPECIAL
, 'Confirmemail' );
69 $tpl->set( 'action', $title->getLocalUrl() );
72 $wgOut->addTemplate( $tpl );
75 function showInvalidCode() {
77 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );
80 function showError() {
82 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
85 function showSuccess() {
86 global $wgOut, $wgRequest, $wgUser;
88 if( $wgUser->isLoggedIn() ) {
89 $wgOut->addWikiText( wfMsg( 'confirmemail_loggedin' ) );
91 $wgOut->addWikiText( wfMsg( 'confirmemail_success' ) );
92 require_once( 'SpecialUserlogin.php' );
93 $form = new LoginForm( $wgRequest );