Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLATFORM-8725 | Use recursive parser calls to preserve template dom cache #7

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions includes/LST.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public static function includeTemplate( $parser, Lister $lister, $dplNr, $articl
}
} else {
// put a red link into the output
$output[0] = $parser->preprocess( '{{' . $defaultTemplate . '|%PAGE%=' . $page . '|%TITLE%=' . $title->getText() . '|%DATE%=' . $date . '|%USER%=' . $user . '}}', $parser->getPage(), $parser->getOptions() );
$output[0] = self::callParserPreprocess( $parser, '{{' . $defaultTemplate . '|%PAGE%=' . $page . '|%TITLE%=' . $title->getText() . '|%DATE%=' . $date . '|%USER%=' . $user . '}}', $parser->getPage(), $parser->getOptions() );
}

unset( $title );
Expand Down Expand Up @@ -754,7 +754,7 @@ public static function includeTemplate( $parser, Lister $lister, $dplNr, $articl
}

$argChain .= '|%DATE%=' . $date . '|%USER%=' . $user . '|%ARGS%=' . str_replace( '|', '§', preg_replace( '/[}]+/', '}', preg_replace( '/[{]+/', '{', substr( $invocation, strlen( $template2 ) + 2 ) ) ) ) . '}}';
$output[++$n] = $parser->preprocess( $argChain, $parser->getPage(), $parser->getOptions() );
$output[++$n] = self::callParserPreprocess( $parser, $argChain, $parser->getPage(), $parser->getOptions() );
}
break;
}
Expand Down Expand Up @@ -888,4 +888,24 @@ public static function spaceOrUnderscore( $pattern ) {
// returns a pettern that matches underscores as well as spaces
return str_replace( ' ', '[ _]', $pattern );
}

/**
wladekb marked this conversation as resolved.
Show resolved Hide resolved
* @param Parser $parser
* @param string $text
* @param ?\MediaWiki\Page\PageReference $page
* @param \ParserOptions $options
* @return string
*/
protected static function callParserPreprocess( Parser $parser, $text, $page, $options ): string {
global $wgDplUseRecursivePreprocess;
if ( $wgDplUseRecursivePreprocess ) {
$outputType = $parser->getOutputType();
$parser->setOutputType( OT_PREPROCESS );
$text = $parser->recursivePreprocess( $text );
$parser->setOutputType( $outputType );
wladekb marked this conversation as resolved.
Show resolved Hide resolved
return $text;
} else {
return $parser->preprocess( $text, $page, $options );
}
}
}