From cd8b5fad98fc32bb84b6600c4e268362a26f4fba Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 30 Nov 2007 14:50:48 +0000 Subject: [PATCH] * Add #ifexist invocation count to the limit report comment * Fix limit report inclusion criteria for new preprocessor -- make it display only for the primary text on edit and page view --- includes/Article.php | 1 + includes/EditPage.php | 1 + includes/Parser.php | 14 +++++++------- includes/ParserOptions.php | 4 ++++ includes/Parser_OldPP.php | 14 +++++++------- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index d0e6f04de0..045ea69993 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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; diff --git a/includes/EditPage.php b/includes/EditPage.php index c7d94452c3..8bb9a78a42 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 ); diff --git a/includes/Parser.php b/includes/Parser.php index 3374faa257..3d81b4f666 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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"; + $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"; } $this->mOutput->setText( $text ); $this->mRevisionId = $oldRevisionId; diff --git a/includes/ParserOptions.php b/includes/ParserOptions.php index f4ed78db37..a499ee260c 100644 --- a/includes/ParserOptions.php +++ b/includes/ParserOptions.php @@ -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 ); } } diff --git a/includes/Parser_OldPP.php b/includes/Parser_OldPP.php index 4ca8c7287f..38e426e6dd 100644 --- a/includes/Parser_OldPP.php +++ b/includes/Parser_OldPP.php @@ -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"; + $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"; } $this->mOutput->setText( $text ); $this->mRevisionId = $oldRevisionId; -- 2.20.1