// Set up the session
$ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
+/**
+ * @var MediaWiki\\Session\\SessionId|null $wgInitialSessionId The persistent
+ * session ID (if any) loaded at startup
+ */
+$wgInitialSessionId = null;
if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
// If session.auto_start is there, we can't touch session name
if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
throw $ex;
}
+ if ( $session->isPersistent() ) {
+ $wgInitialSessionId = $session->getSessionId();
+ }
+
$session->renew();
if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
( $session->isPersistent() || $session->shouldRememberUser() )
* @since 1.27
*/
interface SessionManagerInterface extends LoggerAwareInterface {
- /**
- * Fetch the persisted session ID in a request.
- *
- * Note this is not the same thing as whether the session associated with
- * the request is currently persistent, as the session might have been
- * first made persistent during this request.
- *
- * @param WebRequest $request
- * @return string|null
- * @throws \\OverflowException if there are multiple sessions tied for top
- * priority in the request. Exception has a property "sessionInfos"
- * holding the SessionInfo objects for the sessions involved.
- */
- public function getPersistedSessionId( WebRequest $request );
-
/**
* Fetch the session for a request
*
$session = $manager->getSessionForRequest( $request );
$this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
$this->assertSame( $idEmpty, $session->getId() );
- $this->assertNull( $manager->getPersistedSessionId( $request ) );
// Both providers return info, picks best one
$request->info1 = new SessionInfo( SessionInfo::MIN_PRIORITY + 1, array(
$session = $manager->getSessionForRequest( $request );
$this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
$this->assertSame( $id2, $session->getId() );
- $this->assertSame( $id2, $manager->getPersistedSessionId( $request ) );
$request->info1 = new SessionInfo( SessionInfo::MIN_PRIORITY + 2, array(
'provider' => $provider1,
$session = $manager->getSessionForRequest( $request );
$this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
$this->assertSame( $id1, $session->getId() );
- $this->assertSame( $id1, $manager->getPersistedSessionId( $request ) );
// Tied priorities
$request->info1 = new SessionInfo( SessionInfo::MAX_PRIORITY, array(
$this->assertContains( $request->info1, $ex->sessionInfos );
$this->assertContains( $request->info2, $ex->sessionInfos );
}
- try {
- $manager->getPersistedSessionId( $request );
- $this->fail( 'Expcected exception not thrown' );
- } catch ( \OverFlowException $ex ) {
- $this->assertStringStartsWith(
- 'Multiple sessions for this request tied for top priority: ',
- $ex->getMessage()
- );
- $this->assertCount( 2, $ex->sessionInfos );
- $this->assertContains( $request->info1, $ex->sessionInfos );
- $this->assertContains( $request->info2, $ex->sessionInfos );
- }
// Bad provider
$request->info1 = new SessionInfo( SessionInfo::MAX_PRIORITY, array(
$ex->getMessage()
);
}
- try {
- $manager->getPersistedSessionId( $request );
- $this->fail( 'Expcected exception not thrown' );
- } catch ( \UnexpectedValueException $ex ) {
- $this->assertSame(
- 'Provider1 returned session info for a different provider: ' . $request->info1,
- $ex->getMessage()
- );
- }
// Unusable session info
$this->logger->setCollect( true );
$session = $manager->getSessionForRequest( $request );
$this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
$this->assertSame( $id2, $session->getId() );
- $this->assertSame( $id2, $manager->getPersistedSessionId( $request ) );
$this->logger->setCollect( false );
// Unpersisted session ID
$this->assertSame( $id1, $session->getId() );
$session->persist();
$this->assertTrue( $session->isPersistent(), 'sanity check' );
- $this->assertNull( $manager->getPersistedSessionId( $request ) );
}
public function testGetSessionById() {