http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70980

Revision: 70980
Author:   simetrical
Date:     2010-08-12 19:19:13 +0000 (Thu, 12 Aug 2010)

Log Message:
-----------
Allow HTML5 custom data attributes

HTML5 allows any attribute beginning with "data-" to be used for
site-specific purposes:

http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data

I don't see any reason not to allow this.  It means users won't have to
hackily overload title="" or class="" if they want to store per-element
data for scripts.

Modified Paths:
--------------
    trunk/phase3/RELEASE-NOTES
    trunk/phase3/includes/Sanitizer.php
    trunk/phase3/maintenance/parserTests.txt

Modified: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES  2010-08-12 18:51:35 UTC (rev 70979)
+++ trunk/phase3/RELEASE-NOTES  2010-08-12 19:19:13 UTC (rev 70980)
@@ -146,6 +146,7 @@
 * (bug 11005) Add CSS class to empty pages in Special:Newpages
 * The parser cache is now shared amongst users whose different settings aren't
   used in the page.
+* Any attribute beginning with "data-" can now be used in wikitext, per HTML5.
 
 === Bug fixes in 1.17 ===
 * (bug 17560) Half-broken deletion moved image files to deletion archive

Modified: trunk/phase3/includes/Sanitizer.php
===================================================================
--- trunk/phase3/includes/Sanitizer.php 2010-08-12 18:51:35 UTC (rev 70979)
+++ trunk/phase3/includes/Sanitizer.php 2010-08-12 19:19:13 UTC (rev 70980)
@@ -627,7 +627,7 @@
         * @todo Check for unique id attribute :P
         */
        static function validateAttributes( $attribs, $whitelist ) {
-               global $wgAllowRdfaAttributes, $wgAllowMicrodataAttributes;
+               global $wgAllowRdfaAttributes, $wgAllowMicrodataAttributes, 
$wgHtml5;
 
                $whitelist = array_flip( $whitelist );
                $hrefExp = '/^(' . wfUrlProtocols() . ')[^\s]+$/';
@@ -643,7 +643,8 @@
                                continue;
                        }
 
-                       if( !isset( $whitelist[$attribute] ) ) {
+                       # Allow any attribute beginning with "data-", if in 
HTML5 mode
+                       if ( !($wgHtml5 && preg_match( '/^data-/i', $attribute 
)) && !isset( $whitelist[$attribute] ) ) {
                                continue;
                        }
 

Modified: trunk/phase3/maintenance/parserTests.txt
===================================================================
--- trunk/phase3/maintenance/parserTests.txt    2010-08-12 18:51:35 UTC (rev 
70979)
+++ trunk/phase3/maintenance/parserTests.txt    2010-08-12 19:19:13 UTC (rev 
70980)
@@ -8146,7 +8146,19 @@
 
 !! end
 
+!! test
+HTML5 data attributes
+!! input
+<span data-foo="bar">Baz</span>
+<p data-abc-def_hij="">Quuz</p>
+!! result
+<p><span data-foo="bar">Baz</span>
+</p>
+<p data-abc-def_hij="">Quuz</p>
 
+!! end
+
+
 TODO:
 more images
 more tables



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to