Move a bit of code out of Cite::guardedReferences

The main benefit is that the two lines that set and reset
$this->inReferencesGroup are now next to each other. More can be
done in later patches.

Bug: T353266
Change-Id: Ib3f40c40e0b1854f8e5a32af600f28931fffdb8c
This commit is contained in:
thiemowmde 2023-12-12 12:03:45 +01:00 committed by Thiemo Kreuz (WMDE)
parent dda42b9aed
commit 9425bb3248
3 changed files with 8 additions and 9 deletions

View file

@ -392,7 +392,9 @@ class Cite {
return null;
}
$ret = $this->guardedReferences( $parser, $text, $argv );
$status = $this->parseArguments( $argv, [ 'group', 'responsive' ] );
$this->inReferencesGroup = $status->getValue()['group'] ?? self::DEFAULT_GROUP;
$ret = $this->guardedReferences( $parser, $text, $status );
$this->inReferencesGroup = null;
return $ret;
@ -403,18 +405,16 @@ class Cite {
*
* @param Parser $parser
* @param ?string $text Raw, untrimmed wikitext content of the <references> tag, if any
* @param string[] $argv Arguments as given in <references >, already trimmed
* @param StatusValue $status with the arguments as given in <references >
*
* @return string HTML
*/
private function guardedReferences(
Parser $parser,
?string $text,
array $argv
StatusValue $status
): string {
$status = $this->parseArguments( $argv, [ 'group', 'responsive' ] );
[ 'group' => $group, 'responsive' => $responsive ] = $status->getValue();
$this->inReferencesGroup = $group ?? self::DEFAULT_GROUP;
$responsive = $status->getValue()['responsive'];
if ( $text !== null && trim( $text ) !== '' ) {
if ( preg_match( '{' . preg_quote( Parser::MARKER_PREFIX ) . '-(?i:references)-}', $text ) ) {

View file

@ -257,8 +257,6 @@ class ReferenceStack {
/**
* Partially undoes the effect of calls to stack()
*
* Called by guardedReferences()
*
* The option to define <ref> within <references> makes the
* behavior of <ref> context dependent. This is normally fine
* but certain operations (especially #tag) lead to out-of-order

View file

@ -371,6 +371,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
}
/**
* @covers ::references
* @covers ::guardedReferences
* @dataProvider provideGuardedReferences
*/
@ -408,7 +409,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
->with( $expectedRollbackCount )
->willReturn( [ [ 't', [] ] ] );
$output = $spy->guardedReferences( $parser, $text, $argv );
$output = $cite->references( $parser, $text, $argv );
$this->assertSame( $expectedOutput, $output );
}