#14094 When the expansion size is reached, the editor is not warned about it :
authorNicolas Dumazet <nicdumz@users.mediawiki.org>
Mon, 19 May 2008 21:33:47 +0000 (21:33 +0000)
committerNicolas Dumazet <nicdumz@users.mediawiki.org>
Mon, 19 May 2008 21:33:47 +0000 (21:33 +0000)
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
includes/ParserOutput.php
languages/messages/MessagesEn.php
languages/messages/MessagesFr.php
maintenance/language/messages.inc

index 23f29ef..e355833 100644 (file)
@@ -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( '<!-- WARNING: template omitted, post-expand include size too large -->' );
+                       $this->limitationWarn( 'post-expand-template-inclusion' );
                }
 
                if ( $isLocalObj ) {
@@ -3186,6 +3202,7 @@ class Parser
                }
                if ( !$this->incrementIncludeSize( 'arg', strlen( $text ) ) ) {
                        $error = '<!-- WARNING: argument omitted, expansion size too large -->';
+                       $this->limitationWarn( 'post-expand-template-argument' );
                }
 
                if ( $text === false && $object === false ) {
index 7117f71..fd80f1d 100644 (file)
@@ -21,7 +21,7 @@ class ParserOutput
                $mNoGallery,        # No gallery on category page? (__NOGALLERY__)
                $mHeadItems,        # Items to put in the <head> 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 );
index 827fda6..8a56e7a 100644 (file)
@@ -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.',
index e775c1d..0668983 100644 (file)
@@ -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é.',
index 3935ec5..4ea609f 100644 (file)
@@ -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',