Merge "(bug 34876) improve $.makeCollapsible performance on the initial collapsing"
[lhc/web/wiklou.git] / includes / specials / SpecialChangeEmail.php
index a1c6fd2..eae8e3a 100644 (file)
  * @ingroup SpecialPage
  */
 class SpecialChangeEmail extends UnlistedSpecialPage {
+
+       /**
+        * Users password
+        * @var string
+        */
+       protected $mPassword;
+
+       /**
+        * Users new email address
+        * @var string
+        */
+       protected $mNewEmail;
+
        public function __construct() {
                parent::__construct( 'ChangeEmail' );
        }
 
+       /**
+        * @return Bool
+        */
        function isListed() {
                global $wgAuth;
                return $wgAuth->allowPropChange( 'emailaddress' );
@@ -42,11 +58,13 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
        function execute( $par ) {
                global $wgAuth;
 
-               $this->checkReadOnly();
-
                $this->setHeaders();
                $this->outputHeader();
 
+               $out = $this->getOutput();
+               $out->disallowUserJs();
+               $out->addModules( 'mediawiki.special.changeemail' );
+
                if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
                        $this->error( 'cannotchangeemail' );
                        return;
@@ -65,9 +83,7 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                        return;
                }
 
-               $out = $this->getOutput();
-               $out->disallowUserJs();
-               $out->addModules( 'mediawiki.special.changeemail' );
+               $this->checkReadOnly();
 
                $this->mPassword = $request->getVal( 'wpPassword' );
                $this->mNewEmail = $request->getVal( 'wpNewEmail' );
@@ -90,6 +106,9 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                $this->showForm();
        }
 
+       /**
+        * @param $type string
+        */
        protected function doReturnTo( $type = 'hard' ) {
                $titleObj = Title::newFromText( $this->getRequest()->getVal( 'returnto' ) );
                if ( !$titleObj instanceof Title ) {
@@ -102,11 +121,15 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                }
        }
 
+       /**
+        * @param $msg string
+        */
        protected function error( $msg ) {
                $this->getOutput()->wrapWikiMsg( "<p class='error'>\n$1\n</p>", $msg );
        }
 
        protected function showForm() {
+               global $wgRequirePasswordforEmailChange;
                $user = $this->getUser();
 
                $oldEmailText = $user->getEmail()
@@ -123,13 +146,20 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                        Html::hidden( 'token', $user->getEditToken() ) . "\n" .
                        Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" .
                        $this->msg( 'changeemail-text' )->parseAsBlock() . "\n" .
-                       Xml::openElement( 'table', array( 'id' => 'mw-changeemail-table' ) ) . "\n" .
-                       $this->pretty( array(
-                               array( 'wpName', 'username', 'text', $user->getName() ),
-                               array( 'wpOldEmail', 'changeemail-oldemail', 'text', $oldEmailText ),
-                               array( 'wpNewEmail', 'changeemail-newemail', 'input', $this->mNewEmail ),
-                               array( 'wpPassword', 'yourpassword', 'password', $this->mPassword ),
-                       ) ) . "\n" .
+                       Xml::openElement( 'table', array( 'id' => 'mw-changeemail-table' ) ) . "\n"
+               );
+               $items = array(
+                       array( 'wpName', 'username', 'text', $user->getName() ),
+                       array( 'wpOldEmail', 'changeemail-oldemail', 'text', $oldEmailText ),
+                       array( 'wpNewEmail', 'changeemail-newemail', 'email', $this->mNewEmail ),
+               );
+               if ( $wgRequirePasswordforEmailChange ) {
+                       $items[] = array( 'wpPassword', 'changeemail-password', 'password', $this->mPassword );
+               }
+
+               $this->getOutput()->addHTML(
+                       $this->pretty( $items ) .
+                       "\n" .
                        "<tr>\n" .
                                "<td></td>\n" .
                                '<td class="mw-input">' .
@@ -143,6 +173,10 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                );
        }
 
+       /**
+        * @param $fields array
+        * @return string
+        */
        protected function pretty( $fields ) {
                $out = '';
                foreach ( $fields as $list ) {
@@ -173,9 +207,14 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
        }
 
        /**
+        * @param $user User
+        * @param $pass string
+        * @param $newaddr string
         * @return bool|string true or string on success, false on failure
         */
        protected function attemptChange( User $user, $pass, $newaddr ) {
+               global $wgAuth;
+
                if ( $newaddr != '' && !Sanitizer::validateEmail( $newaddr ) ) {
                        $this->error( 'invalidemailaddress' );
                        return false;
@@ -187,7 +226,8 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                        return false;
                }
 
-               if ( !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) {
+               global $wgRequirePasswordforEmailChange;
+               if ( $wgRequirePasswordforEmailChange && !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) {
                        $this->error( 'wrongpassword' );
                        return false;
                }
@@ -210,6 +250,8 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
 
                $user->saveSettings();
 
+               $wgAuth->updateExternalDB( $user );
+
                return $status->value;
        }
 }