Merge "Change order of elements in the refs call stack"

This commit is contained in:
jenkins-bot 2019-12-19 10:30:35 +00:00 committed by Gerrit Code Review
commit 347ad9fb5f
2 changed files with 49 additions and 50 deletions

View file

@ -165,7 +165,7 @@ class ReferenceStack {
// array index is constant, preventing O(N) searches.
array_splice( $this->refs[$group], $k, 0, [ $ref ] );
array_splice( $this->refCallStack, $k, 0,
[ [ 'new', $argv, $text, $name, $extends, $group, $this->refSequence ] ] );
[ [ 'new', $this->refSequence, $group, $name, $extends, $argv, $text ] ] );
// A "follow" never gets its own footnote marker
return null;
@ -238,7 +238,7 @@ class ReferenceStack {
}
}
$this->refCallStack[] = [ $action, $argv, $text, $name, $extends, $group, $ref['key'] ];
$this->refCallStack[] = [ $action, $ref['key'], $group, $name, $extends, $argv, $text ];
return $ref;
}
@ -247,7 +247,7 @@ class ReferenceStack {
* last few tags were actually inside of a references tag.
*
* @param int $count
* @return array Refs to restore under the correct context. [ $argv, $text ]
* @return array[] Refs to restore under the correct context, as a list of [ $argv, $text ]
*/
public function rollbackRefs( int $count ) : array {
$redoStack = [];
@ -257,10 +257,9 @@ class ReferenceStack {
}
$call = array_pop( $this->refCallStack );
if ( $call !== false ) {
[ $action, $argv, $text, $name, $extends, $group, $key ] = $call;
$this->rollbackRef( $action, $name, $extends, $group, $key );
$redoStack[] = [ $argv, $text ];
if ( $call ) {
$this->rollbackRef( ...$call );
$redoStack[] = array_slice( $call, -2 );
}
}
// Drop unused rollbacks, this group is finished.
@ -286,17 +285,17 @@ class ReferenceStack {
* corrupting certain links.
*
* @param string $action
* @param string|null $name The name attribute passed in the ref tag.
* @param string|null $extends
* @param string $group
* @param int $key Autoincrement counter for this ref.
* @param string $group
* @param ?string $name The name attribute passed in the ref tag.
* @param ?string $extends
*/
private function rollbackRef(
string $action,
?string $name,
?string $extends,
int $key,
string $group,
int $key
?string $name,
?string $extends
) {
if ( !$this->hasGroup( $group ) ) {
return;

View file

@ -86,7 +86,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', null, null, '', 1 ]
[ 'new', 1, '', null, null, [], 'text' ],
]
],
'Anonymous ref in named group' => [
@ -116,7 +116,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', null, null, 'foo', 1 ]
[ 'new', 1, 'foo', null, null, [], 'text' ],
]
],
'Ref with text' => [
@ -146,7 +146,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', null, null, 'foo', 1 ]
[ 'new', 1, 'foo', null, null, [], 'text' ],
]
],
'Named ref with text' => [
@ -176,7 +176,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', 'name', null, 'foo', 1 ]
[ 'new', 1, 'foo', 'name', null, [], 'text' ],
]
],
'Follow after base' => [
@ -208,7 +208,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ]
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
]
],
'Follow with no base' => [
@ -231,7 +231,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', null, null, 'foo', 1 ]
[ 'new', 1, 'foo', null, null, [], 'text' ],
]
],
'Follow pointing to later ref' => [
@ -288,9 +288,9 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-b', null, null, 'foo', 2 ],
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
[ 'new', [], 'text-c', 'c', null, 'foo', 3 ]
[ 'new', 2, 'foo', null, null, [], 'text-b' ],
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
[ 'new', 3, 'foo', 'c', null, [], 'text-c' ],
]
],
'Repeated ref, text in first tag' => [
@ -329,8 +329,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text', 'a', null, 'foo', 1 ],
[ 'increment', [], null, 'a', null, 'foo', 1 ]
[ 'new', 1, 'foo', 'a', null, [], 'text' ],
[ 'increment', 1, 'foo', 'a', null, [], null ],
]
],
'Repeated ref, text in second tag' => [
@ -369,8 +369,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], null, 'a', null, 'foo', 1 ],
[ 'assign', [], 'text', 'a', null, 'foo', 1 ]
[ 'new', 1, 'foo', 'a', null, [], null ],
[ 'assign', 1, 'foo', 'a', null, [], 'text' ],
]
],
'Repeated ref, mismatched text' => [
@ -409,8 +409,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-1', 'a', null, 'foo', 1 ],
[ 'increment', [], 'text-2', 'a', null, 'foo', 1 ]
[ 'new', 1, 'foo', 'a', null, [], 'text-1' ],
[ 'increment', 1, 'foo', 'a', null, [], 'text-2' ],
]
],
'Named extends with no parent' => [
@ -448,7 +448,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', 'b', 'foo', 1 ],
[ 'new', 1, 'foo', 'a', 'b', [], 'text-a' ],
]
],
'Named extends before parent' => [
@ -499,8 +499,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', 'b', 'foo', 1 ],
[ 'new', [], 'text-b', 'b', null, 'foo', 2 ],
[ 'new', 1, 'foo', 'a', 'b', [], 'text-a' ],
[ 'new', 2, 'foo', 'b', null, [], 'text-b' ],
]
],
'Named extends after parent' => [
@ -551,8 +551,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
[ 'new', [], 'text-b', 'b', 'a', 'foo', 2 ],
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
[ 'new', 2, 'foo', 'b', 'a', [], 'text-b' ],
]
],
'Anonymous extends with no parent' => [
@ -590,7 +590,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
],
],
[
[ 'new', [], 'text-a', null, 'b', 'foo', 1 ],
[ 'new', 1, 'foo', null, 'b', [], 'text-a' ],
]
],
'Anonymous extends before parent' => [
@ -641,8 +641,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', null, 'b', 'foo', 1 ],
[ 'new', [], 'text-b', 'b', null, 'foo', 2 ],
[ 'new', 1, 'foo', null, 'b', [], 'text-a' ],
[ 'new', 2, 'foo', 'b', null, [], 'text-b' ],
]
],
'Anonymous extends after parent' => [
@ -693,8 +693,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
[ 'new', [], 'text-b', null, 'a', 'foo', 2 ],
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
[ 'new', 2, 'foo', null, 'a', [], 'text-b' ],
]
],
'Normal after extends' => [
@ -762,9 +762,9 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
[ 'new', [], 'text-b', null, 'a', 'foo', 2 ],
[ 'new', [], 'text-c', 'c', null, 'foo', 3 ],
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
[ 'new', 2, 'foo', null, 'a', [], 'text-b' ],
[ 'new', 3, 'foo', 'c', null, [], 'text-c' ],
]
],
'Two broken follows' => [
@ -814,9 +814,9 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
]
],
[
[ 'new', [], 'text-b', null, null, 'foo', 2 ],
[ 'new', [], 'text-c', null, null, 'foo', 3 ],
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
[ 'new', 2, 'foo', null, null, [], 'text-b' ],
[ 'new', 3, 'foo', null, null, [], 'text-c' ],
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
]
],
];
@ -850,7 +850,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
'Skip invalid refs' => [ [ false ], [], 1, [], [] ],
'Missing group' => [
[
[ 'new', [], 'text', null, null, 'foo', 1 ],
[ 'new', 1, 'foo', null, null, [], 'text' ],
],
[],
1,
@ -861,7 +861,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
],
'Find anonymous ref by key' => [
[
[ 'new', [], 'text', null, null, 'foo', 1 ],
[ 'new', 1, 'foo', null, null, [], 'text' ],
],
[
'foo' => [
@ -878,7 +878,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
],
'Missing anonymous ref' => [
[
[ 'new', [], 'text', null, null, 'foo', 1 ],
[ 'new', 1, 'foo', null, null, [], 'text' ],
],
[
'foo' => [
@ -901,7 +901,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
],
'Assign text' => [
[
[ 'assign', [], 'text-2', null, null, 'foo', 1 ],
[ 'assign', 1, 'foo', null, null, [], 'text-2' ],
],
[
'foo' => [
@ -928,7 +928,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
],
'Increment' => [
[
[ 'increment', [], null, null, null, 'foo', 1 ],
[ 'increment', 1, 'foo', null, null, [], null ],
],
[
'foo' => [
@ -953,7 +953,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
],
'Safely ignore placeholder' => [
[
[ 'increment', [], null, null, null, 'foo', 1 ],
[ 'increment', 1, 'foo', null, null, [], null ],
],
[
'foo' => [