X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialChangeEmail.php;h=eae8e3a1483f461cc788978d43022c9a6c9d6ac6;hb=21b7b27f0379cff1b06efa95d27fa88684b65c57;hp=167d4e2c80296562495e1d4604d98da557b4a754;hpb=e676c6953fad3c9b29f50216f1b082a13738bf20;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialChangeEmail.php b/includes/specials/SpecialChangeEmail.php index 167d4e2c80..eae8e3a148 100644 --- a/includes/specials/SpecialChangeEmail.php +++ b/includes/specials/SpecialChangeEmail.php @@ -27,10 +27,26 @@ * @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' ); @@ -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( "

\n$1\n

", $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" . "\n" . "\n" . '' . @@ -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; } }