jenkins-bot has submitted this change and it was merged.
Change subject: Fix Tidy quietly breaking TOC disabling
......................................................................
Fix Tidy quietly breaking TOC disabling
The functionality was introduced in I2889bcb9
but doesn't work in presence if Tidy.
Change-Id: Ibf96cc3bc94fac75fd92ec5b9205011fcb68f0c2
---
M includes/parser/Tidy.php
A tests/phpunit/includes/parser/TidyTest.php
2 files changed, 49 insertions(+), 2 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/parser/Tidy.php b/includes/parser/Tidy.php
index 0625140..32b16aa 100644
--- a/includes/parser/Tidy.php
+++ b/includes/parser/Tidy.php
@@ -61,7 +61,10 @@
// Replace <mw:editsection> elements with placeholders
$wrappedtext = preg_replace_callback(
ParserOutput::EDITSECTION_REGEX,
- array( &$this, 'replaceEditSectionLinksCallback' ),
$text );
+ array( &$this, 'replaceCallback' ), $text );
+ // ...and <mw:toc> markers
+ $wrappedtext = preg_replace_callback( '/\<\\/?mw:toc\>/',
+ 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
@@ -80,7 +83,7 @@
*
* @return string
*/
- function replaceEditSectionLinksCallback( $m ) {
+ function replaceCallback( $m ) {
$marker = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}" .
Parser::MARKER_SUFFIX;
$this->mMarkerIndex++;
$this->mTokens->setPair( $marker, $m[0] );
diff --git a/tests/phpunit/includes/parser/TidyTest.php
b/tests/phpunit/includes/parser/TidyTest.php
new file mode 100644
index 0000000..57a88b9
--- /dev/null
+++ b/tests/phpunit/includes/parser/TidyTest.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * @group Parser
+ */
+class TidyTest extends MediaWikiTestCase {
+ public function setUp() {
+ parent::setUp();
+ $check = MWTidy::tidy( '' );
+ if ( strpos( $check, '<!--' ) !== false ) {
+ $this->markTestSkipped( 'Tidy not found' );
+ }
+ }
+
+ /**
+ * @dataProvider provideTestWrapping
+ */
+ public function testTidyWrapping( $expected, $text, $msg = '' ) {
+ $text = MWTidy::tidy( $text );
+ // We don't care about where Tidy wants to stick is <p>s
+ $text = trim( preg_replace( '#</?p>#', '', $text ) );
+ // Windows, we love you!
+ $text = str_replace( "\r", '', $text );
+ $this->assertEquals( $expected, $text, $msg );
+ }
+
+ public function provideTestWrapping() {
+ return array(
+ array(
+ '<mw:editsection page="foo"
section="bar">foo</mw:editsection>',
+ '<mw:editsection page="foo"
section="bar">foo</mw:editsection>',
+ '<mw:editsection> should survive tidy'
+ ),
+ array(
+ '<editsection page="foo"
section="bar">foo</editsection>',
+ '<editsection page="foo"
section="bar">foo</editsection>',
+ '<editsection> should survive tidy'
+ ),
+ 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' ),
+ );
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/91902
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf96cc3bc94fac75fd92ec5b9205011fcb68f0c2
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits