Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
index ad5155b..f455a1d 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Preprocessor using PHP arrays
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Parser
  */
@@ -32,7 +47,7 @@ class Preprocessor_Hash implements Preprocessor {
        }
 
        /**
-        * @param $args
+        * @param $args array
         * @return PPCustomFrame_Hash
         */
        function newCustomFrame( $args ) {
@@ -153,9 +168,6 @@ class Preprocessor_Hash implements Preprocessor {
                        $ignoredElements = array( 'includeonly' );
                        $xmlishElements[] = 'includeonly';
                }
-               // `dws' stands for "discard white spaces". `<dws>' and all the whitespaces afer it are
-               // discarded.
-               $xmlishElements[] = 'dws';
                $xmlishRegex = implode( '|', array_merge( $xmlishElements, $ignoredTags ) );
 
                // Use "A" modifier (anchored) instead of "^", because ^ doesn't work with an offset
@@ -353,17 +365,6 @@ class Preprocessor_Hash implements Preprocessor {
                                }
 
                                $tagStartPos = $i;
-
-                               // Handle tag dws.
-                               if ( $name == 'dws' ) {
-                                       $i = $tagEndPos + 1;
-                                       if ( preg_match( '/\s*/', $text, $matches, 0, $i ) ) {
-                                               $i += strlen( $matches[0] );
-                                       }
-                                       $accum->addNodeWithText( 'ignore', substr( $text, $tagStartPos, $i - $tagStartPos ) );
-                                       continue;
-                               }
-
                                if ( $text[$tagEndPos-1] == '/' ) {
                                        // Short end tag
                                        $attrEnd = $tagEndPos - 1;
@@ -442,7 +443,7 @@ class Preprocessor_Hash implements Preprocessor {
                        } elseif ( $found == 'line-end' ) {
                                $piece = $stack->top;
                                // A heading must be open, otherwise \n wouldn't have been in the search list
-                               assert( $piece->open == "\n" );
+                               assert( '$piece->open == "\n"' );
                                $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
@@ -883,11 +884,11 @@ class PPFrame_Hash implements PPFrame {
         * $args is optionally a multi-root PPNode or array containing the template arguments
         *
         * @param $args PPNode_Hash_Array|array
-        * @param $title Title|false
+        * @param $title Title|bool
         *
         * @return PPTemplateFrame_Hash
         */
-       function newChild( $args = false, $title = false ) {
+       function newChild( $args = false, $title = false, $indexOffset = 0 ) {
                $namedArgs = array();
                $numberedArgs = array();
                if ( $title === false ) {
@@ -903,8 +904,9 @@ class PPFrame_Hash implements PPFrame {
                                $bits = $arg->splitArg();
                                if ( $bits['index'] !== '' ) {
                                        // Numbered parameter
-                                       $numberedArgs[$bits['index']] = $bits['value'];
-                                       unset( $namedArgs[$bits['index']] );
+                                       $index = $bits['index'] - $indexOffset;
+                                       $numberedArgs[$index] = $bits['value'];
+                                       unset( $namedArgs[$index] );
                                } else {
                                        // Named parameter
                                        $name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
@@ -929,12 +931,23 @@ class PPFrame_Hash implements PPFrame {
                }
 
                if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
+                       $this->parser->limitationWarn( 'node-count-exceeded',
+                                       $this->parser->mPPNodeCount,
+                                       $this->parser->mOptions->getMaxPPNodeCount()
+                       );
                        return '<span class="error">Node-count limit exceeded</span>';
                }
                if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
+                       $this->parser->limitationWarn( 'expansion-depth-exceeded',
+                                       $expansionDepth,
+                                       $this->parser->mOptions->getMaxPPExpandDepth()
+                       );
                        return '<span class="error">Expansion depth limit exceeded</span>';
                }
                ++$expansionDepth;
+               if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
+                       $this->parser->mHighestExpansionDepth = $expansionDepth;
+               }
 
                $outStack = array( '', '' );
                $iteratorStack = array( false, $root );
@@ -1484,6 +1497,10 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
                }
                return $this->args[$index];
        }
+
+       function getArguments() {
+               return $this->args;
+       }
 }
 
 /**