From bddd428304e9fa1785526b8be9c60852a2acd170 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet Date: Mon, 19 May 2008 21:33:47 +0000 Subject: [PATCH] #14094 When the expansion size is reached, the editor is not warned about it : Adding 2 messages + 2 categories, similarly to "Warning: This page contains too many expensive parser function calls" to warn the user when template post include size (or template argument post include size) is too large --- includes/Parser.php | 33 +++++++++++++++++++++++-------- includes/ParserOutput.php | 6 +++--- languages/messages/MessagesEn.php | 4 ++++ languages/messages/MessagesFr.php | 4 ++++ maintenance/language/messages.inc | 4 ++++ 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 23f29ef993..e355833763 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -394,14 +394,7 @@ class Parser } global $wgExpensiveParserFunctionLimit; if ( $this->mExpensiveFunctionCount > $wgExpensiveParserFunctionLimit ) { - if ( is_callable( array( $this->mOutput, 'addWarning' ) ) ) { - $warning = wfMsg( 'expensive-parserfunction-warning', $this->mExpensiveFunctionCount, $wgExpensiveParserFunctionLimit ); - $this->mOutput->addWarning( $warning ); - $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( 'expensive-parserfunction-category' ) ); - if ( $cat ) { - $this->mOutput->addCategory( $cat->getDBkey(), $this->getDefaultSort() ); - } - } + $this->limitationWarn( 'expensive-parserfunction', $this->mExpensiveFunctionCount, $wgExpensiveParserFunctionLimit ); } wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) ); @@ -2702,6 +2695,28 @@ class Parser return $assocArgs; } + /** + * Warn the user when a parser limitation is reached + * Will warn at most once the user per limitation type + * + * @param string $limitationType, should be one of : + * 'expensive-parserfunction' + * 'post-expand-template-argument' + * 'post-expand-template-inclusion' + * @params int $current, $max When an explicit limit has been + * exceeded, provide the values (optional) + */ + function limitationWarn( $limitationType, $current=null, $max=null) { + $msgName = $limitationType . '-warning'; + //does no harm if $current and $max are present but are unnecessary for the message + $warning = wfMsg( $msgName, $current, $max); + $this->mOutput->addWarning( $warning ); + $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( $limitationType . '-category' ) ); + if ( $cat ) { + $this->mOutput->addCategory( $cat->getDBkey(), $this->getDefaultSort() ); + } + } + /** * Return the text of a template, after recursively * replacing any variables or templates within the template. @@ -2988,6 +3003,7 @@ class Parser # Error, oversize inclusion $text = "[[$originalTitle]]" . $this->insertStripItem( '' ); + $this->limitationWarn( 'post-expand-template-inclusion' ); } if ( $isLocalObj ) { @@ -3186,6 +3202,7 @@ class Parser } if ( !$this->incrementIncludeSize( 'arg', strlen( $text ) ) ) { $error = ''; + $this->limitationWarn( 'post-expand-template-argument' ); } if ( $text === false && $object === false ) { diff --git a/includes/ParserOutput.php b/includes/ParserOutput.php index 7117f71eb2..fd80f1dd63 100644 --- a/includes/ParserOutput.php +++ b/includes/ParserOutput.php @@ -21,7 +21,7 @@ class ParserOutput $mNoGallery, # No gallery on category page? (__NOGALLERY__) $mHeadItems, # Items to put in the section $mOutputHooks, # Hook tags as per $wgParserOutputHooks - $mWarnings, # Warning text to be returned to the user. Wikitext formatted. + $mWarnings, # Warning text to be returned to the user. Wikitext formatted, in the key only $mSections, # Table of contents $mProperties; # Name/value pairs to be cached in the DB @@ -68,7 +68,7 @@ class ParserOutput function getNoGallery() { return $this->mNoGallery; } function getSubtitle() { return $this->mSubtitle; } function getOutputHooks() { return (array)$this->mOutputHooks; } - function getWarnings() { return isset( $this->mWarnings ) ? $this->mWarnings : array(); } + function getWarnings() { return array_keys( $this->mWarnings ); } function containsOldMagic() { return $this->mContainsOldMagic; } function setText( $text ) { return wfSetVar( $this->mText, $text ); } @@ -82,7 +82,7 @@ class ParserOutput function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; } function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; } function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; } - function addWarning( $s ) { $this->mWarnings[] = $s; } + function addWarning( $s ) { $this->mWarnings[$s] = 1; } function addOutputHook( $hook, $data = false ) { $this->mOutputHooks[] = array( $hook, $data ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 827fda6e8c..8a56e7a5e1 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1142,6 +1142,10 @@ The deletion log for this page is provided here for convenience:", It should have less than $2, there are now $1.', 'expensive-parserfunction-category' => 'Pages with too many expensive parser function calls', +'post-expand-template-inclusion-warning' => "Warning: Template include size is too large, some templates will not be included.", +'post-expand-template-inclusion-category' => "Pages where template include size is exceeded", +'post-expand-template-argument-warning' => "Warning: This page contains at least one template argument which has a too large expansion size. These arguments have been omitted.", +'post-expand-template-argument-category' => "Pages containing omitted template arguments", # "Undo" feature 'undo-success' => 'The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.', diff --git a/languages/messages/MessagesFr.php b/languages/messages/MessagesFr.php index e775c1dfa6..06689837d5 100644 --- a/languages/messages/MessagesFr.php +++ b/languages/messages/MessagesFr.php @@ -812,6 +812,10 @@ Demandez-vous s’il est réellement approprié de la recréer en vous référan Il devrait en avoir moins de $2 sur le nombre actuel $1.', 'expensive-parserfunction-category' => 'Pages avec trop d’appels dispendieux de fonctions parseurs', +'post-expand-template-inclusion-warning' => "Attention : Cette page contient trop d'inclusions de modèles. Certaines inclusions ne seront pas effectuées.", +'post-expand-template-inclusion-category' => "Pages contenant trop d'inclusions de modèles", +'post-expand-template-argument-warning' => "Attention : Cette page contient au moins un paramètre de modèle dont l'inclusion est rendue impossible. Après extension, celui-ci aurait produit un résultat trop long, il n'a donc pas été inclut" +'post-expand-template-argument-category' => "Pages contenant au moins un paramètre de modèle non évalué", # "Undo" feature 'undo-success' => 'Cette modification va être défaite. Veuillez confirmer les changements (visibles en bas de cette page), puis sauvegarder si vous êtes d’accord. Merci de motiver l’annulation dans la boîte de résumé.', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 3935ec5fe2..4ea609f983 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -561,6 +561,10 @@ $wgMessageStructure = array( 'recreate-deleted-warn', 'expensive-parserfunction-warning', 'expensive-parserfunction-category', + 'post-expand-template-inclusion-warning', + 'post-expand-template-inclusion-category', + 'post-expand-template-argument-warning', + 'post-expand-template-argument-category', ), 'undo' => array( 'undo-success', -- 2.20.1