Deal with <references/> inside a <ref> in automatic references list

The Cite extension already had a recursion guard around the parsing of
`<references/>`, to prevent another `<ref>` containing `<references/>`
from producing a weirdly nested references list.

When an explicit `<references/>` tag is not included in the page, or
`<ref>` tags exist after the last explicit `<references/>`, the extension
automatically adds a reference list at the end of the page, to make the
references still displayed.

This automatic references list creation was bypassing the recursion
guard, causing the weirdly nested output *and* a PHP Notice from
`mRefs[$group]` becoming undefined. This commit sets the recursion guard
state during that automatic references list creation to prevent this.

Bug: T182929
Change-Id: I87737dcf39a4fc15e119a1090a9c34d6b9633c21
This commit is contained in:
Timo Tijhof 2018-07-25 00:08:25 +01:00 committed by Krinkle
parent 580a008af7
commit e86ffeba3a

View file

@ -659,11 +659,12 @@ class Cite {
} }
/** /**
* Must only be called from references(). Use that to prevent recursion.
*
* @param string|null $str Raw content of the <references> tag. * @param string|null $str Raw content of the <references> tag.
* @param string[] $argv * @param string[] $argv
* @param Parser $parser * @param Parser $parser
* @param string $group * @param string $group
*
* @return string * @return string
*/ */
private function guardedReferences( private function guardedReferences(
@ -751,7 +752,10 @@ class Cite {
} }
/** /**
* Make output to be returned from the references() function * Make output to be returned from the references() function.
*
* If called outside of references(), caller is responsible for ensuring
* `mInReferences` is enabled before the call and disabled after call.
* *
* @param string $group * @param string $group
* @param bool $responsive * @param bool $responsive
@ -1222,7 +1226,9 @@ class Cite {
continue; continue;
} }
if ( $group === self::DEFAULT_GROUP || $isSectionPreview ) { if ( $group === self::DEFAULT_GROUP || $isSectionPreview ) {
$this->mInReferences = true;
$s .= $this->referencesFormat( $group, $wgCiteResponsiveReferences ); $s .= $this->referencesFormat( $group, $wgCiteResponsiveReferences );
$this->mInReferences = false;
} else { } else {
$s .= "\n<br />" . $s .= "\n<br />" .
$this->error( $this->error(