Wire extends into ReferenceStack

Takes no action, just shuttle the value between functions.

(Split from I9427e025ea0)

Change-Id: I271043e9161835f3278098787bf58b50ed93c892
This commit is contained in:
Adam Wight 2019-11-28 00:27:11 +01:00
parent dbf4c56896
commit ab78df8d5c
3 changed files with 42 additions and 39 deletions

View file

@ -383,7 +383,7 @@ class Cite {
# if there's any content, regardless of name.
$result = $this->referenceStack->pushRef(
$text, $name, $group, $follow, $argv, $dir, $parser->getStripState() );
$text, $name, $group, $extends, $follow, $argv, $dir, $parser->getStripState() );
if ( $result === null ) {
return '';
} else {

View file

@ -99,6 +99,7 @@ class ReferenceStack {
* @param ?string $text Content from the <ref> tag
* @param ?string $name
* @param string $group
* @param ?string $extends
* @param ?string $follow Guaranteed to not be a numeric string
* @param string[] $argv
* @param ?string $dir ref direction
@ -110,6 +111,7 @@ class ReferenceStack {
?string $text,
?string $name,
string $group,
?string $extends,
?string $follow,
array $argv,
?string $dir,
@ -149,7 +151,7 @@ class ReferenceStack {
}
array_splice( $this->refs[$group], $k, 0, [ $ref ] );
array_splice( $this->refCallStack, $k, 0,
[ [ 'new', $argv, $text, $name, $group, $this->refSequence ] ] );
[ [ 'new', $argv, $text, $name, $extends, $group, $this->refSequence ] ] );
// A "follow" never gets its own footnote marker
return null;
@ -193,7 +195,7 @@ class ReferenceStack {
// move this logic to validateRef.
$this->refSequence--;
}
$this->refCallStack[] = [ $action, $argv, $text, $name, $group, $ref['key'] ];
$this->refCallStack[] = [ $action, $argv, $text, $name, $extends, $group, $ref['key'] ];
return [
$name ?? $ref['key'],
$name ? $ref['key'] . '-' . $ref['count'] : null,
@ -218,8 +220,8 @@ class ReferenceStack {
$call = array_pop( $this->refCallStack );
if ( $call !== false ) {
[ $action, $argv, $text, $name, $group, $index ] = $call;
$this->rollbackRef( $action, $name, $group, $index );
[ $action, $argv, $text, $name, $extends, $group, $index ] = $call;
$this->rollbackRef( $action, $name, $extends, $group, $index );
$redoStack[] = [ $argv, $text ];
}
}
@ -247,10 +249,11 @@ class ReferenceStack {
*
* @param string $type
* @param string|null $name The name attribute passed in the ref tag.
* @param string|null $extends
* @param string $group
* @param int $index Autoincrement counter for this ref.
*/
private function rollbackRef( $type, $name, $group, $index ) {
private function rollbackRef( $type, $name, $extends, $group, $index ) {
if ( !$this->hasGroup( $group ) ) {
return;
}

View file

@ -42,9 +42,9 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
$stack = $this->newStack();
for ( $i = 0; $i < count( $refs ); $i++ ) {
[ $text, $name, $group, $follow, $argv, $dir ] = $refs[$i];
[ $text, $name, $group, $extends, $follow, $argv, $dir ] = $refs[$i];
$result = $stack->pushRef(
$text, $name, $group, $follow, $argv, $dir, $mockStripState );
$text, $name, $group, $extends, $follow, $argv, $dir, $mockStripState );
$this->assertSame( $expectedOutputs[$i], $result );
}
@ -57,7 +57,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
return [
'Anonymous ref in default group' => [
[
[ null, null, '', null, [], 'rtl' ]
[ null, null, '', null, null, [], 'rtl' ]
],
[
[ 1, null, 1, null ]
@ -73,12 +73,12 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], null, null, '', 1 ]
[ 'new', [], null, null, null, '', 1 ]
]
],
'Anonymous ref in named group' => [
[
[ null, null, 'foo', null, [], 'rtl' ]
[ null, null, 'foo', null, null, [], 'rtl' ]
],
[
[ 1, null, 1, null ]
@ -94,12 +94,12 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], null, null, 'foo', 1 ]
[ 'new', [], null, null, null, 'foo', 1 ]
]
],
'Ref with text' => [
[
[ 'text', null, 'foo', null, [], 'rtl' ]
[ 'text', null, 'foo', null, null, [], 'rtl' ]
],
[
[ 1, null, 1, null ]
@ -115,12 +115,12 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', null, 'foo', 1 ]
[ 'new', [], 'text', null, null, 'foo', 1 ]
]
],
'Named ref with text' => [
[
[ 'text', 'name', 'foo', null, [], 'rtl' ]
[ 'text', 'name', 'foo', null, null, [], 'rtl' ]
],
[
[ 'name', '1-0', 1, '-1' ]
@ -137,13 +137,13 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', 'name', 'foo', 1 ]
[ 'new', [], 'text', 'name', null, 'foo', 1 ]
]
],
'Follow after base' => [
[
[ 'text-a', 'a', 'foo', null, [], 'rtl' ],
[ 'text-b', 'b', 'foo', 'a', [], 'rtl' ]
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
[ 'text-b', 'b', 'foo', null, 'a', [], 'rtl' ]
],
[
[ 'a', '1-0', 1, '-1' ],
@ -161,12 +161,12 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', 'foo', 1 ]
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ]
]
],
'Follow with no base' => [
[
[ 'text', null, 'foo', 'a', [], 'rtl' ]
[ 'text', null, 'foo', null, 'a', [], 'rtl' ]
],
[
null
@ -183,14 +183,14 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', null, 'foo', 1 ]
[ 'new', [], 'text', null, null, 'foo', 1 ]
]
],
'Follow pointing to later ref' => [
[
[ 'text-a', 'a', 'foo', null, [], 'rtl' ],
[ 'text-b', null, 'foo', 'c', [], 'rtl' ],
[ 'text-c', 'c', 'foo', null, [], 'rtl' ]
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
[ 'text-b', null, 'foo', null, 'c', [], 'rtl' ],
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ]
],
[
[ 'a', '1-0', 1, '-1' ],
@ -223,15 +223,15 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-b', null, 'foo', 2 ],
[ 'new', [], 'text-a', 'a', 'foo', 1 ],
[ 'new', [], 'text-c', 'c', 'foo', 3 ]
[ 'new', [], 'text-b', null, null, 'foo', 2 ],
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
[ 'new', [], 'text-c', 'c', null, 'foo', 3 ]
]
],
'Repeated ref, text in first tag' => [
[
[ 'text', 'a', 'foo', null, [], 'rtl' ],
[ null, 'a', 'foo', null, [], 'rtl' ]
[ 'text', 'a', 'foo', null, null, [], 'rtl' ],
[ null, 'a', 'foo', null, null, [], 'rtl' ]
],
[
[ 'a', '1-0', 1, '-1' ],
@ -249,14 +249,14 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', 'a', 'foo', 1 ],
[ 'increment', [], null, 'a', 'foo', 1 ]
[ 'new', [], 'text', 'a', null, 'foo', 1 ],
[ 'increment', [], null, 'a', null, 'foo', 1 ]
]
],
'Repeated ref, text in second tag' => [
[
[ null, 'a', 'foo', null, [], 'rtl' ],
[ 'text', 'a', 'foo', null, [], 'rtl' ]
[ null, 'a', 'foo', null, null, [], 'rtl' ],
[ 'text', 'a', 'foo', null, null, [], 'rtl' ]
],
[
[ 'a', '1-0', 1, '-1' ],
@ -274,14 +274,14 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], null, 'a', 'foo', 1 ],
[ 'assign', [], 'text', 'a', 'foo', 1 ]
[ 'new', [], null, 'a', null, 'foo', 1 ],
[ 'assign', [], 'text', 'a', null, 'foo', 1 ]
]
],
'Repeated ref, mismatched text' => [
[
[ 'text-1', 'a', 'foo', null, [], 'rtl' ],
[ 'text-2', 'a', 'foo', null, [], 'rtl' ]
[ 'text-1', 'a', 'foo', null, null, [], 'rtl' ],
[ 'text-2', 'a', 'foo', null, null, [], 'rtl' ]
],
[
[ 'a', '1-0', 1, '-1' ],
@ -299,8 +299,8 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-1', 'a', 'foo', 1 ],
[ 'increment', [], 'text-2', 'a', 'foo', 1 ]
[ 'new', [], 'text-1', 'a', null, 'foo', 1 ],
[ 'increment', [], 'text-2', 'a', null, 'foo', 1 ]
]
],
];