From 3d3aa7c369e21a6bbc25299739adb1725dfe2fc1 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 21 Aug 2009 21:06:06 +0000 Subject: [PATCH] Only require necessary fields in Special:ResetPass This fixes r54567. That made the password fields on Special:ResetPass always required, but in fact the current password should never be required (existing users always might have empty passwords), and the new password is only required if $wgMinimalPasswordLength > 0. This commit also permits passing array( 'required' ) to Html::(rawE|e)lement() instead of array( 'required' => 'meaningless' ), for boolean attribs only. This syntax is used in SpecialResetpass. --- includes/Html.php | 11 +++++++++++ includes/specials/SpecialResetpass.php | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/includes/Html.php b/includes/Html.php index aa168b7de6..18d7390da3 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -195,6 +195,17 @@ class Html { $ret = ''; foreach ( $attribs as $key => $value ) { + # For boolean attributes, support array( 'foo' ) instead of + # requiring array( 'foo' => 'meaningless' ). + if ( is_int( $key ) + && in_array( strtolower( $value ), self::$boolAttribs ) ) { + $key = $value; + } + + # Not technically required in HTML 5, but required in XHTML 1.0, + # and we'd like consistency and better compression anyway. + $key = strtolower( $key ); + # See the "Attributes" section in the HTML syntax part of HTML 5, # 9.1.2.3 as of 2009-08-10. Most attributes can have quotation # marks omitted, but not all. (Although a literal " is not diff --git a/includes/specials/SpecialResetpass.php b/includes/specials/SpecialResetpass.php index 4aac1ee694..e734385762 100644 --- a/includes/specials/SpecialResetpass.php +++ b/includes/specials/SpecialResetpass.php @@ -128,6 +128,8 @@ class SpecialResetpass extends SpecialPage { } function pretty( $fields ) { + global $wgMinimalPasswordLength; + $out = ''; foreach ( $fields as $list ) { list( $name, $label, $type, $value ) = $list; @@ -135,11 +137,17 @@ class SpecialResetpass extends SpecialPage { $field = htmlspecialchars( $value ); } else { $attribs = array( 'id' => $name ); - # All three fields are required, and we should focus the first - # (wpPassword) - $attribs['required'] = ''; + # The current password field is never required; it's possible + # that existing users might have empty passwords on any wiki. + # The two other password fields are required if + # $wgMinimalPasswordLength > 0 (not allowed to set an empty + # password). + if ( ( $name == 'wpNewPassword' || $name == 'wpRetype' ) + && $wgMinimalPasswordLength > 0 ) { + $attribs[] = 'required'; + } if ( $name == 'wpPassword' ) { - $attribs['autofocus'] = ''; + $attribs[] = 'autofocus'; } $field = Html::input( $name, $value, $type, $attribs ); } -- 2.20.1