Merge "Rename autonym for 'no' from 'norsk bokmål' to 'norsk'"
[lhc/web/wiklou.git] / includes / specials / SpecialChangeEmail.php
index 51b08f9..c514300 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Auth\AuthManager;
+
 /**
  * Let users change their email address.
  *
@@ -36,13 +38,15 @@ class SpecialChangeEmail extends FormSpecialPage {
                parent::__construct( 'ChangeEmail', 'editmyprivateinfo' );
        }
 
+       public function doesWrites() {
+               return true;
+       }
+
        /**
         * @return bool
         */
        public function isListed() {
-               global $wgAuth;
-
-               return $wgAuth->allowPropChange( 'emailaddress' );
+               return AuthManager::singleton()->allowsPropertyChange( 'emailaddress' );
        }
 
        /**
@@ -50,6 +54,8 @@ class SpecialChangeEmail extends FormSpecialPage {
         * @param string $par
         */
        function execute( $par ) {
+               $this->checkLoginSecurityLevel();
+
                $out = $this->getOutput();
                $out->disallowUserJs();
 
@@ -57,9 +63,7 @@ class SpecialChangeEmail extends FormSpecialPage {
        }
 
        protected function checkExecutePermissions( User $user ) {
-               global $wgAuth;
-
-               if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
+               if ( !AuthManager::singleton()->allowsPropertyChange( 'emailaddress' ) ) {
                        throw new ErrorPageError( 'changeemail', 'cannotchangeemail' );
                }
 
@@ -77,31 +81,24 @@ class SpecialChangeEmail extends FormSpecialPage {
        protected function getFormFields() {
                $user = $this->getUser();
 
-               $fields = array(
-                       'Name' => array(
+               $fields = [
+                       'Name' => [
                                'type' => 'info',
                                'label-message' => 'username',
                                'default' => $user->getName(),
-                       ),
-                       'OldEmail' => array(
+                       ],
+                       'OldEmail' => [
                                'type' => 'info',
                                'label-message' => 'changeemail-oldemail',
                                'default' => $user->getEmail() ?: $this->msg( 'changeemail-none' )->text(),
-                       ),
-                       'NewEmail' => array(
+                       ],
+                       'NewEmail' => [
                                'type' => 'email',
                                'label-message' => 'changeemail-newemail',
                                'autofocus' => true,
                                'help-message' => 'changeemail-newemail-help',
-                       ),
-               );
-
-               if ( $this->getConfig()->get( 'RequirePasswordforEmailChange' ) ) {
-                       $fields['Password'] = array(
-                               'type' => 'password',
-                               'label-message' => 'changeemail-password'
-                       );
-               }
+                       ],
+               ];
 
                return $fields;
        }
@@ -117,14 +114,10 @@ class SpecialChangeEmail extends FormSpecialPage {
                $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
 
                $form->addHeaderText( $this->msg( 'changeemail-header' )->parseAsBlock() );
-               if ( $this->getConfig()->get( 'RequirePasswordforEmailChange' ) ) {
-                       $form->addHeaderText( $this->msg( 'changeemail-passwordrequired' )->parseAsBlock() );
-               }
        }
 
        public function onSubmit( array $data ) {
-               $password = isset( $data['Password'] ) ? $data['Password'] : null;
-               $status = $this->attemptChange( $this->getUser(), $password, $data['NewEmail'] );
+               $status = $this->attemptChange( $this->getUser(), $data['NewEmail'] );
 
                $this->status = $status;
 
@@ -142,7 +135,7 @@ class SpecialChangeEmail extends FormSpecialPage {
                $query = $request->getVal( 'returntoquery' );
 
                if ( $this->status->value === true ) {
-                       $this->getOutput()->redirect( $titleObj->getFullURL( $query ) );
+                       $this->getOutput()->redirect( $titleObj->getFullUrlForRedirect( $query ) );
                } elseif ( $this->status->value === 'eauth' ) {
                        # Notify user that a confirmation email has been sent...
                        $this->getOutput()->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
@@ -154,12 +147,11 @@ class SpecialChangeEmail extends FormSpecialPage {
 
        /**
         * @param User $user
-        * @param string $pass
         * @param string $newaddr
         * @return Status
         */
-       private function attemptChange( User $user, $pass, $newaddr ) {
-               global $wgAuth;
+       private function attemptChange( User $user, $newaddr ) {
+               $authManager = AuthManager::singleton();
 
                if ( $newaddr != '' && !Sanitizer::validateEmail( $newaddr ) ) {
                        return Status::newFatal( 'invalidemailaddress' );
@@ -169,38 +161,16 @@ class SpecialChangeEmail extends FormSpecialPage {
                        return Status::newFatal( 'changeemail-nochange' );
                }
 
-               $throttleCount = LoginForm::incLoginThrottle( $user->getName() );
-               if ( $throttleCount === true ) {
-                       $lang = $this->getLanguage();
-                       $throttleInfo = $this->getConfig()->get( 'PasswordAttemptThrottle' );
-                       return Status::newFatal(
-                               'changeemail-throttled',
-                               $lang->formatDuration( $throttleInfo['seconds'] )
-                       );
-               }
-
-               if ( $this->getConfig()->get( 'RequirePasswordforEmailChange' )
-                       && !$user->checkTemporaryPassword( $pass )
-                       && !$user->checkPassword( $pass )
-               ) {
-                       return Status::newFatal( 'wrongpassword' );
-               }
-
-               if ( $throttleCount ) {
-                       LoginForm::clearLoginThrottle( $user->getName() );
-               }
-
                $oldaddr = $user->getEmail();
                $status = $user->setEmailWithConfirmation( $newaddr );
                if ( !$status->isGood() ) {
                        return $status;
                }
 
-               Hooks::run( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
+               Hooks::run( 'PrefsEmailAudit', [ $user, $oldaddr, $newaddr ] );
 
                $user->saveSettings();
-
-               $wgAuth->updateExternalDB( $user );
+               MediaWiki\Auth\AuthManager::callLegacyAuthPlugin( 'updateExternalDB', [ $user ] );
 
                return $status;
        }