Removed remaining profile calls
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 6136555..5b71968 100644 (file)
@@ -68,6 +68,7 @@ class Preprocessor_DOM implements Preprocessor {
        /**
         * @param array $values
         * @return PPNode_DOM
+        * @throws MWException
         */
        public function newPartNodeArray( $values ) {
                //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
@@ -85,7 +86,6 @@ class Preprocessor_DOM implements Preprocessor {
 
                $xml .= "</list>";
 
-               wfProfileIn( __METHOD__ . '-loadXML' );
                $dom = new DOMDocument();
                wfSuppressWarnings();
                $result = $dom->loadXML( $xml );
@@ -97,7 +97,6 @@ class Preprocessor_DOM implements Preprocessor {
                        // don't barf when the XML is >256 levels deep
                        $result = $dom->loadXML( $xml, 1 << 19 );
                }
-               wfProfileOut( __METHOD__ . '-loadXML' );
 
                if ( !$result ) {
                        throw new MWException( 'Parameters passed to ' . __METHOD__ . ' result in invalid XML' );
@@ -149,14 +148,12 @@ class Preprocessor_DOM implements Preprocessor {
         * @return PPNode_DOM
         */
        public function preprocessToObj( $text, $flags = 0 ) {
-               wfProfileIn( __METHOD__ );
                global $wgMemc, $wgPreprocessorCacheThreshold;
 
                $xml = false;
                $cacheable = ( $wgPreprocessorCacheThreshold !== false
                        && strlen( $text ) > $wgPreprocessorCacheThreshold );
                if ( $cacheable ) {
-                       wfProfileIn( __METHOD__ . '-cacheable' );
 
                        $cacheKey = wfMemcKey( 'preprocess-xml', md5( $text ), $flags );
                        $cacheValue = $wgMemc->get( $cacheKey );
@@ -169,11 +166,9 @@ class Preprocessor_DOM implements Preprocessor {
                                }
                        }
                        if ( $xml === false ) {
-                               wfProfileIn( __METHOD__ . '-cache-miss' );
                                $xml = $this->preprocessToXml( $text, $flags );
                                $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . $xml;
                                $wgMemc->set( $cacheKey, $cacheValue, 86400 );
-                               wfProfileOut( __METHOD__ . '-cache-miss' );
                                wfDebugLog( "Preprocessor", "Saved preprocessor XML to memcached (key $cacheKey)" );
                        }
                } else {
@@ -186,13 +181,10 @@ class Preprocessor_DOM implements Preprocessor {
                $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' );
                }
 
-               wfProfileIn( __METHOD__ . '-loadXML' );
                $dom = new DOMDocument;
                wfSuppressWarnings();
                $result = $dom->loadXML( $xml );
@@ -207,13 +199,10 @@ class Preprocessor_DOM implements Preprocessor {
                if ( $result ) {
                        $obj = new PPNode_DOM( $dom->documentElement );
                }
-               wfProfileOut( __METHOD__ . '-loadXML' );
 
                if ( $cacheable ) {
-                       wfProfileOut( __METHOD__ . '-cacheable' );
                }
 
-               wfProfileOut( __METHOD__ );
 
                if ( !$result ) {
                        throw new MWException( __METHOD__ . ' generated invalid XML' );
@@ -227,7 +216,6 @@ class Preprocessor_DOM implements Preprocessor {
         * @return string
         */
        public function preprocessToXml( $text, $flags = 0 ) {
-               wfProfileIn( __METHOD__ );
                $rules = array(
                        '{' => array(
                                'end' => '}',
@@ -764,7 +752,6 @@ class Preprocessor_DOM implements Preprocessor {
                $stack->rootAccum .= '</root>';
                $xml = $stack->rootAccum;
 
-               wfProfileOut( __METHOD__ );
 
                return $xml;
        }
@@ -1033,7 +1020,7 @@ class PPFrame_DOM implements PPFrame {
                                if ( $arg instanceof PPNode ) {
                                        $arg = $arg->node;
                                }
-                               if ( !$xpath ) {
+                               if ( !$xpath || $xpath->document !== $arg->ownerDocument ) {
                                        $xpath = new DOMXPath( $arg->ownerDocument );
                                }
 
@@ -1043,11 +1030,17 @@ class PPFrame_DOM implements PPFrame {
                                        // Numbered parameter
                                        $index = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent;
                                        $index = $index - $indexOffset;
+                                       if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
+                                               $this->parser->addTrackingCategory( 'duplicate-args-category' );
+                                       }
                                        $numberedArgs[$index] = $value->item( 0 );
                                        unset( $namedArgs[$index] );
                                } else {
                                        // Named parameter
                                        $name = trim( $this->expand( $nameNodes->item( 0 ), PPFrame::STRIP_COMMENTS ) );
+                                       if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) {
+                                               $this->parser->addTrackingCategory( 'duplicate-args-category' );
+                                       }
                                        $namedArgs[$name] = $value->item( 0 );
                                        unset( $numberedArgs[$name] );
                                }
@@ -1095,7 +1088,6 @@ class PPFrame_DOM implements PPFrame {
                        );
                        return '<span class="error">Expansion depth limit exceeded</span>';
                }
-               wfProfileIn( __METHOD__ );
                ++$expansionDepth;
                if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
                        $this->parser->mHighestExpansionDepth = $expansionDepth;
@@ -1284,7 +1276,6 @@ class PPFrame_DOM implements PPFrame {
                                        $newIterator = $contextNode->childNodes;
                                }
                        } else {
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( __METHOD__ . ': Invalid parameter type' );
                        }
 
@@ -1308,13 +1299,13 @@ class PPFrame_DOM implements PPFrame {
                        }
                }
                --$expansionDepth;
-               wfProfileOut( __METHOD__ );
                return $outStack[0];
        }
 
        /**
         * @param string $sep
         * @param int $flags
+        * @param string|PPNode_DOM|DOMDocument $args,...
         * @return string
         */
        public function implodeWithFlags( $sep, $flags /*, ... */ ) {
@@ -1346,6 +1337,7 @@ class PPFrame_DOM implements PPFrame {
         * This previously called implodeWithFlags but has now been inlined to reduce stack depth
         *
         * @param string $sep
+        * @param string|PPNode_DOM|DOMDocument $args,...
         * @return string
         */
        public function implode( $sep /*, ... */ ) {
@@ -1377,6 +1369,7 @@ class PPFrame_DOM implements PPFrame {
         * with implode()
         *
         * @param string $sep
+        * @param string|PPNode_DOM|DOMDocument $args,...
         * @return array
         */
        public function virtualImplode( $sep /*, ... */ ) {
@@ -1408,6 +1401,7 @@ class PPFrame_DOM implements PPFrame {
         * @param string $start
         * @param string $sep
         * @param string $end
+        * @param string|PPNode_DOM|DOMDocument $args,...
         * @return array
         */
        public function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {