diff options
author | Umherirrender <umherirrender_de.wp@web.de> | 2024-11-12 23:37:36 +0100 |
---|---|---|
committer | Umherirrender <umherirrender_de.wp@web.de> | 2025-01-09 21:43:24 +0100 |
commit | 6965cdc86f576bdd1f02dc6aae79abf8e797b8ee (patch) | |
tree | 30b51c96ac1bd71fcd1506fd480c70b5fdab8573 /includes/parser | |
parent | 349f5b41c409fecb3b41d2d769754f3d3e16b3aa (diff) | |
download | mediawikicore-6965cdc86f576bdd1f02dc6aae79abf8e797b8ee.tar.gz mediawikicore-6965cdc86f576bdd1f02dc6aae79abf8e797b8ee.zip |
parser: Skip most of Parser::finalizeHeadings when no header found
When the regex does not find <h1-6> tags, most of the function does not
need to initialize variables for the empty loop run.
In this case the NO_TOC output flag is no longer set.
This should improve message parsing as the short text snippet from
messages often does not provide headers
Bug: T378764
Change-Id: Ib22c40f10494f7fbe5cb27602a17a365642607e8
Diffstat (limited to 'includes/parser')
-rw-r--r-- | includes/parser/Parser.php | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 75110882d6f1..d8f265737c5e 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4317,6 +4317,10 @@ class Parser { $enoughToc = true; } + if ( !$numMatches ) { + return $text; + } + # headline counter $headlineCount = 0; $haveTocEntries = false; @@ -4337,11 +4341,9 @@ class Parser { $cpOffset = 0; $refers = []; - $headlines = $numMatches !== false ? $matches[3] : []; - $maxTocLevel = $this->svcOptions->get( MainConfigNames::MaxTocLevel ); $domDocument = DOMUtils::parseHTML( '' ); - foreach ( $headlines as $headline ) { + foreach ( $matches[3] as $headline ) { // $headline is half-parsed HTML $isTemplate = false; $titleText = false; |