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
|
* @suppress SecurityCheck-DoubleEscaped
|
||||||
* @param Parser $parser
|
* @param Parser $parser
|
||||||
* @param string $group
|
* @param string $group
|
||||||
* @param array $ref Dictionary with ReferenceStack ref format
|
* @param ReferenceStackItem $ref
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function linkRef( Parser $parser, string $group, array $ref ): string {
|
public function linkRef( Parser $parser, string $group, ReferenceStackItem $ref ): string {
|
||||||
$label = $this->getLinkLabel( $parser, $group, $ref['number'] );
|
$label = $this->getLinkLabel( $parser, $group, $ref->number );
|
||||||
if ( $label === null ) {
|
if ( $label === null ) {
|
||||||
$label = $this->messageLocalizer->localizeDigits( $ref['number'] );
|
$label = $this->messageLocalizer->localizeDigits( (string)$ref->number );
|
||||||
if ( $group !== Cite::DEFAULT_GROUP ) {
|
if ( $group !== Cite::DEFAULT_GROUP ) {
|
||||||
$label = "$group $label";
|
$label = "$group $label";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( isset( $ref['extendsIndex'] ) ) {
|
if ( isset( $ref->extendsIndex ) ) {
|
||||||
$label .= '.' . $this->messageLocalizer->localizeDigits( $ref['extendsIndex'] );
|
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = $ref['name'] ?? $ref['key'];
|
$key = $ref->name ?? $ref->key;
|
||||||
// TODO: Use count without decrementing.
|
// TODO: Use count without decrementing.
|
||||||
$count = $ref['name'] ? $ref['key'] . '-' . ( $ref['count'] - 1 ) : null;
|
$count = $ref->name ? $ref->key . '-' . ( $ref->count - 1 ) : null;
|
||||||
$subkey = $ref['name'] ? '-' . $ref['key'] : null;
|
$subkey = $ref->name ? '-' . $ref->key : null;
|
||||||
|
|
||||||
return $parser->recursiveTagParse(
|
return $parser->recursiveTagParse(
|
||||||
$this->messageLocalizer->msg(
|
$this->messageLocalizer->msg(
|
||||||
|
|
|
@ -68,7 +68,7 @@ class ReferenceStack {
|
||||||
* @param ?string $follow Guaranteed to not be a numeric string
|
* @param ?string $follow Guaranteed to not be a numeric string
|
||||||
* @param ?string $dir ref direction
|
* @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(
|
public function pushRef(
|
||||||
StripState $stripState,
|
StripState $stripState,
|
||||||
|
@ -79,7 +79,7 @@ class ReferenceStack {
|
||||||
?string $extends,
|
?string $extends,
|
||||||
?string $follow,
|
?string $follow,
|
||||||
?string $dir
|
?string $dir
|
||||||
): ?array {
|
): ?ReferenceStackItem {
|
||||||
$this->refs[$group] ??= [];
|
$this->refs[$group] ??= [];
|
||||||
$this->groupRefSequence[$group] ??= 0;
|
$this->groupRefSequence[$group] ??= 0;
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ class ReferenceStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->refCallStack[] = [ $action, $ref->key, $group, $name, $extends, $text, $argv ];
|
$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\ErrorReporter;
|
||||||
use Cite\FootnoteMarkFormatter;
|
use Cite\FootnoteMarkFormatter;
|
||||||
use Cite\ReferenceMessageLocalizer;
|
use Cite\ReferenceMessageLocalizer;
|
||||||
|
use Cite\Tests\TestUtils;
|
||||||
use Message;
|
use Message;
|
||||||
use Parser;
|
use Parser;
|
||||||
use Wikimedia\TestingAccessWrapper;
|
use Wikimedia\TestingAccessWrapper;
|
||||||
|
@ -52,6 +53,7 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
||||||
$messageLocalizer
|
$messageLocalizer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$ref = TestUtils::refFromArray( $ref );
|
||||||
$output = $formatter->linkRef( $mockParser, $group, $ref );
|
$output = $formatter->linkRef( $mockParser, $group, $ref );
|
||||||
$this->assertSame( $expectedOutput, $output );
|
$this->assertSame( $expectedOutput, $output );
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
|
|
||||||
$this->assertArrayHasKey( $i, $expectedOutputs,
|
$this->assertArrayHasKey( $i, $expectedOutputs,
|
||||||
'Bad test, not enough expected outputs in fixture.' );
|
'Bad test, not enough expected outputs in fixture.' );
|
||||||
$expectedOutput = $expectedOutputs[$i]
|
$expectedRef = TestUtils::refFromArray( $expectedOutputs[$i] );
|
||||||
? (array)TestUtils::refFromArray( $expectedOutputs[$i] )
|
$this->assertEquals( $expectedRef, $result );
|
||||||
: null;
|
|
||||||
$this->assertEquals( $expectedOutput, $result );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$finalRefs = TestUtils::refGroupsFromArray( $finalRefs );
|
$finalRefs = TestUtils::refGroupsFromArray( $finalRefs );
|
||||||
|
|
Loading…
Reference in a new issue