Merge "mw.Upload.BookletLayout: Don't explode when the API call fails with 'exception'"
[lhc/web/wiklou.git] / includes / specials / SpecialConfirmemail.php
index 147f67e..5ed33e0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Implements Special:Confirmemail and Special:Invalidateemail
+ * Implements Special:Confirmemail
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,6 +34,10 @@ class EmailConfirmation extends UnlistedSpecialPage {
                parent::__construct( 'Confirmemail', 'editmyprivateinfo' );
        }
 
+       public function doesWrites() {
+               return true;
+       }
+
        /**
         * Main execution point
         *
@@ -78,16 +82,37 @@ class EmailConfirmation extends UnlistedSpecialPage {
                $user = $this->getUser();
                $out = $this->getOutput();
 
-               if ( $this->getRequest()->wasPosted() &&
-                       $user->matchEditToken( $this->getRequest()->getText( 'token' ) )
-               ) {
-                       $status = $user->sendConfirmationMail();
-                       if ( $status->isGood() ) {
+               if ( !$user->isEmailConfirmed() ) {
+                       $descriptor = array();
+                       if ( $user->isEmailConfirmationPending() ) {
+                               $descriptor += array(
+                                       'pending' => array(
+                                               'type' => 'info',
+                                               'raw' => true,
+                                               'default' => "<div class=\"error mw-confirmemail-pending\">\n" .
+                                                       $this->msg( 'confirmemail_pending' )->escaped() .
+                                                       "\n</div>",
+                                       ),
+                               );
+                       }
+
+                       $out->addWikiMsg( 'confirmemail_text' );
+                       $form = HTMLForm::factory( 'ooui', $descriptor, $this->getContext() );
+                       $form
+                               ->setMethod( 'post' )
+                               ->setAction( $this->getPageTitle()->getLocalURL() )
+                               ->setSubmitTextMsg( 'confirmemail_send' )
+                               ->setSubmitCallback( array( $this, 'submitSend' ) );
+
+                       $retval = $form->show();
+
+                       if ( $retval === true ) {
+                               // should never happen, but if so, don't let the user without any message
                                $out->addWikiMsg( 'confirmemail_sent' );
-                       } else {
-                               $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
+                       } elseif ( $retval instanceof Status && $retval->isGood() ) {
+                               $out->addWikiText( $retval->getValue() );
                        }
-               } elseif ( $user->isEmailConfirmed() ) {
+               } else {
                        // date and time are separate parameters to facilitate localisation.
                        // $time is kept for backward compat reasons.
                        // 'emailauthenticated' is also used in SpecialPreferences.php
@@ -97,23 +122,22 @@ class EmailConfirmation extends UnlistedSpecialPage {
                        $d = $lang->userDate( $emailAuthenticated, $user );
                        $t = $lang->userTime( $emailAuthenticated, $user );
                        $out->addWikiMsg( 'emailauthenticated', $time, $d, $t );
-               } else {
-                       if ( $user->isEmailConfirmationPending() ) {
-                               $out->wrapWikiMsg(
-                                       "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>",
-                                       'confirmemail_pending'
-                               );
-                       }
+               }
+       }
 
-                       $out->addWikiMsg( 'confirmemail_text' );
-                       $form = Html::openElement(
-                               'form',
-                               array( 'method' => 'post', 'action' => $this->getPageTitle()->getLocalURL() )
-                       ) . "\n";
-                       $form .= Html::hidden( 'token', $user->getEditToken() ) . "\n";
-                       $form .= Xml::submitButton( $this->msg( 'confirmemail_send' )->text() ) . "\n";
-                       $form .= Html::closeElement( 'form' ) . "\n";
-                       $out->addHTML( $form );
+       /**
+        * Callback for HTMLForm send confirmation mail.
+        *
+        * @return Status Status object with the result
+        */
+       public function submitSend() {
+               $status = $this->getUser()->sendConfirmationMail();
+               if ( $status->isGood() ) {
+                       return Status::newGood( $this->msg( 'confirmemail_sent' )->text() );
+               } else {
+                       return Status::newFatal( new RawMessage(
+                               $status->getWikiText( 'confirmemail_sendfailed' )
+                       ) );
                }
        }
 
@@ -142,49 +166,3 @@ class EmailConfirmation extends UnlistedSpecialPage {
                }
        }
 }
-
-/**
- * Special page allows users to cancel an email confirmation using the e-mail
- * confirmation code
- *
- * @ingroup SpecialPage
- */
-class EmailInvalidation extends UnlistedSpecialPage {
-       public function __construct() {
-               parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
-       }
-
-       function execute( $code ) {
-               // Ignore things like master queries/connections on GET requests.
-               // It's very convenient to just allow formless link usage.
-               Profiler::instance()->getTransactionProfiler()->resetExpectations();
-
-               $this->setHeaders();
-               $this->checkReadOnly();
-               $this->checkPermissions();
-               $this->attemptInvalidate( $code );
-       }
-
-       /**
-        * Attempt to invalidate the user's email address and show success or failure
-        * as needed; if successful, link to main page
-        *
-        * @param string $code Confirmation code
-        */
-       function attemptInvalidate( $code ) {
-               $user = User::newFromConfirmationCode( $code, User::READ_LATEST );
-               if ( !is_object( $user ) ) {
-                       $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
-
-                       return;
-               }
-
-               $user->invalidateEmail();
-               $user->saveSettings();
-               $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
-
-               if ( !$this->getUser()->isLoggedIn() ) {
-                       $this->getOutput()->returnToMain();
-               }
-       }
-}