From e4e6b593064c1da0e79a1c57aced612be5e91596 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Thu, 31 Oct 2024 13:12:32 +0100 Subject: [PATCH] No-op wiring to get ref "extends" into Parsoid This doesn't change behavior yet, it's pure wiring to make the attribute available to Parsoid logic. Bug: T378567 Change-Id: I6182b601f6fee66a9c32d5006d0a36150eb47e7f --- src/Parsoid/RefGroupItem.php | 1 + src/Parsoid/References.php | 3 ++- src/Parsoid/ReferencesData.php | 5 ++++- tests/phpunit/unit/Parsoid/ReferencesDataTest.php | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) 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 );