From 616096da5c541e4d3d60244d26fa50eb74784511 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Tue, 12 Jul 2011 19:09:20 +0000 Subject: [PATCH] =?utf8?q?followup=20r91985=20=E2=80=94=20remove=20duplica?= =?utf8?q?tion=20of=20code=20per=20^demon's=20suggestion.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- includes/specials/SpecialPasswordReset.php | 47 +++++++++++----------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/includes/specials/SpecialPasswordReset.php b/includes/specials/SpecialPasswordReset.php index a400940392..191832b69b 100644 --- a/includes/specials/SpecialPasswordReset.php +++ b/includes/specials/SpecialPasswordReset.php @@ -35,23 +35,13 @@ class SpecialPasswordReset extends FormSpecialPage { public function userCanExecute( User $user ) { global $wgPasswordResetRoutes, $wgAuth; - // Maybe password resets are disabled, or there are no allowable routes - if ( !is_array( $wgPasswordResetRoutes ) || - !in_array( true, array_values( $wgPasswordResetRoutes ) ) ) { - throw new ErrorPageError( 'internalerror', 'passwordreset-disabled' ); - } - - // Maybe the external auth plugin won't allow local password changes - if ( !$wgAuth->allowPasswordChange() ) { + $error = $this->canChangePassword( $user ); + if ( is_string( $error ) ) { + throw new ErrorPageError( 'internalerror', $error ); + } else if ( !$error ) { throw new ErrorPageError( 'internalerror', 'resetpass_forbidden' ); } - // Maybe the user is blocked (check this here rather than relying on the parent - // method as we have a more specific error message to use here - if ( $user->isBlocked() ) { - throw new ErrorPageError( 'internalerror', 'blocked-mailpassword' ); - } - return parent::userCanExecute( $user ); } @@ -224,30 +214,41 @@ class SpecialPasswordReset extends FormSpecialPage { $this->getOutput()->returnToMain(); } - /** - * Hide the password reset page if resets are disabled. - * @return Bool - */ - function isListed() { + function canChangePassword(User $user) { global $wgPasswordResetRoutes, $wgAuth; // Maybe password resets are disabled, or there are no allowable routes if ( !is_array( $wgPasswordResetRoutes ) || !in_array( true, array_values( $wgPasswordResetRoutes ) ) ) { - return false; + return 'passwordreset-disabled'; } // Maybe the external auth plugin won't allow local password changes if ( !$wgAuth->allowPasswordChange() ) { - return false; + return 'resetpass_forbidden'; } // Maybe the user is blocked (check this here rather than relying on the parent // method as we have a more specific error message to use here if ( $user->isBlocked() ) { - return false; + return 'blocked-mailpassword'; + } + + return true; + } + + + /** + * Hide the password reset page if resets are disabled. + * @return Bool + */ + function isListed() { + global $wgPasswordResetRoutes, $wgAuth, $wgUser; + + if ( $this->canChangePassword( $wgUser ) === true ) { + return parent::isListed(); } - return parent::isListed(); + return false; } } \ No newline at end of file -- 2.20.1