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 15, 2024
1 parent f022e19 commit 7121868
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 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,35 @@ protected static function callParserPreprocess( Parser $parser, $text, $page, $o
return $parser->preprocess( $text, $page, $options );
}
}

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;
}
}
}
foreach ( $properties as $property => $value ) {
if ( $reflectionCache[$property] ) {
$reflectionCache[$property]->setValue( $parser, $value );
}
}
}
}

0 comments on commit 7121868

Please sign in to comment.