HtmlFormatter fixes
authorMax Semenik <maxsem.wiki@gmail.com>
Tue, 15 Apr 2014 01:31:20 +0000 (18:31 -0700)
committerMax Semenik <maxsem.wiki@gmail.com>
Tue, 15 Apr 2014 01:31:20 +0000 (18:31 -0700)
* Don't fixup HTML if  it hasn't been ruined by libxml2
* More detailed profiling

Change-Id: Ieabce23819f7563fdf17e3f1dfd621d853dae589

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;