From 76e6e870d49ea5edcc1032b462f84c56c4a28342 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Thu, 21 Dec 2023 22:43:12 +0100 Subject: [PATCH] Include more information in missing parent placeholder This allows the subreferences to be collected together under a heading. Bug: T353451 Change-Id: Ibf28f0baca14de8140c87b03ad4aa86d2f81a20d --- src/ReferenceStack.php | 6 +++++- tests/parser/bookReferencing.txt | 6 +++--- tests/phpunit/unit/ReferenceStackTest.php | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ReferenceStack.php b/src/ReferenceStack.php index 1b831ee3f..9786c05c4 100644 --- a/src/ReferenceStack.php +++ b/src/ReferenceStack.php @@ -69,7 +69,7 @@ class ReferenceStack { private const ACTION_INCREMENT = 'increment'; private const ACTION_NEW_FROM_PLACEHOLDER = 'new-from-placeholder'; private const ACTION_NEW = 'new'; - private const PARENT_REF_PLACEHOLDER = '__placeholder__'; + public const PARENT_REF_PLACEHOLDER = '__placeholder__'; /** * Leave a mark in the stack which matches an invalid ref tag. @@ -194,6 +194,7 @@ class ReferenceStack { } else { // Transfer my number to parent ref. $this->refs[$group][$extends] = [ + 'name' => $extends, 'number' => $ref['number'], self::PARENT_REF_PLACEHOLDER => true, ]; @@ -380,6 +381,9 @@ class ReferenceStack { } public function listDefinedRef( string $group, string $name, string $text ): void { + if ( isset( $this->refs[$group][$name][self::PARENT_REF_PLACEHOLDER] ) ) { + unset( $this->refs[$group][$name][self::PARENT_REF_PLACEHOLDER] ); + } if ( !isset( $this->refs[$group][$name]['text'] ) ) { $this->refs[$group][$name]['text'] = $text; } elseif ( $this->refs[$group][$name]['text'] !== $text ) { diff --git a/tests/parser/bookReferencing.txt b/tests/parser/bookReferencing.txt index 110b74f37..1be8d1bc6 100644 --- a/tests/parser/bookReferencing.txt +++ b/tests/parser/bookReferencing.txt @@ -373,7 +373,7 @@ wgCiteBookReferencing=true !! end !! test -T236256 - Base and book reference in different groups +T236256 - Base and book reference in different groups don't collide !! config wgCiteBookReferencing=true !! wikitext @@ -397,7 +397,7 @@ wgCiteBookReferencing=true !! end !! test -T236256 - Extending in the unnamed default group +T236256 - Extending in the unnamed default group doesn't collide with refs from other groups !! config wgCiteBookReferencing=true !! wikitext @@ -420,7 +420,7 @@ wgCiteBookReferencing=true !! end !! test -T236256 - Base in the unnamed default group +T236256 - Extends in named group doesn't conflict with default group !! config wgCiteBookReferencing=true !! wikitext diff --git a/tests/phpunit/unit/ReferenceStackTest.php b/tests/phpunit/unit/ReferenceStackTest.php index 6f81b5d84..fd3342598 100644 --- a/tests/phpunit/unit/ReferenceStackTest.php +++ b/tests/phpunit/unit/ReferenceStackTest.php @@ -436,6 +436,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { 'extendsIndex' => 1, ], 'b' => [ + 'name' => 'b', 'number' => 1, '__placeholder__' => true, ] @@ -578,6 +579,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { 'extendsIndex' => 1, ], 'b' => [ + 'name' => 'b', 'number' => 1, '__placeholder__' => true, ]