From e86ffeba3ad1e111ce5a7e082244cd2dd1602aa8 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 25 Jul 2018 00:08:25 +0100 Subject: [PATCH] Deal with inside a in automatic references list The Cite extension already had a recursion guard around the parsing of ``, to prevent another `` containing `` from producing a weirdly nested references list. When an explicit `` tag is not included in the page, or `` tags exist after the last explicit ``, 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 --- includes/Cite.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/Cite.php b/includes/Cite.php index 7899060b1..b3ec861b5 100644 --- a/includes/Cite.php +++ b/includes/Cite.php @@ -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 tag. * @param string[] $argv * @param Parser $parser * @param string $group - * * @return string */ 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 bool $responsive @@ -1222,7 +1226,9 @@ class Cite { continue; } if ( $group === self::DEFAULT_GROUP || $isSectionPreview ) { + $this->mInReferences = true; $s .= $this->referencesFormat( $group, $wgCiteResponsiveReferences ); + $this->mInReferences = false; } else { $s .= "\n
" . $this->error(