Don't try to auto-create users when MW_NO_SESSION is defined
authorBrad Jorsch <bjorsch@wikimedia.org>
Sun, 7 Feb 2016 22:46:34 +0000 (17:46 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Sun, 7 Feb 2016 22:46:34 +0000 (17:46 -0500)
Bug: T126177
Change-Id: Ia62ec77cd2cc177d81923a96171498dbc8c0ed50

includes/Setup.php

index ba3d628..b9a1c37 100644 (file)
@@ -796,13 +796,15 @@ foreach ( $wgExtensionFunctions as $func ) {
 
 // If the session user has a 0 id but a valid name, that means we need to
 // autocreate it.
-$sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
-if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
-       $ps_autocreate = Profiler::instance()->scopedProfileIn( $fname . '-autocreate' );
-       MediaWiki\Session\SessionManager::autoCreateUser( $sessionUser );
-       Profiler::instance()->scopedProfileOut( $ps_autocreate );
+if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
+       $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
+       if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
+               $ps_autocreate = Profiler::instance()->scopedProfileIn( $fname . '-autocreate' );
+               MediaWiki\Session\SessionManager::autoCreateUser( $sessionUser );
+               Profiler::instance()->scopedProfileOut( $ps_autocreate );
+       }
+       unset( $sessionUser );
 }
-unset( $sessionUser );
 
 wfDebug( "Fully initialised\n" );
 $wgFullyInitialised = true;