From 4ad22c9e3f9c8e11061d5f75d6aca1187c54f41a Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 12 Aug 2010 19:19:13 +0000 Subject: [PATCH] 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. --- RELEASE-NOTES | 1 + includes/Sanitizer.php | 5 +++-- maintenance/parserTests.txt | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index dc18d4031f..8cc23cb860 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -146,6 +146,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (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 diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 8926b28802..cfbda57d38 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -627,7 +627,7 @@ class Sanitizer { * @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 @@ class Sanitizer { 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; } diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 12a2cd1980..b6cfe30d5d 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -8146,6 +8146,18 @@ disabled !! end +!! test +HTML5 data attributes +!! input +Baz +

Quuz

+!! result +

Baz +

+

Quuz

+ +!! end + TODO: more images -- 2.20.1