Add missing wfProfileOut before throwing an exception
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 468802d..7cb91da 100644 (file)
@@ -110,7 +110,7 @@ class Preprocessor_DOM implements Preprocessor {
         * Preprocess some wikitext and return the document tree.
         * This is the ghost of Parser::replace_variables().
         *
-        * @param $text String: the text to parse
+        * @param string $text the text to parse
         * @param $flags Integer: bitwise combination of:
         *          Parser::PTD_FOR_INCLUSION    Handle "<noinclude>" and "<includeonly>" as if the text is being
         *                                     included. Default is to assume a direct page view.
@@ -169,6 +169,10 @@ class Preprocessor_DOM implements Preprocessor {
                $this->parser->mGeneratedPPNodeCount += substr_count( $xml, '<' );
                $max = $this->parser->mOptions->getMaxGeneratedPPNodeCount();
                if ( $this->parser->mGeneratedPPNodeCount > $max ) {
+                       if ( $cacheable ) {
+                               wfProfileOut( __METHOD__ . '-cacheable' );
+                       }
+                       wfProfileOut( __METHOD__ );
                        throw new MWException( __METHOD__ . ': generated node count limit exceeded' );
                }
 
@@ -183,6 +187,11 @@ class Preprocessor_DOM implements Preprocessor {
                        // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep
                        $result = $dom->loadXML( $xml, 1 << 19 );
                        if ( !$result ) {
+                               wfProfileOut( __METHOD__ . '-loadXML' );
+                               if ( $cacheable ) {
+                                       wfProfileOut( __METHOD__ . '-cacheable' );
+                               }
+                               wfProfileOut( __METHOD__ );
                                throw new MWException( __METHOD__ . ' generated invalid XML' );
                        }
                }
@@ -397,7 +406,7 @@ class Preprocessor_DOM implements Preprocessor {
 
                                                if ( $stack->top ) {
                                                        $part = $stack->top->getCurrentPart();
-                                                       if ( !(isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 )) {
+                                                       if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
                                                                $part->visualEnd = $wsStart;
                                                        }
                                                        // Else comments abutting, no change in visual end
@@ -522,7 +531,7 @@ class Preprocessor_DOM implements Preprocessor {
                                if ( $equalsLength > 0 ) {
                                        if ( $searchStart - $equalsLength == $piece->startPos ) {
                                                // This is just a single string of equals signs on its own line
-                                               // Replicate the doHeadings behaviour /={count}(.+)={count}/
+                                               // Replicate the doHeadings behavior /={count}(.+)={count}/
                                                // First find out how many equals signs there really are (don't stop at 6)
                                                $count = $equalsLength;
                                                if ( $count < 3 ) {
@@ -746,7 +755,7 @@ class PPDStack {
                        $class = $this->elementClass;
                        $this->stack[] = new $class( $data );
                }
-               $this->top = $this->stack[ count( $this->stack ) - 1 ];
+               $this->top = $this->stack[count( $this->stack ) - 1];
                $this->accum =& $this->top->getAccum();
        }
 
@@ -757,7 +766,7 @@ class PPDStack {
                $temp = array_pop( $this->stack );
 
                if ( count( $this->stack ) ) {
-                       $this->top = $this->stack[ count( $this->stack ) - 1 ];
+                       $this->top = $this->stack[count( $this->stack ) - 1];
                        $this->accum =& $this->top->getAccum();
                } else {
                        $this->top = self::$false;
@@ -911,7 +920,6 @@ class PPFrame_DOM implements PPFrame {
         */
        var $depth;
 
-
        /**
         * Construct a new preprocessor frame.
         * @param $preprocessor Preprocessor The parent preprocessor
@@ -1015,11 +1023,13 @@ class PPFrame_DOM implements PPFrame {
 
                while ( count( $iteratorStack ) > 1 ) {
                        $level = count( $outStack ) - 1;
-                       $iteratorNode =& $iteratorStack[ $level ];
+                       $iteratorNode =& $iteratorStack[$level];
                        $out =& $outStack[$level];
                        $index =& $indexStack[$level];
 
-                       if ( $iteratorNode instanceof PPNode_DOM ) $iteratorNode = $iteratorNode->node;
+                       if ( $iteratorNode instanceof PPNode_DOM ) {
+                               $iteratorNode = $iteratorNode->node;
+                       }
 
                        if ( is_array( $iteratorNode ) ) {
                                if ( $index >= count( $iteratorNode ) ) {
@@ -1149,9 +1159,7 @@ class PPFrame_DOM implements PPFrame {
 
                                        # Insert a heading marker only for <h> children of <root>
                                        # This is to stop extractSections from going over multiple tree levels
-                                       if ( $contextNode->parentNode->nodeName == 'root'
-                                         && $this->parser->ot['html'] )
-                                       {
+                                       if ( $contextNode->parentNode->nodeName == 'root' && $this->parser->ot['html'] ) {
                                                # Insert heading index marker
                                                $headingIndex = $contextNode->getAttribute( 'i' );
                                                $titleText = $this->title->getPrefixedDBkey();