(bug 39067) Add support for HTML5 <mark> element.
authorDaniel Friesen <pub-github@nadir-seen-fire.com>
Mon, 6 Aug 2012 10:02:49 +0000 (03:02 -0700)
committerAntoine Musso <hashar@free.fr>
Mon, 19 Nov 2012 08:22:48 +0000 (09:22 +0100)
* whitelist <mark> in tidy and sanitizer
* provides a default styling for mark elements

Change-Id: I23fc2fc558ff0590be04771ef1e75fcfdf240aac

RELEASE-NOTES-1.21
includes/Sanitizer.php
includes/tidy.conf
skins/common/shared.css
tests/phpunit/includes/SanitizerTest.php

index 66b3927..70c6bf8 100644 (file)
@@ -39,6 +39,7 @@ production.
 * (bug 7851) Implemented one-click AJAX patrolling.
 * The <data>, <time>, <meta>, and <link> elements are allowed within WikiText
   for use with Microdata.
+* The HTML5 <mark> tag has been whitelisted.
 
 === Bug fixes in 1.21 ===
 * (bug 40353) SpecialDoubleRedirect should support interwiki redirects.
index c529417..7bb3d93 100644 (file)
@@ -385,7 +385,7 @@ class Sanitizer {
                                'kbd', 'samp'
                        );
                        if ( $wgHtml5 ) {
-                               $htmlpairsStatic = array_merge( $htmlpairsStatic, array( 'data', 'time' ) );
+                               $htmlpairsStatic = array_merge( $htmlpairsStatic, array( 'data', 'time', 'mark' ) );
                        }
                        $htmlsingle = array(
                                'br', 'hr', 'li', 'dt', 'dd'
@@ -1696,6 +1696,7 @@ class Sanitizer {
                        $whitelist += array(
                                'data' => array_merge( $common, array( 'value' ) ),
                                'time' => array_merge( $common, array( 'datetime' ) ),
+                               'mark' => $common,
 
                                // meta and link are only permitted by removeHTMLtags when Microdata
                                // is enabled so we don't bother adding a conditional to hide these
index bced6fd..6c94729 100644 (file)
@@ -19,4 +19,4 @@ fix-uri: no
 # Don't strip html5 elements we support
 # html-{meta,link} is a hack we use to prevent Tidy from stripping <meta> and <link> used in the body for Microdata
 new-empty-tags: html-meta, html-link
-new-inline-tags: video, audio, source, track, bdi, data, time
+new-inline-tags: video, audio, source, track, bdi, data, time, mark
index ed4e8c5..34d3357 100644 (file)
        direction: rtl;
 }
 
+/* User-Agent styles for new HTML5 elements */
+mark {
+       background-color: yellow;
+       color: black;
+}
+
 /* Input types that should follow user direction, like buttons */
 /* TODO: What about buttons in wikipage content ? */
 input[type="submit"],
index dc672ba..6e618e3 100644 (file)
@@ -64,6 +64,46 @@ class SanitizerTest extends MediaWikiTestCase {
                $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "&#88888888888888;" ), 'Invalid numbered entity' );
        }
 
+       /**
+        * @cover Sanitizer::removeHTMLtags
+        * @dataProvider provideHtml5Tags
+        *
+        * @param String $tag Name of an HTML5 element (ie: 'video')
+        * @param Boolean $escaped Wheter sanitizer let the tag in or escape it (ie: '&lt;video&gt;')
+        */
+       function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) {
+
+               # Enable HTML5 mode
+               global $wgHTML5;
+               $save = $wgHTML5;
+               $wgHTML5 = true;
+
+               if( $escaped ) {
+                       $this->assertEquals( "&lt;$tag&gt;",
+                               Sanitizer::removeHTMLtags( "<$tag>" )
+                       );
+               } else {
+                       $this->assertEquals( "<$tag></$tag>\n",
+                               Sanitizer::removeHTMLtags( "<$tag>" )
+                       );
+               }
+               $wgHTML5 = $save;
+       }
+
+       /**
+        * Provide HTML5 tags
+        */
+       function provideHtml5Tags() {
+               $ESCAPED  = true; # We want tag to be escaped
+               $VERBATIM = false;  # We want to keep the tag
+               return array(
+                       array( 'data', $VERBATIM ),
+                       array( 'mark', $VERBATIM ),
+                       array( 'time', $VERBATIM ),
+                       array( 'video', $ESCAPED ),
+               );
+       }
+
        function testSelfClosingTag() {
                $GLOBALS['wgUseTidy'] = false;
                $this->assertEquals(