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();
}
* specify the $element in the method it'll change the underlying dom and you won't be able to get
* it back.
*
- * @param DOMElement|string|null $element ID of element to get HTML from or false to get it from the whole tree
+ * @param DOMElement|string|null $element ID of element to get HTML from or
+ * false to get it from the whole tree
* @return string Processed HTML
*/
public function getText( $element = null ) {
// 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' );