HTML5 new types for input element
authorAntoine Musso <hashar@free.fr>
Thu, 30 Aug 2012 09:57:22 +0000 (11:57 +0200)
committerAntoine Musso <hashar@free.fr>
Sat, 15 Sep 2012 04:26:55 +0000 (21:26 -0700)
HTML5 introduced new types for the input element. For some reasons we
never added them to Html::openElement which would thus strip them even
in HTML5 mode.

The issue is:
 $wgHtml5 = true;
 Html::element( 'input', array( 'type' => 'color' );
 # -> "<input />"

With this patch, we returns: <input type="color" />

Change-Id: I7de373635d0eb47f788d1d664c3a913c8801efd6

RELEASE-NOTES-1.20
includes/Html.php
tests/phpunit/includes/HtmlTest.php

index 9203f90..b28cc70 100644 (file)
@@ -245,6 +245,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 32552) Drop unused database field cat_hidden from table category.
 * (bug 40214) Category pages no longer use deprecated "width" HTML attribute.
 * (bug 39941) Add missing stylesheets to the installer pages
+* In HTML5 mode, allow new input element types values (such as color, range..)
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index d4d0203..7b79146 100644 (file)
@@ -211,6 +211,23 @@ class Html {
                                'search',
                        );
 
+                       if( $wgHtml5 ) {
+                               $validTypes = array_merge( $validTypes, array(
+                                       'datetime',
+                                       'datetime-local',
+                                       'date',
+                                       'month',
+                                       'time',
+                                       'week',
+                                       'number',
+                                       'range',
+                                       'email',
+                                       'url',
+                                       'search',
+                                       'tel',
+                                       'color',
+                               ) );
+                       }
                        if ( isset( $attribs['type'] )
                        && !in_array( $attribs['type'], $validTypes ) ) {
                                unset( $attribs['type'] );
index 0dd85c1..02a8328 100644 (file)
@@ -365,4 +365,42 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @dataProvider providesHtml5InputTypes
+        */
+       function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
+               $this->enableHTML5();
+               $this->assertEquals(
+                       '<input type="' . $HTML5InputType . '" />',
+                       HTML::element( 'input', array( 'type' => $HTML5InputType ) ),
+                       'In HTML5, HTML::element() should accept type="' . $HTML5InputType . '"'
+               );
+       }
+
+       /**
+        * List of input element types values introduced by HTML5
+        * Full list at http://www.w3.org/TR/html-markup/input.html
+        */
+       function providesHtml5InputTypes() {
+               $types = array(
+                       'datetime',
+                       'datetime-local',
+                       'date',
+                       'month',
+                       'time',
+                       'week',
+                       'number',
+                       'range',
+                       'email',
+                       'url',
+                       'search',
+                       'tel',
+                       'color',
+               );
+               $cases = array();
+               foreach( $types as $type ) {
+                       $cases[] = array( $type );
+               }
+               return $cases;
+       }
 }