Merge "HtmlFormatter fixes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 16 Apr 2014 20:36:00 +0000 (20:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 16 Apr 2014 20:36:00 +0000 (20:36 +0000)
includes/HtmlFormatter.php

index a72fd59..7f590e5 100644 (file)
@@ -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( '&#13;', '', $html );
+                       }
+                       $html = preg_replace( '/<!--.*?-->|^.*?<body>|<\/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( '&#13;', '', $html );
-               }
-               $html = preg_replace( '/<!--.*?-->|^.*?<body>|<\/body>.*$/s', '', $html );
                $html = $this->onHtmlReady( $html );
 
+               wfProfileIn( __METHOD__ . '-flatten' );
                if ( $this->elementsToFlatten ) {
                        $elements = implode( '|', $this->elementsToFlatten );
                        $html = preg_replace( "#</?($elements)\\b[^>]*>#is", '', $html );
                }
+               wfProfileOut( __METHOD__ . '-flatten' );
 
                wfProfileOut( __METHOD__ );
                return $html;