wfProfileIn( __METHOD__ );
$removals = $this->parseItemsToRemove();
- if ( !$removals ) {
+ // Bail out early if nothing to do
+ if ( array_reduce( $removals,
+ function( $carry, $item ) {
+ return $carry && !$item;
+ },
+ true
+ ) ) {
wfProfileOut( __METHOD__ );
return array();
}
// XML code paths if possible and fix there.
$html = str_replace( ' ', '', $html );
}
- $html = preg_replace( '/<!--.*?-->|^.*?<body>|<\/body>.*$/s', '', $html );
wfProfileOut( __METHOD__ . '-fixes' );
} else {
$html = $this->html;
}
+ // Remove stuff added by wrapHTML()
+ $html = preg_replace( '/<!--.*?-->|^.*?<body>|<\/body>.*$/s', '', $html );
$html = $this->onHtmlReady( $html );
wfProfileIn( __METHOD__ . '-flatten' );
class HtmlFormatterTest extends MediaWikiTestCase {
/**
* @dataProvider getHtmlData
- * @covers HtmlFormatter::getText
+ *
+ * @param string $input
+ * @param $expectedText
+ * @param array $expectedRemoved
+ * @param callable|bool $callback
*/
public function testTransform( $input, $expectedText,
$expectedRemoved = array(), $callback = false
array(
'<span title="" \' &"><Тест!></span> &<&&&&',
'<span title="" \' &"><Тест!></span> &<&&&&',
+ array(),
+ $removeTags, // Have some rules to trigger a DOM parse
),
// https://bugzilla.wikimedia.org/show_bug.cgi?id=53086
array(
),
);
}
+
+ public function testQuickProcessing() {
+ $f = new MockHtmlFormatter( 'foo' );
+ $f->filterContent();
+ $this->assertFalse( $f->hasDoc, 'HtmlFormatter should not needlessly parse HTML' );
+ }
+}
+
+class MockHtmlFormatter extends HtmlFormatter {
+ public $hasDoc = false;
+
+ public function getDoc() {
+ $this->hasDoc = true;
+ return parent::getDoc();
+ }
}