--- Parser.php 2004-07-17 21:11:31.000000000 +0200 +++ Parser.php.new 2004-07-17 21:10:50.000000000 +0200 @@ -31,6 +31,7 @@ # define( "MAX_INCLUDE_REPEAT", 5 ); +define( "MAX_INCLUDE_SIZE", 4200 ); # Allowed values for $mOutputType define( "OT_HTML", 1 ); @@ -56,9 +57,11 @@ var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre; # Temporary: - var $mOptions, $mTitle, $mOutputType; + var $mOptions, $mTitle, $mOutputType, $mTemplates, $mTemplatePath; function Parser() { + $this->mTemplates = array(); + $this->mTemplatePath = array(); $this->mTagHooks = array(); $this->clearState(); } @@ -1445,6 +1448,10 @@ /* private */ function replaceVariables( $text, $args = array() ) { global $wgLang, $wgScript, $wgArticlePath; + # Prevent to big inclusions + if(strlen($text)> MAX_INCLUDE_SIZE) + return $text; + $fname = 'Parser::replaceVariables'; wfProfileIn( $fname ); @@ -1620,6 +1627,24 @@ $found = true; } */ + + # Tmp template table test + for($i=0; $imTemplates); $i++) { + if ($this->mTemplates[$i][0] == $part1) { + # Infinite loop test + for($j=0; $jmTemplatePath); $j++) { + if ($this->mTemplatePath[$j] == $part1) { + $noparse = true; + $found = true; + break; + } + } + $text = $this->mTemplates[$i][1]; + $found = true; + break; + } + } + # Load from database if ( !$found ) { $title = Title::newFromText( $part1, NS_TEMPLATE ); @@ -1641,6 +1666,9 @@ $text = '[[' . $title->getPrefixedText() . ']]'; $found = true; } + + # Tmp array insertion + array_push($this->mTemplates, array($part1, $text)); } } @@ -1673,6 +1701,9 @@ $wgLinkCache->suspend(); } + # Add a new level in the templace recursion path + array_push($this->mTemplatePath, $part1); + # Run full parser on the included text $text = $this->stripParse( $text, $newline, $assocArgs ); @@ -1682,6 +1713,8 @@ $wgLinkCache->addLinkObj( $title ); } } + # Empties the template path + $this->mTemplatePath = array(); if ( !$found ) { return $matches[0];