mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SyntaxHighlight_GeSHi
synced 2024-11-27 15:50:37 +00:00
Count only real highlighting as expensive parser tag hooks
Skip the expensive check, for example when no highlighting is wanted because there is no lexer Also all validation of the tag is now processed and invalid tags also not counted. Bug: T316858 Change-Id: Ifad9a9a14fae92463c345fb12defb41f14c2e1f3
This commit is contained in:
parent
6ca610c484
commit
fe6415836d
|
@ -172,11 +172,6 @@ class SyntaxHighlight extends ExtensionTagHandler {
|
|||
// Replace strip markers (For e.g. {{#tag:syntaxhighlight|<nowiki>...}})
|
||||
$out = $parser->getStripState()->unstripNoWiki( $text ?? '' );
|
||||
|
||||
if ( !$parser->incrementExpensiveFunctionCount() ) {
|
||||
// Highlighting is expensive, return unstyled
|
||||
return self::plainCodeWrap( $out, isset( $args['inline'] ) );
|
||||
}
|
||||
|
||||
$result = self::processContent( $out, $args, $parser );
|
||||
foreach ( $result['cats'] as $cat ) {
|
||||
$parser->addTrackingCategory( $cat );
|
||||
|
@ -242,9 +237,10 @@ class SyntaxHighlight extends ExtensionTagHandler {
|
|||
* @param string $code
|
||||
* @param string|null $lang
|
||||
* @param array $args
|
||||
* @param Parser|null $parser Parser, if generating content to be parsed.
|
||||
* @return Status
|
||||
*/
|
||||
private static function highlightInner( $code, $lang = null, $args = [] ) {
|
||||
private static function highlightInner( $code, $lang = null, $args = [], ?Parser $parser = null ) {
|
||||
$status = new Status;
|
||||
|
||||
$lexer = self::getLexer( $lang );
|
||||
|
@ -282,6 +278,12 @@ class SyntaxHighlight extends ExtensionTagHandler {
|
|||
return $status;
|
||||
}
|
||||
|
||||
if ( $parser && !$parser->incrementExpensiveFunctionCount() ) {
|
||||
// Highlighting is expensive, return unstyled
|
||||
$status->value = self::plainCodeWrap( $code, $isInline );
|
||||
return $status;
|
||||
}
|
||||
|
||||
$options = [
|
||||
'cssclass' => self::HIGHLIGHT_CSS_CLASS,
|
||||
'encoding' => 'utf-8',
|
||||
|
@ -372,7 +374,7 @@ class SyntaxHighlight extends ExtensionTagHandler {
|
|||
* code as its value.
|
||||
*/
|
||||
public static function highlight( $code, $lang = null, $args = [], ?Parser $parser = null ) {
|
||||
$status = self::highlightInner( $code, $lang, $args );
|
||||
$status = self::highlightInner( $code, $lang, $args, $parser );
|
||||
$output = $status->getValue();
|
||||
|
||||
$isInline = isset( $args['inline'] );
|
||||
|
|
Loading…
Reference in a new issue