jenkins-bot has submitted this change and it was merged.
Change subject: Handle raw <h#> when calculating $rawtoc
......................................................................
Handle raw <h#> when calculating $rawtoc
When the parser is constructing $rawtoc, it needs the sectionIndex
number to be able to calculate the byteoffset. This number is only
available for wikitext headings ("== foo =="), HTML headings
("<h2>foo</h2>") do not have it and the lack makes byteoffset be wrong
for all subsequent headings in the page.
To fix this, we just omit output of byteoffset in this situation.
Bug: 25203
Change-Id: I39e5faa4ac22d915f06125aac36ced11607b94a3
---
M includes/parser/Parser.php
M tests/phpunit/includes/parser/ParserMethodsTest.php
2 files changed, 42 insertions(+), 2 deletions(-)
Approvals:
Cscott: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index eac2202..0603a9b 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -4447,7 +4447,8 @@
# Add the section to the section tree
# Find the DOM node for this header
- while ( $node && !$isTemplate ) {
+ $noOffset = ( $isTemplate || $sectionIndex === false );
+ while ( $node && !$noOffset ) {
if ( $node->getName() === 'h' ) {
$bits = $node->splitHeading();
if ( $bits['i'] == $sectionIndex ) {
@@ -4465,7 +4466,7 @@
'number' => $numbering,
'index' => ( $isTemplate ? 'T-' : '' ) .
$sectionIndex,
'fromtitle' => $titleText,
- 'byteoffset' => ( $isTemplate ? null :
$byteOffset ),
+ 'byteoffset' => ( $noOffset ? null :
$byteOffset ),
'anchor' => $anchor,
);
diff --git a/tests/phpunit/includes/parser/ParserMethodsTest.php
b/tests/phpunit/includes/parser/ParserMethodsTest.php
index cacbb85..3cdbf15 100644
--- a/tests/phpunit/includes/parser/ParserMethodsTest.php
+++ b/tests/phpunit/includes/parser/ParserMethodsTest.php
@@ -44,5 +44,44 @@
'text' => '<pre style="margin-left: 1.6em">foo</pre>',
), $ret, 'callParserFunction works for
{{#tag:pre|foo|style=margin-left: 1.6em}}' );
}
+
+ public function testGetSections() {
+ global $wgParser;
+
+ $title = Title::newFromText( str_replace( '::', '__',
__METHOD__ ) );
+ $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n",
$title, new ParserOptions() );
+ $this->assertSame( array(
+ array(
+ 'toclevel' => 1,
+ 'level' => '2',
+ 'line' => 'foo',
+ 'number' => '1',
+ 'index' => '1',
+ 'fromtitle' => $title->getPrefixedDBkey(),
+ 'byteoffset' => 0,
+ 'anchor' => 'foo',
+ ),
+ array(
+ 'toclevel' => 1,
+ 'level' => '2',
+ 'line' => 'bar',
+ 'number' => '2',
+ 'index' => '',
+ 'fromtitle' => false,
+ 'byteoffset' => null,
+ 'anchor' => 'bar',
+ ),
+ array(
+ 'toclevel' => 1,
+ 'level' => '2',
+ 'line' => 'baz',
+ 'number' => '3',
+ 'index' => '2',
+ 'fromtitle' => $title->getPrefixedDBkey(),
+ 'byteoffset' => 21,
+ 'anchor' => 'baz',
+ ),
+ ), $out->getSections(), 'getSections() with proper value when
<h2> is used' );
+ }
// TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(),
replaceSection(), getPreloadText()
}
--
To view, visit https://gerrit.wikimedia.org/r/88750
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I39e5faa4ac22d915f06125aac36ced11607b94a3
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits