Skip to content

Commit

Permalink
Use recursive parser calls to preserve template dom cache
Browse files Browse the repository at this point in the history
  • Loading branch information
wladekb committed Apr 23, 2024
1 parent 9c8897a commit d45cb7a
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 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,25 @@ public static function spaceOrUnderscore( $pattern ) {
// returns a pettern that matches underscores as well as spaces
return str_replace( ' ', '[ _]', $pattern );
}

public static $useRecursivePreprocess = true;

/**
* @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 {
if ( self::$useRecursivePreprocess ) {
$outputType = $parser->getOutputType();
$parser->setOutputType( OT_PREPROCESS );
$text = $parser->recursivePreprocess( $text );
$parser->setOutputType( $outputType );
return $text;
} else {
return $parser->preprocess( $text, $page, $options );
}
}
}

0 comments on commit d45cb7a

Please sign in to comment.