From 06489d69f3ddc0e89d5b0d3961bb0b02e6643477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=C5=82adys=C5=82aw=20Bodzek?= Date: Wed, 15 May 2024 21:42:28 +0200 Subject: [PATCH] PLATFORM-9358 | Ignore Parser processing limit in DPL --- includes/LST.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/includes/LST.php b/includes/LST.php index 84cacddf..ef293aa4 100644 --- a/includes/LST.php +++ b/includes/LST.php @@ -915,6 +915,7 @@ public static function spaceOrUnderscore( $pattern ) { protected static function callParserPreprocess( Parser $parser, $text, $page, $options ): string { global $wgDplUseRecursivePreprocess; if ( $wgDplUseRecursivePreprocess ) { + self::softResetParser( $parser ); $parser->setOutputType( OT_PREPROCESS ); $text = $parser->recursivePreprocess( $text ); @@ -923,4 +924,36 @@ protected static function callParserPreprocess( Parser $parser, $text, $page, $o return $parser->preprocess( $text, $page, $options ); } } + + /** + * Reset Parser's internal counters to avoid kicking in the limits when rendering long lists of results. + */ + private static function softResetParser( Parser $parser ): void { + self::setParserProperties( $parser, [ + 'mStripState' => new \StripState( $parser ), + 'mIncludeSizes' => [ + 'post-expand' => 0, + 'arg' => 0, + ], + 'mPPNodeCount' => 0, + 'mHighestExpansionDepth' => 0, + 'mExpensiveFunctionCount' => 0, + ] ); + } + + private static function setParserProperties( Parser $parser, array $properties ): void { + static $reflectionCache = []; + foreach ( $properties as $property => $value ) { + if ( !array_key_exists( $property, $reflectionCache ) ) { + try { + $reflectionCache[$property] = ( new \ReflectionClass( Parser::class ) )->getProperty( $property ); + } catch ( \ReflectionException ) { + $reflectionCache[$property] = null; + } + } + if ( $reflectionCache[$property] ) { + $reflectionCache[$property]->setValue( $parser, $value ); + } + } + } }