mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-27 16:30:12 +00:00
Encapsulate ref: pushRef returns an object
This patch affects a few methods which use the output of pushRef. Bug: T353451 Change-Id: I10b3fe89406c11cdaede92f18a4b96586ecaf5a0
This commit is contained in:
parent
262fbe24eb
commit
f148c65078
|
@ -36,26 +36,26 @@ class FootnoteMarkFormatter {
|
|||
* @suppress SecurityCheck-DoubleEscaped
|
||||
* @param Parser $parser
|
||||
* @param string $group
|
||||
* @param array $ref Dictionary with ReferenceStack ref format
|
||||
* @param ReferenceStackItem $ref
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function linkRef( Parser $parser, string $group, array $ref ): string {
|
||||
$label = $this->getLinkLabel( $parser, $group, $ref['number'] );
|
||||
public function linkRef( Parser $parser, string $group, ReferenceStackItem $ref ): string {
|
||||
$label = $this->getLinkLabel( $parser, $group, $ref->number );
|
||||
if ( $label === null ) {
|
||||
$label = $this->messageLocalizer->localizeDigits( $ref['number'] );
|
||||
$label = $this->messageLocalizer->localizeDigits( (string)$ref->number );
|
||||
if ( $group !== Cite::DEFAULT_GROUP ) {
|
||||
$label = "$group $label";
|
||||
}
|
||||
}
|
||||
if ( isset( $ref['extendsIndex'] ) ) {
|
||||
$label .= '.' . $this->messageLocalizer->localizeDigits( $ref['extendsIndex'] );
|
||||
if ( isset( $ref->extendsIndex ) ) {
|
||||
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
|
||||
}
|
||||
|
||||
$key = $ref['name'] ?? $ref['key'];
|
||||
$key = $ref->name ?? $ref->key;
|
||||
// TODO: Use count without decrementing.
|
||||
$count = $ref['name'] ? $ref['key'] . '-' . ( $ref['count'] - 1 ) : null;
|
||||
$subkey = $ref['name'] ? '-' . $ref['key'] : null;
|
||||
$count = $ref->name ? $ref->key . '-' . ( $ref->count - 1 ) : null;
|
||||
$subkey = $ref->name ? '-' . $ref->key : null;
|
||||
|
||||
return $parser->recursiveTagParse(
|
||||
$this->messageLocalizer->msg(
|
||||
|
|
|
@ -68,7 +68,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 no footnote marker should be rendered
|
||||
* @return ?ReferenceStackItem ref structure, or null if no footnote marker should be rendered
|
||||
*/
|
||||
public function pushRef(
|
||||
StripState $stripState,
|
||||
|
@ -79,7 +79,7 @@ class ReferenceStack {
|
|||
?string $extends,
|
||||
?string $follow,
|
||||
?string $dir
|
||||
): ?array {
|
||||
): ?ReferenceStackItem {
|
||||
$this->refs[$group] ??= [];
|
||||
$this->groupRefSequence[$group] ??= 0;
|
||||
|
||||
|
@ -183,7 +183,7 @@ class ReferenceStack {
|
|||
}
|
||||
|
||||
$this->refCallStack[] = [ $action, $ref->key, $group, $name, $extends, $text, $argv ];
|
||||
return (array)$ref;
|
||||
return $ref;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ use Cite\AnchorFormatter;
|
|||
use Cite\ErrorReporter;
|
||||
use Cite\FootnoteMarkFormatter;
|
||||
use Cite\ReferenceMessageLocalizer;
|
||||
use Cite\Tests\TestUtils;
|
||||
use Message;
|
||||
use Parser;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
@ -52,6 +53,7 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
$messageLocalizer
|
||||
);
|
||||
|
||||
$ref = TestUtils::refFromArray( $ref );
|
||||
$output = $formatter->linkRef( $mockParser, $group, $ref );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
}
|
||||
|
|
|
@ -43,10 +43,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
|
||||
$this->assertArrayHasKey( $i, $expectedOutputs,
|
||||
'Bad test, not enough expected outputs in fixture.' );
|
||||
$expectedOutput = $expectedOutputs[$i]
|
||||
? (array)TestUtils::refFromArray( $expectedOutputs[$i] )
|
||||
: null;
|
||||
$this->assertEquals( $expectedOutput, $result );
|
||||
$expectedRef = TestUtils::refFromArray( $expectedOutputs[$i] );
|
||||
$this->assertEquals( $expectedRef, $result );
|
||||
}
|
||||
|
||||
$finalRefs = TestUtils::refGroupsFromArray( $finalRefs );
|
||||
|
|
Loading…
Reference in a new issue