r70980 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70979‎ | r70980 | r70981 >
Date:19:19, 12 August 2010
Author:simetrical
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -8146,7 +8146,19 @@
81478147
81488148 !! end
81498149
 8150+!! test
 8151+HTML5 data attributes
 8152+!! input
 8153+<span data-foo="bar">Baz</span>
 8154+<p data-abc-def_hij="">Quuz</p>
 8155+!! result
 8156+<p><span data-foo="bar">Baz</span>
 8157+</p>
 8158+<p data-abc-def_hij="">Quuz</p>
81508159
 8160+!! end
 8161+
 8162+
81518163 TODO:
81528164 more images
81538165 more tables
Index: trunk/phase3/includes/Sanitizer.php
@@ -627,7 +627,7 @@
628628 * @todo Check for unique id attribute :P
629629 */
630630 static function validateAttributes( $attribs, $whitelist ) {
631 - global $wgAllowRdfaAttributes, $wgAllowMicrodataAttributes;
 631+ global $wgAllowRdfaAttributes, $wgAllowMicrodataAttributes, $wgHtml5;
632632
633633 $whitelist = array_flip( $whitelist );
634634 $hrefExp = '/^(' . wfUrlProtocols() . ')[^\s]+$/';
@@ -643,7 +643,8 @@
644644 continue;
645645 }
646646
647 - if( !isset( $whitelist[$attribute] ) ) {
 647+ # Allow any attribute beginning with "data-", if in HTML5 mode
 648+ if ( !($wgHtml5 && preg_match( '/^data-/i', $attribute )) && !isset( $whitelist[$attribute] ) ) {
648649 continue;
649650 }
650651
Index: trunk/phase3/RELEASE-NOTES
@@ -146,6 +146,7 @@
147147 * (bug 11005) Add CSS class to empty pages in Special:Newpages
148148 * The parser cache is now shared amongst users whose different settings aren't
149149 used in the page.
 150+* Any attribute beginning with "data-" can now be used in wikitext, per HTML5.
150151
151152 === Bug fixes in 1.17 ===
152153 * (bug 17560) Half-broken deletion moved image files to deletion archive

Status & tagging log