r91985 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91984‎ | r91985 | r91986 >
Date:18:44, 12 July 2011
Author:mah
Status:resolved (Comments)
Tags:
Comment:
Bug #29807 — Special:PasswordReset listed on Special:SpecialPages when Authplugin allowPasswordChange() is false

After my spanking last week, I've gone over the patch more closely this time.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialPasswordReset.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialPasswordReset.php
@@ -36,9 +36,8 @@
3737 global $wgPasswordResetRoutes, $wgAuth;
3838
3939 // Maybe password resets are disabled, or there are no allowable routes
40 - if ( !is_array( $wgPasswordResetRoutes )
41 - || !in_array( true, array_values( $wgPasswordResetRoutes ) ) )
42 - {
 40+ if ( !is_array( $wgPasswordResetRoutes ) ||
 41+ !in_array( true, array_values( $wgPasswordResetRoutes ) ) ) {
4342 throw new ErrorPageError( 'internalerror', 'passwordreset-disabled' );
4443 }
4544
@@ -224,4 +223,31 @@
225224 $this->getOutput()->addWikiMsg( 'passwordreset-emailsent' );
226225 $this->getOutput()->returnToMain();
227226 }
228 -}
 227+
 228+ /**
 229+ * Hide the password reset page if resets are disabled.
 230+ * @return Bool
 231+ */
 232+ function isListed() {
 233+ global $wgPasswordResetRoutes, $wgAuth;
 234+
 235+ // Maybe password resets are disabled, or there are no allowable routes
 236+ if ( !is_array( $wgPasswordResetRoutes ) ||
 237+ !in_array( true, array_values( $wgPasswordResetRoutes ) ) ) {
 238+ return false;
 239+ }
 240+
 241+ // Maybe the external auth plugin won't allow local password changes
 242+ if ( !$wgAuth->allowPasswordChange() ) {
 243+ return false;
 244+ }
 245+
 246+ // Maybe the user is blocked (check this here rather than relying on the parent
 247+ // method as we have a more specific error message to use here
 248+ if ( $user->isBlocked() ) {
 249+ return false;
 250+ }
 251+
 252+ return parent::isListed();
 253+ }
 254+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r91987followup r91985 — remove duplication of code per ^demon's suggestion.mah19:09, 12 July 2011

Comments

#Comment by 😂 (talk | contribs)   18:48, 12 July 2011

The duplication here is kind of ehhh. Maybe refactor these checks so both code paths can reuse the same code?

#Comment by Aaron Schulz (talk | contribs)   17:59, 25 July 2011

I don't think isListed() needs to check

!is_array( $wgPasswordResetRoutes )...

Status & tagging log