Disable expensive {{REVISIONID}} magic word in miser mode
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 5f7621e..b0c4bf9 100644 (file)
@@ -2592,6 +2592,18 @@ class Parser {
                $ts = wfTimestamp( TS_UNIX, $this->mOptions->getTimestamp() );
                Hooks::run( 'ParserGetVariableValueTs', [ &$parser, &$ts ] );
 
+               // In miser mode, disable words that always cause double-parses on page save (T137900)
+               static $slowRevWords = [ 'revisionid' => true ]; // @TODO: 'revisiontimestamp'
+               if (
+                       isset( $slowRevWords[$index] ) &&
+                       $this->siteConfig->get( 'MiserMode' ) &&
+                       !$this->mOptions->getInterfaceMessage() &&
+                       // @TODO: disallow this word on all namespaces
+                       MWNamespace::isContent( $this->mTitle->getNamespace() )
+               ) {
+                       return $this->mRevisionId ? '-' : '';
+               };
+
                $pageLang = $this->getFunctionLang();
 
                switch ( $index ) {
@@ -3681,7 +3693,6 @@ class Parser {
                $deps = [];
 
                # Loop to fetch the article, with up to 1 redirect
-               // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
                for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
                        # Give extensions a chance to select the revision instead
                        $id = false; # Assume current
@@ -4371,7 +4382,7 @@ class Parser {
                        $anchor = $safeHeadline;
                        $fallbackAnchor = $fallbackHeadline;
                        if ( isset( $refers[$arrayKey] ) ) {
-                               // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall,Generic.Formatting.DisallowMultipleStatements
+                               // phpcs:ignore Generic.Formatting.DisallowMultipleStatements
                                for ( $i = 2; isset( $refers["${arrayKey}_$i"] ); ++$i );
                                $anchor .= "_$i";
                                $linkAnchor .= "_$i";
@@ -4380,7 +4391,7 @@ class Parser {
                                $refers[$arrayKey] = true;
                        }
                        if ( $fallbackHeadline !== false && isset( $refers[$fallbackArrayKey] ) ) {
-                               // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall,Generic.Formatting.DisallowMultipleStatements
+                               // phpcs:ignore Generic.Formatting.DisallowMultipleStatements
                                for ( $i = 2; isset( $refers["${fallbackArrayKey}_$i"] ); ++$i );
                                $fallbackAnchor .= "_$i";
                                $refers["${fallbackArrayKey}_$i"] = true;