Use $wgExpensiveParserFunctionLimit over ParserOptions
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 4 May 2012 18:56:28 +0000 (20:56 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Fri, 4 May 2012 18:56:28 +0000 (20:56 +0200)
This allows extensions to set the value

Change-Id: I4a935a00fe02a2bb88a14942e5e3ec6f4e5e833e

includes/parser/Parser.php
includes/parser/ParserOptions.php

index d5868a7..cc47db5 100644 (file)
@@ -462,9 +462,12 @@ class Parser {
                                array_values( $tidyregs ),
                                $text );
                }
-               global $wgExpensiveParserFunctionLimit;
-               if ( $this->mExpensiveFunctionCount > $wgExpensiveParserFunctionLimit ) {
-                       $this->limitationWarn( 'expensive-parserfunction', $this->mExpensiveFunctionCount, $wgExpensiveParserFunctionLimit );
+
+               if ( $this->mExpensiveFunctionCount > $this->mOptions->getExpensiveParserFunctionLimit() ) {
+                       $this->limitationWarn( 'expensive-parserfunction',
+                               $this->mExpensiveFunctionCount,
+                               $this->mOptions->getExpensiveParserFunctionLimit()
+                       );
                }
 
                wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
@@ -472,7 +475,7 @@ class Parser {
                # Information on include size limits, for the benefit of users who try to skirt them
                if ( $this->mOptions->getEnableLimitReport() ) {
                        $max = $this->mOptions->getMaxIncludeSize();
-                       $PFreport = "Expensive parser function count: {$this->mExpensiveFunctionCount}/$wgExpensiveParserFunctionLimit\n";
+                       $PFreport = "Expensive parser function count: {$this->mExpensiveFunctionCount}/{$this->mOptions->getExpensiveParserFunctionLimit()}\n";
                        $limitReport =
                                "NewPP limit report\n" .
                                "Preprocessor node count: {$this->mPPNodeCount}/{$this->mOptions->getMaxPPNodeCount()}\n" .
@@ -3828,12 +3831,8 @@ class Parser {
         * @return Boolean: false if the limit has been exceeded
         */
        function incrementExpensiveFunctionCount() {
-               global $wgExpensiveParserFunctionLimit;
                $this->mExpensiveFunctionCount++;
-               if ( $this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit ) {
-                       return true;
-               }
-               return false;
+               return $this->mExpensiveFunctionCount <= $this->mOptions->getExpensiveParserFunctionLimit();
        }
 
        /**
index 650a175..211fcd6 100644 (file)
@@ -105,6 +105,11 @@ class ParserOptions {
         */
        var $mMaxTemplateDepth;
        
+       /**
+        * Maximum number of calls per parse to expensive parser functions
+        */
+       var $mExpensiveParserFunctionLimit;
+       
        /**
         * Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
         */
@@ -216,6 +221,8 @@ class ParserOptions {
        function getMaxPPNodeCount()                { return $this->mMaxPPNodeCount; }
        function getMaxPPExpandDepth()              { return $this->mMaxPPExpandDepth; }
        function getMaxTemplateDepth()              { return $this->mMaxTemplateDepth; }
+       /* @since 1.20 */
+       function getExpensiveParserFunctionLimit()  { return $this->mExpensiveParserFunctionLimit; }
        function getRemoveComments()                { return $this->mRemoveComments; }
        function getTemplateCallback()              { return $this->mTemplateCallback; }
        function getEnableLimitReport()             { return $this->mEnableLimitReport; }
@@ -301,6 +308,8 @@ class ParserOptions {
        function setMaxIncludeSize( $x )            { return wfSetVar( $this->mMaxIncludeSize, $x ); }
        function setMaxPPNodeCount( $x )            { return wfSetVar( $this->mMaxPPNodeCount, $x ); }
        function setMaxTemplateDepth( $x )          { return wfSetVar( $this->mMaxTemplateDepth, $x ); }
+       /* @since 1.20 */
+       function setExpensiveParserFunctionLimit( $x ) { return wfSetVar( $this->mExpensiveParserFunctionLimit, $x ); }
        function setRemoveComments( $x )            { return wfSetVar( $this->mRemoveComments, $x ); }
        function setTemplateCallback( $x )          { return wfSetVar( $this->mTemplateCallback, $x ); }
        function enableLimitReport( $x = true )     { return wfSetVar( $this->mEnableLimitReport, $x ); }
@@ -395,7 +404,7 @@ class ParserOptions {
                global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages,
                        $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion,
                        $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth,
-                       $wgCleanSignatures, $wgExternalLinkTarget;
+                       $wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit;
 
                wfProfileIn( __METHOD__ );
 
@@ -409,6 +418,7 @@ class ParserOptions {
                $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
                $this->mMaxPPExpandDepth = $wgMaxPPExpandDepth;
                $this->mMaxTemplateDepth = $wgMaxTemplateDepth;
+               $this->mExpensiveParserFunctionLimit = $wgExpensiveParserFunctionLimit;
                $this->mCleanSignatures = $wgCleanSignatures;
                $this->mExternalLinkTarget = $wgExternalLinkTarget;