diff --git a/src/Parsoid/RefGroupItem.php b/src/Parsoid/RefGroupItem.php index be042be6d..5de601215 100644 --- a/src/Parsoid/RefGroupItem.php +++ b/src/Parsoid/RefGroupItem.php @@ -27,6 +27,7 @@ class RefGroupItem { public string $dir = ''; public string $group = ''; public int $groupIndex = 1; + public ?string $extendsRef = null; public int $index = 0; public string $key; public string $id; diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index 49dae62b0..4fafffc00 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -163,6 +163,7 @@ class References extends ExtensionTagHandler { $refName = $refDmw->attrs->name ?? ''; $followName = $refDmw->attrs->follow ?? ''; $refDir = strtolower( $refDmw->attrs->dir ?? '' ); + $extendsRef = $refDmw->attrs->extends ?? null; // Add ref-index linkback $linkBack = $doc->createElement( 'sup' ); @@ -285,7 +286,7 @@ class References extends ExtensionTagHandler { // Even worse would be if it tried to redefine itself! if ( !$ref ) { - $ref = $refsData->add( $extApi, $groupName, $refName, $refDir ); + $ref = $refsData->add( $extApi, $groupName, $refName, $extendsRef, $refDir ); } // Handle linkbacks diff --git a/src/Parsoid/ReferencesData.php b/src/Parsoid/ReferencesData.php index 60e6483ae..e73e2424a 100644 --- a/src/Parsoid/ReferencesData.php +++ b/src/Parsoid/ReferencesData.php @@ -68,7 +68,7 @@ class ReferencesData { } public function add( - ParsoidExtensionAPI $extApi, string $groupName, string $refName, string $refDir + ParsoidExtensionAPI $extApi, string $groupName, string $refName, ?string $extendsRef, string $refDir ): RefGroupItem { $group = $this->getRefGroup( $groupName, true ); $hasRefName = $refName !== ''; @@ -93,6 +93,9 @@ class ReferencesData { $ref->dir = $refDir; $ref->group = $group->name; $ref->groupIndex = count( $group->refs ) + 1; + if ( $extendsRef ) { + $ref->extendsRef = $extendsRef; + } $ref->index = $n; $ref->key = $refIdBase; $ref->id = $hasRefName ? $refIdBase . '-0' : $refIdBase; diff --git a/tests/phpunit/unit/Parsoid/ReferencesDataTest.php b/tests/phpunit/unit/Parsoid/ReferencesDataTest.php index 7d8388638..7aaa60633 100644 --- a/tests/phpunit/unit/Parsoid/ReferencesDataTest.php +++ b/tests/phpunit/unit/Parsoid/ReferencesDataTest.php @@ -56,6 +56,7 @@ class ReferencesDataTest extends MediaWikiUnitTestCase { $this->createNoOpMock( ParsoidExtensionAPI::class ), Cite::DEFAULT_GROUP, '', + null, '' ); @@ -76,6 +77,7 @@ class ReferencesDataTest extends MediaWikiUnitTestCase { $this->createNoOpMock( ParsoidExtensionAPI::class ), 'note', 'wales', + 'main', 'rtl' ); @@ -85,6 +87,7 @@ class ReferencesDataTest extends MediaWikiUnitTestCase { $expected->key = 'cite_ref-wales_1'; $expected->id = 'cite_ref-wales_1-0'; $expected->name = 'wales'; + $expected->extendsRef = 'main'; $expected->target = 'cite_note-wales-1'; $this->assertEquals( $expected, $ref );