r111906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111905‎ | r111906 | r111907 >
Date:02:12, 20 February 2012
Author:dantman
Status:reverted
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/includes/tidy.conf (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Tidy.php
@@ -41,9 +41,15 @@
4242 dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) );
4343 $this->mMarkerIndex = 0;
4444
 45+ // Replace <mw:editsection> elements with placeholders
4546 $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX,
4647 array( &$this, 'replaceEditSectionLinksCallback' ), $text );
4748
 49+ // Modify inline Microdata <link> and <meta> elements so they say <html-link> and <html-meta> so
 50+ // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config
 51+ $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '<html-$1$2$3', $wrappedtext );
 52+
 53+ // Wrap the whole thing in a doctype and body for Tidy.
4854 $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
4955 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
5056 '<head><title>test</title></head><body>'.$wrappedtext.'</body></html>';
@@ -68,7 +74,13 @@
6975 * @return string
7076 */
7177 public function postprocess( $text ) {
72 - return $this->mTokens->replace( $text );
 78+ // Revert <html-{link,meta}> back to <{link,meta}>
 79+ $text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text );
 80+
 81+ // Restore the contents of placeholder tokens
 82+ $text = $this->mTokens->replace( $text );
 83+
 84+ return $text;
7385 }
7486
7587 }
Index: trunk/phase3/includes/tidy.conf
@@ -18,4 +18,6 @@
1919 fix-uri: no
2020
2121 # Don't strip html5 elements we support
 22+# html-{meta,link} is a hack we use to prevent Tidy from stripping <meta> and <link> used in the body for Microdata
 23+new-empty-tags: html-meta, html-link
2224 new-inline-tags: data, time

Follow-up revisions

RevisionCommit summaryAuthorDate
r111973Revert Microdata improvements in r111891, r111898, r111899, r111901, r111903,...dantman22:32, 20 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111903Followup r111891; Update tidy.conf so that it doesn't strip out <data> and <t...dantman01:01, 20 February 2012

Status & tagging log