* @return ParserOptions
*/
function getParserOptions() {
- global $wgFullyInitialised, $wgContLang;
+ global $wgUser;
if ( !$this->mParserOptions ) {
- if ( !$wgFullyInitialised ) {
+ if ( !$wgUser->isSafeToLoad() ) {
// $wgUser isn't unstubbable yet, so don't try to get a
// ParserOptions for it. And don't cache this ParserOptions
// either.
- $po = new ParserOptions( new User, $wgContLang );
+ $po = ParserOptions::newFromAnon();
$po->setEditSection( false );
return $po;
}
$this->initialiseFromUser( $user, $lang );
}
+ /**
+ * Get a ParserOptions object for an anonymous user
+ * @return ParserOptions
+ */
+ public static function newFromAnon() {
+ global $wgContLang;
+ return new ParserOptions( new User, $wgContLang );
+ }
+
/**
* Get a ParserOptions object from a given user.
* Language will be taken from $wgLang.
return $this->getName();
}
+ /**
+ * Test if it's safe to load this User object
+ * @return bool
+ */
+ public function isSafeToLoad() {
+ global $wgFullyInitialised;
+ return $wgFullyInitialised || $this->mLoadedItems === true || $this->mFrom !== 'session';
+ }
+
/**
* Load the user table data for this object from the source given by mFrom.
*
$this->queryFlagsUsed = $flags;
// If this is called too early, things are likely to break.
- if ( $this->mFrom === 'session' && empty( $wgFullyInitialised ) ) {
+ if ( !$wgFullyInitialised && $this->mFrom === 'session' ) {
\MediaWiki\Logger\LoggerFactory::getInstance( 'session' )
->warning( 'User::loadFromSession called before the end of Setup.php', array(
'exception' => new Exception( 'User::loadFromSession called before the end of Setup.php' ),