merging latest master
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 5bb951b..e75237b 100644 (file)
@@ -112,7 +112,7 @@ class Preprocessor_DOM implements Preprocessor {
         *
         * @param $text String: the text to parse
         * @param $flags Integer: bitwise combination of:
-        *          Parser::PTD_FOR_INCLUSION    Handle <noinclude>/<includeonly> as if the text is being
+        *          Parser::PTD_FOR_INCLUSION    Handle "<noinclude>" and "<includeonly>" as if the text is being
         *                                     included. Default is to assume a direct page view.
         *
         * The generated DOM tree must depend only on the input text and the flags.
@@ -235,6 +235,7 @@ class Preprocessor_DOM implements Preprocessor {
 
                $searchBase = "[{<\n"; #}
                $revText = strrev( $text ); // For fast reverse searches
+               $lengthText = strlen( $text );
 
                $i = 0;                     # Input pointer, starts out pointing to a pseudo-newline before the start
                $accum =& $stack->getAccum();   # Current accumulator
@@ -290,7 +291,7 @@ class Preprocessor_DOM implements Preprocessor {
                                        $accum .= htmlspecialchars( substr( $text, $i, $literalLength ) );
                                        $i += $literalLength;
                                }
-                               if ( $i >= strlen( $text ) ) {
+                               if ( $i >= $lengthText ) {
                                        if ( $currentClosing == "\n" ) {
                                                // Do a past-the-end run to finish off the heading
                                                $curChar = '';
@@ -354,10 +355,10 @@ class Preprocessor_DOM implements Preprocessor {
                                                // Unclosed comment in input, runs to end
                                                $inner = substr( $text, $i );
                                                $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
-                                               $i = strlen( $text );
+                                               $i = $lengthText;
                                        } else {
                                                // Search backwards for leading whitespace
-                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0;
+                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0;
                                                // Search forwards for trailing whitespace
                                                // $wsEnd will be the position of the last space (or the '>' if there's none)
                                                $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 );
@@ -438,7 +439,7 @@ class Preprocessor_DOM implements Preprocessor {
                                        } else {
                                                // No end tag -- let it run out to the end of the text.
                                                $inner = substr( $text, $tagEndPos + 1 );
-                                               $i = strlen( $text );
+                                               $i = $lengthText;
                                                $close = '';
                                        }
                                }
@@ -498,16 +499,16 @@ class Preprocessor_DOM implements Preprocessor {
                                $part = $piece->getCurrentPart();
                                // Search back through the input to see if it has a proper close
                                // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient
-                               $wsLength = strspn( $revText, " \t", strlen( $text ) - $i );
+                               $wsLength = strspn( $revText, " \t", $lengthText - $i );
                                $searchStart = $i - $wsLength;
                                if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
                                        // Comment found at line end
                                        // Search for equals signs before the comment
                                        $searchStart = $part->visualEnd;
-                                       $searchStart -= strspn( $revText, " \t", strlen( $text ) - $searchStart );
+                                       $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart );
                                }
                                $count = $piece->count;
-                               $equalsLength = strspn( $revText, '=', strlen( $text ) - $searchStart );
+                               $equalsLength = strspn( $revText, '=', $lengthText - $searchStart );
                                if ( $equalsLength > 0 ) {
                                        if ( $searchStart - $equalsLength == $piece->startPos ) {
                                                // This is just a single string of equals signs on its own line
@@ -926,7 +927,7 @@ class PPFrame_DOM implements PPFrame {
         *
         * @return PPTemplateFrame_DOM
         */
-       function newChild( $args = false, $title = false ) {
+       function newChild( $args = false, $title = false, $indexOffset = 0 ) {
                $namedArgs = array();
                $numberedArgs = array();
                if ( $title === false ) {
@@ -938,6 +939,9 @@ class PPFrame_DOM implements PPFrame {
                                $args = $args->node;
                        }
                        foreach ( $args as $arg ) {
+                               if ( $arg instanceof PPNode ) {
+                                       $arg = $arg->node;
+                               }
                                if ( !$xpath ) {
                                        $xpath = new DOMXPath( $arg->ownerDocument );
                                }
@@ -947,6 +951,7 @@ class PPFrame_DOM implements PPFrame {
                                if ( $nameNodes->item( 0 )->hasAttributes() ) {
                                        // Numbered parameter
                                        $index = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent;
+                                       $index = $index - $indexOffset;
                                        $numberedArgs[$index] = $value->item( 0 );
                                        unset( $namedArgs[$index] );
                                } else {
@@ -1549,6 +1554,10 @@ class PPCustomFrame_DOM extends PPFrame_DOM {
                }
                return $this->args[$index];
        }
+
+       function getArguments() {
+               return $this->args;
+       }
 }
 
 /**
@@ -1650,10 +1659,10 @@ class PPNode_DOM implements PPNode {
        }
 
        /**
-        * Split a <part> node into an associative array containing:
-        *    name          PPNode name
-        *    index         String index
-        *    value         PPNode value
+        * Split a "<part>" node into an associative array containing:
+        *  - name          PPNode name
+        *  - index         String index
+        *  - value         PPNode value
         *
         * @return array
         */
@@ -1673,7 +1682,7 @@ class PPNode_DOM implements PPNode {
        }
 
        /**
-        * Split an <ext> node into an associative array containing name, attr, inner and close
+        * Split an "<ext>" node into an associative array containing name, attr, inner and close
         * All values in the resulting array are PPNodes. Inner and close are optional.
         *
         * @return array
@@ -1700,7 +1709,7 @@ class PPNode_DOM implements PPNode {
        }
 
        /**
-        * Split a <h> node
+        * Split a "<h>" node
         * @return array
         */
        function splitHeading() {