MediaWiki
REL1_19
|
00001 <?php 00032 class EmailConfirmation extends UnlistedSpecialPage { 00033 00037 public function __construct() { 00038 parent::__construct( 'Confirmemail' ); 00039 } 00040 00046 function execute( $code ) { 00047 $this->setHeaders(); 00048 00049 $this->checkReadOnly(); 00050 00051 if( $code === null || $code === '' ) { 00052 if( $this->getUser()->isLoggedIn() ) { 00053 if( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) { 00054 $this->showRequestForm(); 00055 } else { 00056 $this->getOutput()->addWikiMsg( 'confirmemail_noemail' ); 00057 } 00058 } else { 00059 $llink = Linker::linkKnown( 00060 SpecialPage::getTitleFor( 'Userlogin' ), 00061 $this->msg( 'loginreqlink' )->escaped(), 00062 array(), 00063 array( 'returnto' => $this->getTitle()->getPrefixedText() ) 00064 ); 00065 $this->getOutput()->addHTML( $this->msg( 'confirmemail_needlogin' )->rawParams( $llink )->parse() ); 00066 } 00067 } else { 00068 $this->attemptConfirm( $code ); 00069 } 00070 } 00071 00075 function showRequestForm() { 00076 $user = $this->getUser(); 00077 $out = $this->getOutput(); 00078 if( $this->getRequest()->wasPosted() && $user->matchEditToken( $this->getRequest()->getText( 'token' ) ) ) { 00079 $status = $user->sendConfirmationMail(); 00080 if ( $status->isGood() ) { 00081 $out->addWikiMsg( 'confirmemail_sent' ); 00082 } else { 00083 $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); 00084 } 00085 } else { 00086 if( $user->isEmailConfirmed() ) { 00087 // date and time are separate parameters to facilitate localisation. 00088 // $time is kept for backward compat reasons. 00089 // 'emailauthenticated' is also used in SpecialPreferences.php 00090 $lang = $this->getLanguage(); 00091 $emailAuthenticated = $user->getEmailAuthenticationTimestamp(); 00092 $time = $lang->userTimeAndDate( $emailAuthenticated, $user ); 00093 $d = $lang->userDate( $emailAuthenticated, $user ); 00094 $t = $lang->userTime( $emailAuthenticated, $user ); 00095 $out->addWikiMsg( 'emailauthenticated', $time, $d, $t ); 00096 } 00097 if( $user->isEmailConfirmationPending() ) { 00098 $out->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>", 'confirmemail_pending' ); 00099 } 00100 $out->addWikiMsg( 'confirmemail_text' ); 00101 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) ); 00102 $form .= Html::hidden( 'token', $user->getEditToken() ); 00103 $form .= Xml::submitButton( $this->msg( 'confirmemail_send' )->text() ); 00104 $form .= Xml::closeElement( 'form' ); 00105 $out->addHTML( $form ); 00106 } 00107 } 00108 00115 function attemptConfirm( $code ) { 00116 $user = User::newFromConfirmationCode( $code ); 00117 if( is_object( $user ) ) { 00118 $user->confirmEmail(); 00119 $user->saveSettings(); 00120 $message = $this->getUser()->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success'; 00121 $this->getOutput()->addWikiMsg( $message ); 00122 if( !$this->getUser()->isLoggedIn() ) { 00123 $title = SpecialPage::getTitleFor( 'Userlogin' ); 00124 $this->getOutput()->returnToMain( true, $title ); 00125 } 00126 } else { 00127 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' ); 00128 } 00129 } 00130 00131 } 00132 00139 class EmailInvalidation extends UnlistedSpecialPage { 00140 00141 public function __construct() { 00142 parent::__construct( 'Invalidateemail' ); 00143 } 00144 00145 function execute( $code ) { 00146 $this->setHeaders(); 00147 00148 if ( wfReadOnly() ) { 00149 throw new ReadOnlyError; 00150 } 00151 00152 $this->attemptInvalidate( $code ); 00153 } 00154 00161 function attemptInvalidate( $code ) { 00162 $user = User::newFromConfirmationCode( $code ); 00163 if( is_object( $user ) ) { 00164 $user->invalidateEmail(); 00165 $user->saveSettings(); 00166 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' ); 00167 if( !$this->getUser()->isLoggedIn() ) { 00168 $this->getOutput()->returnToMain(); 00169 } 00170 } else { 00171 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' ); 00172 } 00173 } 00174 }