* Add #ifexist invocation count to the limit report comment
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 30 Nov 2007 14:50:48 +0000 (14:50 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 30 Nov 2007 14:50:48 +0000 (14:50 +0000)
* Fix limit report inclusion criteria for new preprocessor -- make it display only for the primary text on edit and page view

includes/Article.php
includes/EditPage.php
includes/Parser.php
includes/ParserOptions.php
includes/Parser_OldPP.php

index d0e6f04..045ea69 100644 (file)
@@ -2496,6 +2496,7 @@ class Article {
                $edit->pst = $this->preSaveTransform( $text );
                $options = new ParserOptions;
                $options->setTidy( true );
+               $options->enableLimitReport();
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
                $edit->oldText = $this->getContent();
                $this->mPreparedEdit = $edit;
index c7d9445..8bb9a78 100644 (file)
@@ -1497,6 +1497,7 @@ END
 
                        if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ;
                        $parserOptions->setTidy(true);
+                       $parserOptions->enableLimitReport();
                        $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n",
                                        $this->mTitle, $parserOptions );
 
index 3374faa..3d81b4f 100644 (file)
@@ -380,14 +380,14 @@ class Parser
                wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
 
                # Information on include size limits, for the benefit of users who try to skirt them
-               if ( max( $this->mIncludeSizes ) > 1000 ) {
+               if ( $this->mOptions->getEnableLimitReport() ) {
                        $max = $this->mOptions->getMaxIncludeSize();
-                       $text .= "<!-- \n" .
-                               "Preprocessor node count: {$this->mPPNodeCount}\n" .
-                               "Post-expand include size: {$this->mIncludeSizes['post-expand']} bytes\n" .
-                               "Template argument size: {$this->mIncludeSizes['arg']} bytes\n" .
-                               "Maximum: $max bytes\n" .
-                               "-->\n";
+                       $limitReport = 
+                               "Preprocessor node count: {$this->mPPNodeCount}/{$this->mOptions->mMaxPPNodeCount}\n" .
+                               "Post-expand include size: {$this->mIncludeSizes['post-expand']}/$max bytes\n" .
+                               "Template argument size: {$this->mIncludeSizes['arg']}/$max bytes\n";
+                       wfRunHooks( 'ParserLimitReport', array( $this, &$limitReport ) );
+                       $text .= "\n<!-- \n$limitReport-->\n";
                }
                $this->mOutput->setText( $text );
                $this->mRevisionId = $oldRevisionId;
index f4ed78d..a499ee2 100644 (file)
@@ -24,6 +24,7 @@ class ParserOptions
        var $mMaxPPNodeCount;            # Maximum number of nodes touched by PPFrame::expand()
        var $mRemoveComments;            # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
        var $mTemplateCallback;          # Callback for template fetching
+       var $mEnableLimitReport;         # Enable limit report in an HTML comment on output
 
        var $mUser;                      # Stored user object, just used to initialise the skin
 
@@ -41,6 +42,7 @@ class ParserOptions
        function getMaxPPNodeCount()                { return $this->mMaxPPNodeCount; }
        function getRemoveComments()                { return $this->mRemoveComments; }
        function getTemplateCallback()              { return $this->mTemplateCallback; }
+       function getEnableLimitReport()             { return $this->mEnableLimitReport; }
 
        function getSkin() {
                if ( !isset( $this->mSkin ) ) {
@@ -72,6 +74,7 @@ class ParserOptions
        function setMaxPPNodeCount( $x )            { return wfSetVar( $this->mMaxPPNodeCount, $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 ); }
 
        function __construct( $user = null ) {
                $this->initialiseFromUser( $user );
@@ -121,6 +124,7 @@ class ParserOptions
                $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
                $this->mRemoveComments = true;
                $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
+               $this->mEnableLimitReport = false;
                wfProfileOut( $fname );
        }
 }
index 4ca8c72..38e426e 100644 (file)
@@ -331,14 +331,14 @@ class Parser_OldPP
                wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
 
                # Information on include size limits, for the benefit of users who try to skirt them
-               if ( max( $this->mIncludeSizes ) > 1000 ) {
+               if ( $this->mOptions->getEnableLimitReport() ) {
                        $max = $this->mOptions->getMaxIncludeSize();
-                       $text .= "<!-- \n" .
-                               "Pre-expand include size: {$this->mIncludeSizes['pre-expand']} bytes\n" .
-                               "Post-expand include size: {$this->mIncludeSizes['post-expand']} bytes\n" .
-                               "Template argument size: {$this->mIncludeSizes['arg']} bytes\n" .
-                               "Maximum: $max bytes\n" .
-                               "-->\n";
+                       $limitReport = 
+                               "Pre-expand include size: {$this->mIncludeSizes['pre-expand']}/$max bytes\n" .
+                               "Post-expand include size: {$this->mIncludeSizes['post-expand']}/$max bytes\n" .
+                               "Template argument size: {$this->mIncludeSizes['arg']}/$max bytes\n";
+                       wfRunHooks( 'ParserLimitReport', array( $this, &$limitReport ) );
+                       $text .= "<!-- \n$limitReport-->\n";
                }
                $this->mOutput->setText( $text );
                $this->mRevisionId = $oldRevisionId;