From: Mark A. Hershberger Date: Tue, 12 Jul 2011 19:09:20 +0000 (+0000) Subject: followup r91985 — remove duplication of code per ^demon's suggestion. X-Git-Tag: 1.31.0-rc.0~28901 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=616096da5c541e4d3d60244d26fa50eb74784511;hp=eb09d10fa6dbf03a723d3ba5d9e794414f288b76;p=lhc%2Fweb%2Fwiklou.git followup r91985 — remove duplication of code per ^demon's suggestion. --- 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