Skip to content

Commit

Permalink
PLATFORM-9358 | Ignore Parser processing limit in DPL
Browse files Browse the repository at this point in the history
  • Loading branch information
wladekb committed May 16, 2024
1 parent f022e19 commit 06489d6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions includes/LST.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 );
}
}
}
}

0 comments on commit 06489d6

Please sign in to comment.