From a45e20ff11476e5a6daf7ec177cdd0ee5f850b97 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 30 Aug 2012 11:57:22 +0200 Subject: [PATCH] HTML5 new types for input element 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' ); # -> "" With this patch, we returns: Change-Id: I7de373635d0eb47f788d1d664c3a913c8801efd6 --- RELEASE-NOTES-1.20 | 1 + includes/Html.php | 17 +++++++++++++ tests/phpunit/includes/HtmlTest.php | 38 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 9203f90887..b28cc70c10 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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. diff --git a/includes/Html.php b/includes/Html.php index d4d0203ae6..7b79146054 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -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'] ); diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 0dd85c19e3..02a83282ea 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -365,4 +365,42 @@ class HtmlTest extends MediaWikiTestCase { ); } + /** + * @dataProvider providesHtml5InputTypes + */ + function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) { + $this->enableHTML5(); + $this->assertEquals( + '', + 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; + } } -- 2.20.1