Only require necessary fields in Special:ResetPass
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 21 Aug 2009 21:06:06 +0000 (21:06 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 21 Aug 2009 21:06:06 +0000 (21:06 +0000)
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
includes/specials/SpecialResetpass.php

index aa168b7..18d7390 100644 (file)
@@ -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
index 4aac1ee..e734385 100644 (file)
@@ -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 );
                        }