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
This commit is contained in:
Adam Wight 2024-10-31 13:12:32 +01:00
parent 373ed01123
commit e4e6b59306
4 changed files with 10 additions and 2 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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 );