From 9bcb7bc8b0a65ef73d774a242b19bada78c7909c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 19 Aug 2009 01:39:05 +0000 Subject: [PATCH] Cleanup from r54770 "Add Html::input() convenience function" Split the giant arrays of attributes/values to one item per line, which makes them easier to look at, easier to grep, and easier to see what's happening when they're changed in diffs. We're not printing; vertical space isn't at a premium. ;) --- includes/Html.php | 76 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/includes/Html.php b/includes/Html.php index fcbe4ea1c6..57f9ba012c 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -42,16 +42,45 @@ class Html { # List of void elements from HTML 5, section 9.1.2 as of 2009-08-10 private static $voidElements = array( - 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', - 'keygen', 'link', 'meta', 'param', 'source' + 'area', + 'base', + 'br', + 'col', + 'command', + 'embed', + 'hr', + 'img', + 'input', + 'keygen', + 'link', + 'meta', + 'param', + 'source', ); # Boolean attributes, which may have the value omitted entirely. Manually # collected from the HTML 5 spec as of 2009-08-10. - private static $boolAttribs = array( 'async', 'autobuffer', 'autofocus', - 'autoplay', 'checked', 'controls', 'defer', 'disabled', - 'formnovalidate', 'hidden', 'ismap', 'loop', 'multiple', 'novalidate', - 'open', 'readonly', 'required', 'reversed', 'scoped', 'seamless' + private static $boolAttribs = array( + 'async', + 'autobuffer', + 'autofocus', + 'autoplay', + 'checked', + 'controls', + 'defer', + 'disabled', + 'formnovalidate', + 'hidden', + 'ismap', + 'loop', + 'multiple', + 'novalidate', + 'open', + 'readonly', + 'required', + 'reversed', + 'scoped', + 'seamless', ); /** @@ -268,13 +297,38 @@ class Html { global $wgHtml5; if ( !$wgHtml5 ) { - if ( !in_array( $type, array( 'hidden', 'text', 'password', - 'checkbox', 'radio', 'file', 'submit', 'image', 'reset', 'button' - ) ) ) { + // With $wgHtml5 off we want to validate as XHTML 1, so we + // strip out any fancy HTML 5-only input types for now. + // + // Whitelist of valid types: + $validTypes = array( + 'hidden', + 'text', + 'password', + 'checkbox', + 'radio', + 'file', + 'submit', + 'image', + 'reset', + 'button', + ); + if ( !in_array( $type, $validTypes ) ) { $type = 'text'; } - foreach ( array( 'autocomplete', 'autofocus', 'max', 'min', 'multiple', - 'pattern', 'placeholder', 'required', 'step' ) as $badAttr ) { + // Here we're blacklisting some HTML5-only attributes... + $html5attribs = array( + 'autocomplete', + 'autofocus', + 'max', + 'min', + 'multiple', + 'pattern', + 'placeholder', + 'required', + 'step', + ); + foreach ( $html5attribs as $badAttr ) { unset( $attribs[$badAttr] ); } } -- 2.20.1