https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111906
Revision: 111906
Author: dantman
Date: 2012-02-20 02:12:48 +0000 (Mon, 20 Feb 2012)
Log Message:
-----------
Followup r111903; Introduce a new Tidy hack to prevent tidy from stripping the
<link> and <meta> elements from the body which are used in Microdata.
We do this by replacing every <link> and <meta> with a <html-link> or
<html-meta> element and adding html-link and html-meta to tidy's new-empty-tags
config so that Tidy doesn't strip it, and then restoring the <html-*> elements
back to normal.
Modified Paths:
--------------
trunk/phase3/includes/parser/Tidy.php
trunk/phase3/includes/tidy.conf
Modified: trunk/phase3/includes/parser/Tidy.php
===================================================================
--- trunk/phase3/includes/parser/Tidy.php 2012-02-20 01:58:23 UTC (rev
111905)
+++ trunk/phase3/includes/parser/Tidy.php 2012-02-20 02:12:48 UTC (rev
111906)
@@ -41,9 +41,15 @@
dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand(
0, 0x7fffffff ) );
$this->mMarkerIndex = 0;
+ // Replace <mw:editsection> elements with placeholders
$wrappedtext = preg_replace_callback(
ParserOutput::EDITSECTION_REGEX,
array( &$this, 'replaceEditSectionLinksCallback' ),
$text );
+ // Modify inline Microdata <link> and <meta> elements so they
say <html-link> and <html-meta> so
+ // we can trick Tidy into not stripping them out by including
them in tidy's new-empty-tags config
+ $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!',
'<html-$1$2$3', $wrappedtext );
+
+ // Wrap the whole thing in a doctype and body for Tidy.
$wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"'.
'
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
'<head><title>test</title></head><body>'.$wrappedtext.'</body></html>';
@@ -68,7 +74,13 @@
* @return string
*/
public function postprocess( $text ) {
- return $this->mTokens->replace( $text );
+ // Revert <html-{link,meta}> back to <{link,meta}>
+ $text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!',
'<$1$2$3', $text );
+
+ // Restore the contents of placeholder tokens
+ $text = $this->mTokens->replace( $text );
+
+ return $text;
}
}
Modified: trunk/phase3/includes/tidy.conf
===================================================================
--- trunk/phase3/includes/tidy.conf 2012-02-20 01:58:23 UTC (rev 111905)
+++ trunk/phase3/includes/tidy.conf 2012-02-20 02:12:48 UTC (rev 111906)
@@ -18,4 +18,6 @@
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: data, time
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs