Index: trunk/phase3/includes/Html.php |
— | — | @@ -105,8 +105,53 @@ |
106 | 106 | * @return string Raw HTML |
107 | 107 | */ |
108 | 108 | public static function rawElement( $element, $attribs = array(), $contents = '' ) { |
109 | | - global $wgWellFormedXml; |
| 109 | + global $wgHtml5, $wgWellFormedXml; |
| 110 | + # This is not required in HTML 5, but let's do it anyway, for |
| 111 | + # consistency and better compression. |
110 | 112 | $element = strtolower( $element ); |
| 113 | + |
| 114 | + # Element-specific hacks to slim down output and ensure validity |
| 115 | + if ( $element == 'input' ) { |
| 116 | + if ( !$wgHtml5 ) { |
| 117 | + # With $wgHtml5 off we want to validate as XHTML 1, so we |
| 118 | + # strip out any fancy HTML 5-only input types for now. |
| 119 | + # |
| 120 | + # Whitelist of valid types: |
| 121 | + $validTypes = array( |
| 122 | + 'hidden', |
| 123 | + 'text', |
| 124 | + 'password', |
| 125 | + 'checkbox', |
| 126 | + 'radio', |
| 127 | + 'file', |
| 128 | + 'submit', |
| 129 | + 'image', |
| 130 | + 'reset', |
| 131 | + 'button', |
| 132 | + ); |
| 133 | + if ( isset( $attribs['type'] ) |
| 134 | + && !in_array( $attribs['type'], $validTypes ) ) { |
| 135 | + # Fall back to type=text, the default |
| 136 | + unset( $attribs['type'] ); |
| 137 | + } |
| 138 | + # Here we're blacklisting some HTML5-only attributes... |
| 139 | + $html5attribs = array( |
| 140 | + 'autocomplete', |
| 141 | + 'autofocus', |
| 142 | + 'max', |
| 143 | + 'min', |
| 144 | + 'multiple', |
| 145 | + 'pattern', |
| 146 | + 'placeholder', |
| 147 | + 'required', |
| 148 | + 'step', |
| 149 | + ); |
| 150 | + foreach ( $html5attribs as $badAttr ) { |
| 151 | + unset( $attribs[$badAttr] ); |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + |
111 | 156 | $start = "<$element" . self::expandAttributes( $attribs ); |
112 | 157 | if ( in_array( $element, self::$voidElements ) ) { |
113 | 158 | if ( $wgWellFormedXml ) { |
— | — | @@ -288,44 +333,6 @@ |
289 | 334 | * @return string Raw HTML |
290 | 335 | */ |
291 | 336 | public static function input( $name, $value = null, $type = 'text', $attribs = array() ) { |
292 | | - global $wgHtml5; |
293 | | - |
294 | | - if ( !$wgHtml5 ) { |
295 | | - // With $wgHtml5 off we want to validate as XHTML 1, so we |
296 | | - // strip out any fancy HTML 5-only input types for now. |
297 | | - // |
298 | | - // Whitelist of valid types: |
299 | | - $validTypes = array( |
300 | | - 'hidden', |
301 | | - 'text', |
302 | | - 'password', |
303 | | - 'checkbox', |
304 | | - 'radio', |
305 | | - 'file', |
306 | | - 'submit', |
307 | | - 'image', |
308 | | - 'reset', |
309 | | - 'button', |
310 | | - ); |
311 | | - if ( !in_array( $type, $validTypes ) ) { |
312 | | - $type = 'text'; |
313 | | - } |
314 | | - // Here we're blacklisting some HTML5-only attributes... |
315 | | - $html5attribs = array( |
316 | | - 'autocomplete', |
317 | | - 'autofocus', |
318 | | - 'max', |
319 | | - 'min', |
320 | | - 'multiple', |
321 | | - 'pattern', |
322 | | - 'placeholder', |
323 | | - 'required', |
324 | | - 'step', |
325 | | - ); |
326 | | - foreach ( $html5attribs as $badAttr ) { |
327 | | - unset( $attribs[$badAttr] ); |
328 | | - } |
329 | | - } |
330 | 337 | if ( $type != 'text' ) { |
331 | 338 | $attribs['type'] = $type; |
332 | 339 | } |