diff --git a/src/ReferenceStack.php b/src/ReferenceStack.php index ba89101b1..0d107b42d 100644 --- a/src/ReferenceStack.php +++ b/src/ReferenceStack.php @@ -105,7 +105,7 @@ class ReferenceStack { * @param ?string $follow Guaranteed to not be a numeric string * @param ?string $dir ref direction * - * @return ?array ref structure, or null if nothing was pushed + * @return ?array ref structure, or null if no footnote marker should be rendered * @suppress PhanTypePossiblyInvalidDimOffset To many complaints about array indizes */ public function pushRef( @@ -125,7 +125,7 @@ class ReferenceStack { } if ( $follow && isset( $this->refs[$group][$follow] ) && $text !== null ) { - // We know the parent note already, so just perform the "follow" and bail out + // We know the parent already, so just perform the follow="…" and bail out $this->appendText( $group, $follow, ' ' . $text ); return null; } @@ -140,20 +140,12 @@ class ReferenceStack { ]; if ( $follow ) { - $ref['follow'] = $follow; - // This inserts the incomplete "follow" at the end of all other incomplete "follow" - $k = 0; - foreach ( $this->refs[$group] as $value ) { - if ( !isset( $value['follow'] ) ) { - break; - } - $k++; - } - array_splice( $this->refs[$group], $k, 0, [ $ref ] ); - array_splice( $this->refCallStack, $k, 0, - [ [ 'new', $this->refSequence, $group, $name, $extends, $text, $argv ] ] ); - - // A "follow" never gets its own footnote marker + // Mark an incomplete follow="…" as such. This is valid e.g. in the Page:… namespace + // on Wikisource. + $this->refs[$group][] = $ref + [ 'follow' => $follow ]; + $this->refCallStack[] = [ 'new', $this->refSequence, $group, $name, $extends, $text, + $argv ]; + // A follow="…" never gets its own footnote marker return null; } diff --git a/tests/phpunit/unit/ReferenceStackTest.php b/tests/phpunit/unit/ReferenceStackTest.php index 7411f3980..7d29c8dd5 100644 --- a/tests/phpunit/unit/ReferenceStackTest.php +++ b/tests/phpunit/unit/ReferenceStackTest.php @@ -263,14 +263,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { ], [ 'foo' => [ - 0 => [ - 'count' => -1, - 'dir' => 'rtl', - 'key' => 2, - 'name' => null, - 'text' => 'text-b', - 'follow' => 'c', - ], 'a' => [ 'count' => 0, 'dir' => 'rtl', @@ -279,6 +271,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { 'text' => 'text-a', 'number' => 1, ], + 0 => [ + 'count' => -1, + 'dir' => 'rtl', + 'key' => 2, + 'name' => null, + 'text' => 'text-b', + 'follow' => 'c', + ], 'c' => [ 'count' => 0, 'dir' => 'rtl', @@ -290,8 +290,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { ] ], [ - [ 'new', 2, 'foo', null, null, 'text-b', [] ], [ 'new', 1, 'foo', 'a', null, 'text-a', [] ], + [ 'new', 2, 'foo', null, null, 'text-b', [] ], [ 'new', 3, 'foo', 'c', null, 'text-c', [] ], ] ], @@ -789,6 +789,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { ], [ 'foo' => [ + 'a' => [ + 'count' => 0, + 'dir' => 'rtl', + 'key' => 1, + 'name' => 'a', + 'text' => 'text-a', + 'number' => 1, + ], 0 => [ 'count' => -1, 'dir' => 'rtl', @@ -805,20 +813,12 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase { 'text' => 'text-c', 'follow' => 'd', ], - 'a' => [ - 'count' => 0, - 'dir' => 'rtl', - 'key' => 1, - 'name' => 'a', - 'text' => 'text-a', - 'number' => 1, - ], ] ], [ + [ 'new', 1, 'foo', 'a', null, 'text-a', [] ], [ 'new', 2, 'foo', null, null, 'text-b', [] ], [ 'new', 3, 'foo', null, null, 'text-c', [] ], - [ 'new', 1, 'foo', 'a', null, 'text-a', [] ], ] ], ]; diff --git a/tests/phpunit/unit/ReferencesFormatterTest.php b/tests/phpunit/unit/ReferencesFormatterTest.php index 6379f004f..a03ca0b7f 100644 --- a/tests/phpunit/unit/ReferencesFormatterTest.php +++ b/tests/phpunit/unit/ReferencesFormatterTest.php @@ -246,7 +246,7 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase { [ 'text' => 't', ], - '(cite_references_link_many|||t' . "\n" . '|)' + '(cite_references_link_many|||t' . "\n|)" ], 'With dir' => [ 1,