r91987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91986‎ | r91987 | r91988 >
Date:19:09, 12 July 2011
Author:mah
Status:resolved
Tags:
Comment:
followup r91985 — remove duplication of code per ^demon's suggestion.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialPasswordReset.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialPasswordReset.php
@@ -35,23 +35,13 @@
3636 public function userCanExecute( User $user ) {
3737 global $wgPasswordResetRoutes, $wgAuth;
3838
39 - // Maybe password resets are disabled, or there are no allowable routes
40 - if ( !is_array( $wgPasswordResetRoutes ) ||
41 - !in_array( true, array_values( $wgPasswordResetRoutes ) ) ) {
42 - throw new ErrorPageError( 'internalerror', 'passwordreset-disabled' );
43 - }
44 -
45 - // Maybe the external auth plugin won't allow local password changes
46 - if ( !$wgAuth->allowPasswordChange() ) {
 39+ $error = $this->canChangePassword( $user );
 40+ if ( is_string( $error ) ) {
 41+ throw new ErrorPageError( 'internalerror', $error );
 42+ } else if ( !$error ) {
4743 throw new ErrorPageError( 'internalerror', 'resetpass_forbidden' );
4844 }
4945
50 - // Maybe the user is blocked (check this here rather than relying on the parent
51 - // method as we have a more specific error message to use here
52 - if ( $user->isBlocked() ) {
53 - throw new ErrorPageError( 'internalerror', 'blocked-mailpassword' );
54 - }
55 -
5646 return parent::userCanExecute( $user );
5747 }
5848
@@ -224,30 +214,41 @@
225215 $this->getOutput()->returnToMain();
226216 }
227217
228 - /**
229 - * Hide the password reset page if resets are disabled.
230 - * @return Bool
231 - */
232 - function isListed() {
 218+ function canChangePassword(User $user) {
233219 global $wgPasswordResetRoutes, $wgAuth;
234220
235221 // Maybe password resets are disabled, or there are no allowable routes
236222 if ( !is_array( $wgPasswordResetRoutes ) ||
237223 !in_array( true, array_values( $wgPasswordResetRoutes ) ) ) {
238 - return false;
 224+ return 'passwordreset-disabled';
239225 }
240226
241227 // Maybe the external auth plugin won't allow local password changes
242228 if ( !$wgAuth->allowPasswordChange() ) {
243 - return false;
 229+ return 'resetpass_forbidden';
244230 }
245231
246232 // Maybe the user is blocked (check this here rather than relying on the parent
247233 // method as we have a more specific error message to use here
248234 if ( $user->isBlocked() ) {
249 - return false;
 235+ return 'blocked-mailpassword';
250236 }
251237
252 - return parent::isListed();
 238+ return true;
253239 }
 240+
 241+
 242+ /**
 243+ * Hide the password reset page if resets are disabled.
 244+ * @return Bool
 245+ */
 246+ function isListed() {
 247+ global $wgPasswordResetRoutes, $wgAuth, $wgUser;
 248+
 249+ if ( $this->canChangePassword( $wgUser ) === true ) {
 250+ return parent::isListed();
 251+ }
 252+
 253+ return false;
 254+ }
254255 }
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91985Bug #29807 — Special:PasswordReset listed on Special:SpecialPages when Auth...mah18:44, 12 July 2011

Status & tagging log