From b435e659b5c9e666055e2282159b8606f6331b31 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 3 Feb 2016 15:18:52 -0500 Subject: [PATCH] OutputPage: Don't get a ParserOptions for $wgUser before the end of Setup.php Until Setup.php completes, we can't access the "current" user and trying to do so logs a warning. So don't try. Bug: T124367 Change-Id: I1acc82760c368a24448f3c90e268b24414e43a30 --- includes/OutputPage.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 3adef5b2515..317c1261d68 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1573,11 +1573,42 @@ class OutputPage extends ContextSource { * @return ParserOptions */ public function parserOptions( $options = null ) { + if ( $options !== null && !empty( $options->isBogus ) ) { + // Someone is trying to set a bogus pre-$wgUser PO. Check if it has + // been changed somehow, and keep it if so. + $anonPO = ParserOptions::newFromAnon(); + $anonPO->setEditSection( false ); + if ( !$options->matches( $anonPO ) ) { + wfLogWarning( __METHOD__ . ': Setting a changed bogus ParserOptions: ' . wfGetAllCallers( 5 ) ); + $options->isBogus = false; + } + } + if ( !$this->mParserOptions ) { + if ( !$this->getContext()->getUser()->isSafeToLoad() ) { + // $wgUser isn't unstubbable yet, so don't try to get a + // ParserOptions for it. And don't cache this ParserOptions + // either. + $po = ParserOptions::newFromAnon(); + $po->setEditSection( false ); + $po->isBogus = true; + if ( $options !== null ) { + $this->mParserOptions = empty( $options->isBogus ) ? $options : null; + } + return $po; + } + $this->mParserOptions = ParserOptions::newFromContext( $this->getContext() ); $this->mParserOptions->setEditSection( false ); } - return wfSetVar( $this->mParserOptions, $options ); + + if ( $options !== null && !empty( $options->isBogus ) ) { + // They're trying to restore the bogus pre-$wgUser PO. Do the right + // thing. + return wfSetVar( $this->mParserOptions, null, true ); + } else { + return wfSetVar( $this->mParserOptions, $options ); + } } /** -- 2.11.4.GIT