Disable form validation more thoroughly
authorAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 30 Jun 2010 22:14:36 +0000 (22:14 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 30 Jun 2010 22:14:36 +0000 (22:14 +0000)
Expands on r67283 by not using any HTML5 input types either, except
search.  Otherwise you'd still have problems when changing integer
fields in Special:Preferences, say.  Sad, since in Opera it had a cute
little widget for incrementing/decrementing, and types like email have
some neat effects on platforms like the iPhone (see
<http://diveintohtml5.org/forms.html#type-email>).  But there's no other
way to disable the constraints these impose without using JS, and given
how broken WebKit is right now . . .

includes/Html.php

index 6fe6da8..76abf38 100644 (file)
@@ -155,32 +155,37 @@ class Html {
                        return '';
                }
 
-               # Remove HTML5-only attributes if we aren't doing HTML5
-               if ( !$wgHtml5 ) {
-                       if ( $element == 'input' ) {
-                               # Whitelist of valid XHTML1 types
-                               $validTypes = array(
-                                       'hidden',
-                                       'text',
-                                       'password',
-                                       'checkbox',
-                                       'radio',
-                                       'file',
-                                       'submit',
-                                       'image',
-                                       'reset',
-                                       'button',
-                               );
-                               if ( isset( $attribs['type'] )
-                               && !in_array( $attribs['type'], $validTypes ) ) {
-                                       # Fall back to type=text, the default
-                                       unset( $attribs['type'] );
-                               }
+               # Remove HTML5-only attributes if we aren't doing HTML5, and disable
+               # form validation regardless (see bug 23769 and the more detailed
+               # comment in expandAttributes())
+               if ( $element == 'input' ) {
+                       # Whitelist of types that don't cause validation.  All except
+                       # 'search' are valid in XHTML1.
+                       $validTypes = array(
+                               'hidden',
+                               'text',
+                               'password',
+                               'checkbox',
+                               'radio',
+                               'file',
+                               'submit',
+                               'image',
+                               'reset',
+                               'button',
+                               'search',
+                       );
+                       if ( isset( $attribs['type'] )
+                       && !in_array( $attribs['type'], $validTypes ) ) {
+                               unset( $attribs['type'] );
                        }
-                       if ( $element == 'textarea' && isset( $attribs['maxlength'] ) ) {
-                               unset( $attribs['maxlength'] );
+                       if ( isset( $attribs['type'] ) && $attribs['type'] == 'search'
+                       && !$wgHtml5 ) {
+                               unset( $attribs['type'] );
                        }
                }
+               if ( !$wgHtml5 && $element == 'textarea' && isset( $attribs['maxlength'] ) ) {
+                       unset( $attribs['maxlength'] );
+               }
 
                return "<$element" . self::expandAttributes(
                        self::dropDefaults( $element, $attribs ) ) . '>';