From c10d5a91e033f7c65d8e182b55ae6a3110db7c2f Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 14 Apr 2014 18:31:20 -0700 Subject: [PATCH] HtmlFormatter fixes * Don't fixup HTML if it hasn't been ruined by libxml2 * More detailed profiling Change-Id: Ieabce23819f7563fdf17e3f1dfd621d853dae589 --- includes/HtmlFormatter.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/includes/HtmlFormatter.php b/includes/HtmlFormatter.php index a72fd59f43..7f590e5207 100644 --- a/includes/HtmlFormatter.php +++ b/includes/HtmlFormatter.php @@ -254,6 +254,7 @@ class HtmlFormatter { wfProfileIn( __METHOD__ ); if ( $this->doc ) { + wfProfileIn( __METHOD__ . '-dom' ); if ( $element !== null && !( $element instanceof DOMElement ) ) { $element = $this->doc->getElementById( $element ); } @@ -269,25 +270,30 @@ class HtmlFormatter { $body->appendChild( $element ); } $html = $this->doc->saveHTML(); + wfProfileOut( __METHOD__ . '-dom' ); + + wfProfileIn( __METHOD__ . '-fixes' ); $html = $this->fixLibXml( $html ); + if ( wfIsWindows() ) { + // Cleanup for CRLF misprocessing of unknown origin on Windows. + // + // If this error continues in the future, please track it down in the + // XML code paths if possible and fix there. + $html = str_replace( ' ', '', $html ); + } + $html = preg_replace( '/|^.*?|<\/body>.*$/s', '', $html ); + wfProfileOut( __METHOD__ . '-fixes' ); } else { $html = $this->html; } - if ( wfIsWindows() ) { - // Appears to be cleanup for CRLF misprocessing of unknown origin - // when running server on Windows platform. - // - // If this error continues in the future, please track it down in the - // XML code paths if possible and fix there. - $html = str_replace( ' ', '', $html ); - } - $html = preg_replace( '/|^.*?|<\/body>.*$/s', '', $html ); $html = $this->onHtmlReady( $html ); + wfProfileIn( __METHOD__ . '-flatten' ); if ( $this->elementsToFlatten ) { $elements = implode( '|', $this->elementsToFlatten ); $html = preg_replace( "#]*>#is", '', $html ); } + wfProfileOut( __METHOD__ . '-flatten' ); wfProfileOut( __METHOD__ ); return $html; -- 2.20.1