Merge "Add a sort parameter to SearchEngine"
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 6136555..e642c96 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)
@@ -149,7 +150,6 @@ class Preprocessor_DOM implements Preprocessor {
         * @return PPNode_DOM
         */
        public function preprocessToObj( $text, $flags = 0 ) {
-               wfProfileIn( __METHOD__ );
                global $wgMemc, $wgPreprocessorCacheThreshold;
 
                $xml = false;
@@ -188,7 +188,6 @@ class Preprocessor_DOM implements Preprocessor {
                        if ( $cacheable ) {
                                wfProfileOut( __METHOD__ . '-cacheable' );
                        }
-                       wfProfileOut( __METHOD__ );
                        throw new MWException( __METHOD__ . ': generated node count limit exceeded' );
                }
 
@@ -213,7 +212,6 @@ class Preprocessor_DOM implements Preprocessor {
                        wfProfileOut( __METHOD__ . '-cacheable' );
                }
 
-               wfProfileOut( __METHOD__ );
 
                if ( !$result ) {
                        throw new MWException( __METHOD__ . ' generated invalid XML' );
@@ -227,7 +225,6 @@ class Preprocessor_DOM implements Preprocessor {
         * @return string
         */
        public function preprocessToXml( $text, $flags = 0 ) {
-               wfProfileIn( __METHOD__ );
                $rules = array(
                        '{' => array(
                                'end' => '}',
@@ -764,7 +761,6 @@ class Preprocessor_DOM implements Preprocessor {
                $stack->rootAccum .= '</root>';
                $xml = $stack->rootAccum;
 
-               wfProfileOut( __METHOD__ );
 
                return $xml;
        }
@@ -1033,7 +1029,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 +1039,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 +1097,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 +1285,6 @@ class PPFrame_DOM implements PPFrame {
                                        $newIterator = $contextNode->childNodes;
                                }
                        } else {
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( __METHOD__ . ': Invalid parameter type' );
                        }
 
@@ -1308,13 +1308,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 +1346,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 +1378,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 +1410,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 /*, ... */ ) {