Protect MathML from Tidy
authorphysikerwelt <wiki@physikerwelt.de>
Thu, 14 Aug 2014 16:28:36 +0000 (12:28 -0400)
committerphysikerwelt <wiki@physikerwelt.de>
Fri, 22 Aug 2014 16:21:06 +0000 (12:21 -0400)
MediaWiki installations that use the setting
$wgUseTidy = true; are unable to output
MathML since the well defined MathML elements
are filtered out by Tidy. This was reported as
  http://sourceforge.net/p/tidy/patches/84/ .

This change hides MathML blocks from
Tidy.

Bug: 66516
Change-Id: Ib48b91238c3eddd6a86b62f6ce57801d7058f0d8

includes/parser/MWTidy.php
tests/parser/parserTests.txt
tests/phpunit/includes/parser/TidyTest.php

index a108d2b..b310862 100644 (file)
@@ -65,7 +65,9 @@ class MWTidyWrapper {
                // ...and <mw:toc> markers
                $wrappedtext = preg_replace_callback( '/\<\\/?mw:toc\>/',
                        array( &$this, 'replaceCallback' ), $wrappedtext );
-
+               // ... and <math> tags
+               $wrappedtext = preg_replace_callback( '/\<math(.*?)\<\\/math\>/s',
+                       array( &$this, 'replaceCallback' ), $wrappedtext );
                // 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 );
index 1d17fc4..e164b12 100644 (file)
@@ -13927,6 +13927,14 @@ Expansion of multi-line templates in attribute values (bug 6255 sanity check 2)
 
 !! end
 
+!! test
+evil <math>-wiki-tags without Extension:Math enabled
+!! wikitext
+<math><img src="some evil external link"><script>some_evil_javascript();</script></math>
+!! html+tidy
+<p>&lt;math&gt;&lt;img src="some evil external link"&gt;&lt;script&gt;some_evil_javascript();&lt;/script&gt;&lt;/math&gt;</p>
+!! end
+
 ###
 ### Parser hooks (see tests/parser/parserTestsParserHook.php for the <tag> extension)
 ###
index 12aac69..7b2a1da 100644 (file)
@@ -26,6 +26,24 @@ class TidyTest extends MediaWikiTestCase {
        }
 
        public function provideTestWrapping() {
+               $testMathML = <<<'MathML'
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+    <mrow>
+      <mi>a</mi>
+      <mo>&InvisibleTimes;</mo>
+      <msup>
+        <mi>x</mi>
+        <mn>2</mn>
+      </msup>
+      <mo>+</mo>
+      <mi>b</mi>
+      <mo>&InvisibleTimes; </mo>
+      <mi>x</mi>
+      <mo>+</mo>
+      <mi>c</mi>
+    </mrow>
+  </math>
+MathML;
                return array(
                        array(
                                '<mw:editsection page="foo" section="bar">foo</mw:editsection>',
@@ -40,6 +58,7 @@ class TidyTest extends MediaWikiTestCase {
                        array( '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ),
                        array( "<link foo=\"bar\" />\nfoo", '<link foo="bar"/>foo', '<link> should survive tidy' ),
                        array( "<meta foo=\"bar\" />\nfoo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ),
+                       array( $testMathML , $testMathML, '<math> should survive tidy' ),
                );
        }
 }