3 * Implements Special:ChangeEmail
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Let users change their email address.
27 * @ingroup SpecialPage
29 class SpecialChangeEmail
extends FormSpecialPage
{
35 public function __construct() {
36 parent
::__construct( 'ChangeEmail', 'editmyprivateinfo' );
42 public function isListed() {
45 return $wgAuth->allowPropChange( 'emailaddress' );
49 * Main execution point
52 function execute( $par ) {
53 $out = $this->getOutput();
54 $out->disallowUserJs();
55 $out->addModules( 'mediawiki.special.changeemail' );
57 parent
::execute( $par );
60 protected function checkExecutePermissions( User
$user ) {
63 if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
64 throw new ErrorPageError( 'changeemail', 'cannotchangeemail' );
67 $this->requireLogin( 'changeemail-no-info' );
69 // This could also let someone check the current email address, so
70 // require both permissions.
71 if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) {
72 throw new PermissionsError( 'viewmyprivateinfo' );
75 parent
::checkExecutePermissions( $user );
78 protected function getFormFields() {
79 $user = $this->getUser();
84 'label-message' => 'username',
85 'default' => $user->getName(),
89 'label-message' => 'changeemail-oldemail',
90 'default' => $user->getEmail() ?
: $this->msg( 'changeemail-none' )->text(),
94 'label-message' => 'changeemail-newemail',
98 if ( $this->getConfig()->get( 'RequirePasswordforEmailChange' ) ) {
99 $fields['Password'] = array(
100 'type' => 'password',
101 'label-message' => 'changeemail-password',
109 protected function getDisplayFormat() {
113 protected function alterForm( HTMLForm
$form ) {
114 $form->setId( 'mw-changeemail-form' );
115 $form->setTableId( 'mw-changeemail-table' );
116 $form->setSubmitTextMsg( 'changeemail-submit' );
117 $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
120 public function onSubmit( array $data ) {
121 $password = isset( $data['Password'] ) ?
$data['Password'] : null;
122 $status = $this->attemptChange( $this->getUser(), $password, $data['NewEmail'] );
124 $this->status
= $status;
129 public function onSuccess() {
130 $request = $this->getRequest();
132 $titleObj = Title
::newFromText( $request->getVal( 'returnto' ) );
133 if ( !$titleObj instanceof Title
) {
134 $titleObj = Title
::newMainPage();
136 $query = $request->getVal( 'returntoquery' );
138 if ( $this->status
->value
=== true ) {
139 $this->getOutput()->redirect( $titleObj->getFullURL( $query ) );
140 } elseif ( $this->status
->value
=== 'eauth' ) {
141 # Notify user that a confirmation email has been sent...
142 $this->getOutput()->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
143 'eauthentsent', $this->getUser()->getName() );
144 $this->getOutput()->addReturnTo( $titleObj, wfCgiToArray( $query ) ); // just show the link to go back
150 * @param string $pass
151 * @param string $newaddr
154 private function attemptChange( User
$user, $pass, $newaddr ) {
157 if ( $newaddr != '' && !Sanitizer
::validateEmail( $newaddr ) ) {
158 return Status
::newFatal( 'invalidemailaddress' );
161 $throttleCount = LoginForm
::incLoginThrottle( $user->getName() );
162 if ( $throttleCount === true ) {
163 $lang = $this->getLanguage();
164 $throttleInfo = $this->getConfig()->get( 'PasswordAttemptThrottle' );
165 return Status
::newFatal(
166 'changeemail-throttled',
167 $lang->formatDuration( $throttleInfo['seconds'] )
171 if ( $this->getConfig()->get( 'RequirePasswordforEmailChange' )
172 && !$user->checkTemporaryPassword( $pass )
173 && !$user->checkPassword( $pass )
175 return Status
::newFatal( 'wrongpassword' );
178 if ( $throttleCount ) {
179 LoginForm
::clearLoginThrottle( $user->getName() );
182 $oldaddr = $user->getEmail();
183 $status = $user->setEmailWithConfirmation( $newaddr );
184 if ( !$status->isGood() ) {
188 Hooks
::run( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
190 $user->saveSettings();
192 $wgAuth->updateExternalDB( $user );
197 public function requiresUnblock() {
201 protected function getGroupName() {