14 const SESSIONID =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
29 if ( !$this->config ) {
30 $this->config = new \HashConfig();
31 $this->manager = null;
33 if ( !$this->
store ) {
35 $this->manager = null;
38 $logger = new \Psr\Log\NullLogger();
39 if ( !$this->manager ) {
41 'store' => $this->
store,
43 'config' => $this->config,
47 if ( !$this->provider ) {
48 $this->provider = new \DummySessionProvider();
50 $this->provider->setLogger( $logger );
51 $this->provider->setConfig( $this->config );
52 $this->provider->setManager( $this->manager );
55 'provider' => $this->provider,
56 'id' => $id ?: self::SESSIONID,
65 $priv->persist =
false;
66 $priv->requests = [ 100 => new \FauxRequest() ];
67 $priv->requests[100]->setSessionId( $id );
68 $priv->usePhpSessionHandling =
false;
73 $manager->sessionProviders = [ (
string)$this->provider => $this->provider ];
83 'provider' => $this->provider,
84 'id' => self::SESSIONID,
90 $logger = new \Psr\Log\NullLogger();
93 $this->fail(
'Expected exception not thrown' );
96 "Refusing to create session for unverified user {$info->getUserInfo()}",
102 'id' => self::SESSIONID,
109 $this->fail(
'Expected exception not thrown' );
111 $this->assertSame(
'Cannot create session without a provider', $ex->getMessage() );
115 'provider' => $this->provider,
116 'id' => self::SESSIONID,
121 $id =
new SessionId(
'!' . $info->getId() );
124 $this->fail(
'Expected exception not thrown' );
127 'SessionId and SessionInfo don\'t match',
133 'provider' => $this->provider,
134 'id' => self::SESSIONID,
141 $this->assertSame( self::SESSIONID, $backend->
getId() );
142 $this->assertSame( $id, $backend->getSessionId() );
143 $this->assertSame( $this->provider, $backend->getProvider() );
144 $this->assertInstanceOf(
'User', $backend->getUser() );
145 $this->assertSame(
'UTSysop', $backend->getUser()->getName() );
146 $this->assertSame( $info->wasPersisted(), $backend->isPersistent() );
147 $this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() );
148 $this->assertSame( $info->forceHTTPS(), $backend->shouldForceHTTPS() );
150 $expire = time() + 100;
151 $this->
store->setSessionMeta( self::SESSIONID, [
'expires' => $expire ], 2 );
154 'provider' => $this->provider,
155 'id' => self::SESSIONID,
157 'forceHTTPS' =>
true,
158 'metadata' => [
'foo' ],
163 $this->assertSame( self::SESSIONID, $backend->
getId() );
164 $this->assertSame( $id, $backend->getSessionId() );
165 $this->assertSame( $this->provider, $backend->getProvider() );
166 $this->assertInstanceOf(
'User', $backend->getUser() );
167 $this->assertTrue( $backend->getUser()->isAnon() );
168 $this->assertSame( $info->wasPersisted(), $backend->isPersistent() );
169 $this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() );
170 $this->assertSame( $info->forceHTTPS(), $backend->shouldForceHTTPS() );
172 $this->assertSame( [
'foo' ], $backend->getProviderMetadata() );
178 $priv->requests = [];
182 $request1 = new \FauxRequest();
183 $session1 = $backend->getSession( $request1 );
184 $request2 = new \FauxRequest();
185 $session2 = $backend->getSession( $request2 );
189 $this->assertSame( 2, count( $priv->requests ) );
193 $this->assertSame( $request1, $backend->getRequest( $index ) );
194 $this->assertSame( null, $backend->suggestLoginUsername( $index ) );
195 $request1->setCookie(
'UserName',
'Example' );
196 $this->assertSame(
'Example', $backend->suggestLoginUsername( $index ) );
199 $this->assertSame( 1, count( $priv->requests ) );
200 $this->assertArrayHasKey( $backend->getId(),
$manager->allSessionBackends );
201 $this->assertSame( $backend,
$manager->allSessionBackends[$backend->getId()] );
203 $backend->getRequest( $index );
204 $this->fail(
'Expected exception not thrown' );
206 $this->assertSame(
'Invalid session index', $ex->getMessage() );
209 $backend->suggestLoginUsername( $index );
210 $this->fail(
'Expected exception not thrown' );
212 $this->assertSame(
'Invalid session index', $ex->getMessage() );
216 $this->assertSame( 0, count( $priv->requests ) );
217 $this->assertArrayNotHasKey( $backend->getId(),
$manager->allSessionBackends );
218 $this->assertArrayHasKey( $backend->getId(),
$manager->allSessionIds );
224 $priv->providerMetadata = [
'dummy' ];
227 $backend->setProviderMetadata(
'foo' );
228 $this->fail(
'Expected exception not thrown' );
230 $this->assertSame(
'$metadata must be an array or null', $ex->getMessage() );
234 $backend->setProviderMetadata( (
object)[] );
235 $this->fail(
'Expected exception not thrown' );
237 $this->assertSame(
'$metadata must be an array or null', $ex->getMessage() );
240 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'sanity check' );
241 $backend->setProviderMetadata( [
'dummy' ] );
242 $this->assertFalse( $this->
store->getSession( self::SESSIONID ) );
244 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'sanity check' );
245 $backend->setProviderMetadata( [
'test' ] );
246 $this->assertNotFalse( $this->
store->getSession( self::SESSIONID ) );
247 $this->assertSame( [
'test' ], $backend->getProviderMetadata() );
248 $this->
store->deleteSession( self::SESSIONID );
250 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'sanity check' );
251 $backend->setProviderMetadata( null );
252 $this->assertNotFalse( $this->
store->getSession( self::SESSIONID ) );
253 $this->assertSame( null, $backend->getProviderMetadata() );
254 $this->
store->deleteSession( self::SESSIONID );
260 $builder = $this->getMockBuilder(
'DummySessionProvider' )
261 ->setMethods( [
'persistsSessionId',
'sessionIdWasReset' ] );
263 $this->provider = $builder->getMock();
264 $this->provider->expects( $this->any() )->method(
'persistsSessionId' )
265 ->will( $this->returnValue(
false ) );
266 $this->provider->expects( $this->never() )->method(
'sessionIdWasReset' );
269 $sessionId = $backend->getSessionId();
271 $this->assertSame( self::SESSIONID, $backend->getId() );
272 $this->assertSame( $backend->getId(), $sessionId->getId() );
273 $this->assertSame( $id, session_id() );
274 $this->assertSame( $backend,
$manager->allSessionBackends[self::SESSIONID] );
276 $this->provider = $builder->getMock();
277 $this->provider->expects( $this->any() )->method(
'persistsSessionId' )
278 ->will( $this->returnValue(
true ) );
280 $this->provider->expects( $this->once() )->method(
'sessionIdWasReset' )
281 ->with( $this->identicalTo( $backend ), $this->identicalTo( self::SESSIONID ) );
283 $sessionId = $backend->getSessionId();
285 $this->assertNotEquals( self::SESSIONID, $backend->getId() );
286 $this->assertSame( $backend->getId(), $sessionId->getId() );
287 $this->assertInternalType(
'array', $this->
store->getSession( $backend->getId() ) );
288 $this->assertFalse( $this->
store->getSession( self::SESSIONID ) );
289 $this->assertSame( $id, session_id() );
290 $this->assertArrayNotHasKey( self::SESSIONID,
$manager->allSessionBackends );
291 $this->assertArrayHasKey( $backend->getId(),
$manager->allSessionBackends );
292 $this->assertSame( $backend,
$manager->allSessionBackends[$backend->getId()] );
296 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
297 $this->provider->expects( $this->once() )->method(
'persistSession' );
299 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
303 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
305 $this->provider = null;
308 $wrap->persist =
true;
311 $this->assertNotEquals( 0, $wrap->expires );
315 $this->provider = $this->getMock(
'DummySessionProvider', [
'unpersistSession' ] );
316 $this->provider->expects( $this->once() )->method(
'unpersistSession' );
319 $wrap->store = new \CachedBagOStuff( $this->
store );
320 $wrap->persist =
true;
321 $wrap->dataDirty =
true;
324 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
325 $this->assertNotFalse( $this->
store->getSession( self::SESSIONID ),
'sanity check' );
327 $backend->unpersist();
328 $this->assertFalse( $backend->isPersistent() );
329 $this->assertFalse( $this->
store->getSession( self::SESSIONID ) );
330 $this->assertNotFalse( $wrap->store->get(
wfMemcKey(
'MWSession', self::SESSIONID ) ) );
336 $remembered = $backend->shouldRememberUser();
337 $backend->setRememberUser( !$remembered );
338 $this->assertNotEquals( $remembered, $backend->shouldRememberUser() );
339 $backend->setRememberUser( $remembered );
340 $this->assertEquals( $remembered, $backend->shouldRememberUser() );
346 $force = $backend->shouldForceHTTPS();
347 $backend->setForceHTTPS( !$force );
348 $this->assertNotEquals( $force, $backend->shouldForceHTTPS() );
349 $backend->setForceHTTPS( $force );
350 $this->assertEquals( $force, $backend->shouldForceHTTPS() );
356 $backend->setLoggedOutTimestamp( 42 );
357 $this->assertSame( 42, $backend->getLoggedOutTimestamp() );
358 $backend->setLoggedOutTimestamp(
'123' );
359 $this->assertSame( 123, $backend->getLoggedOutTimestamp() );
363 $user = static::getTestSysop()->getUser();
365 $this->provider = $this->getMock(
'DummySessionProvider', [
'canChangeUser' ] );
366 $this->provider->expects( $this->any() )->method(
'canChangeUser' )
367 ->will( $this->returnValue(
false ) );
369 $this->assertFalse( $backend->canSetUser() );
371 $backend->setUser(
$user );
372 $this->fail(
'Expected exception not thrown' );
373 }
catch ( \BadMethodCallException $ex ) {
375 'Cannot set user on this session; check $session->canSetUser() first',
379 $this->assertNotSame(
$user, $backend->getUser() );
381 $this->provider = null;
383 $this->assertTrue( $backend->canSetUser() );
384 $this->assertNotSame(
$user, $backend->getUser(),
'sanity check' );
385 $backend->setUser(
$user );
386 $this->assertSame(
$user, $backend->getUser() );
392 $priv->dataDirty =
false;
394 $this->assertTrue( $priv->dataDirty );
399 $data = $backend->getData();
400 $this->assertSame( [], $data );
402 $data[
'???'] =
'!!!';
403 $this->assertSame( [
'???' =>
'!!!' ], $data );
405 $testData = [
'foo' =>
'foo!',
'bar', [
'baz', null ] ];
406 $this->
store->setSessionData( self::SESSIONID, $testData );
408 $this->assertSame( $testData, $backend->getData() );
416 $priv->data = [
'foo' => 1 ];
417 $priv->dataDirty =
false;
418 $backend->addData( [
'foo' => 1 ] );
419 $this->assertSame( [
'foo' => 1 ], $priv->data );
420 $this->assertFalse( $priv->dataDirty );
422 $priv->data = [
'foo' => 1 ];
423 $priv->dataDirty =
false;
424 $backend->addData( [
'foo' =>
'1' ] );
425 $this->assertSame( [
'foo' =>
'1' ], $priv->data );
426 $this->assertTrue( $priv->dataDirty );
428 $priv->data = [
'foo' => 1 ];
429 $priv->dataDirty =
false;
430 $backend->addData( [
'bar' => 2 ] );
431 $this->assertSame( [
'foo' => 1,
'bar' => 2 ], $priv->data );
432 $this->assertTrue( $priv->dataDirty );
439 $priv->persist =
true;
442 $this->onSessionMetadataCalled =
false;
443 $priv->metaDirty =
true;
445 $this->assertTrue( $this->onSessionMetadataCalled,
'sanity check' );
447 $this->onSessionMetadataCalled =
false;
448 $priv->metaDirty =
true;
450 $this->assertTrue( $this->onSessionMetadataCalled,
'sanity check' );
452 $delay = $backend->delaySave();
455 $this->onSessionMetadataCalled =
false;
456 $priv->metaDirty =
true;
458 $this->assertFalse( $this->onSessionMetadataCalled );
462 $this->assertTrue( $this->onSessionMetadataCalled );
465 $this->onSessionMetadataCalled =
false;
466 $priv->metaDirty =
true;
467 \Wikimedia\ScopedCallback::consume( $delay );
468 $this->assertTrue( $this->onSessionMetadataCalled );
471 $delay1 = $backend->delaySave();
472 $delay2 = $backend->delaySave();
473 $delay3 = $backend->delaySave();
474 $this->onSessionMetadataCalled =
false;
475 $priv->metaDirty =
true;
477 $this->assertFalse( $this->onSessionMetadataCalled );
478 \Wikimedia\ScopedCallback::consume( $delay3 );
479 $this->assertFalse( $this->onSessionMetadataCalled );
480 \Wikimedia\ScopedCallback::consume( $delay1 );
481 $this->assertFalse( $this->onSessionMetadataCalled );
482 \Wikimedia\ScopedCallback::consume( $delay2 );
483 $this->assertTrue( $this->onSessionMetadataCalled );
487 $user = static::getTestSysop()->getUser();
489 $testData = [
'foo' =>
'foo!',
'bar', [
'baz', null ] ];
491 $neverHook = $this->getMock( __CLASS__, [
'onSessionMetadata' ] );
492 $neverHook->expects( $this->never() )->method(
'onSessionMetadata' );
494 $builder = $this->getMockBuilder(
'DummySessionProvider' )
495 ->setMethods( [
'persistSession',
'unpersistSession' ] );
497 $neverProvider = $builder->getMock();
498 $neverProvider->expects( $this->never() )->method(
'persistSession' );
499 $neverProvider->expects( $this->never() )->method(
'unpersistSession' );
502 $this->provider = $neverProvider;
504 $this->
store->setSessionData( self::SESSIONID, $testData );
506 $this->
store->deleteSession( self::SESSIONID );
507 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
511 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
514 $this->provider = $builder->getMock();
515 $this->provider->expects( $this->never() )->method(
'persistSession' );
516 $this->provider->expects( $this->atLeastOnce() )->method(
'unpersistSession' );
518 $this->
store->setSessionData( self::SESSIONID, $testData );
520 $this->
store->deleteSession( self::SESSIONID );
523 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
527 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
530 $this->provider = $neverProvider;
532 $this->
store->setSessionData( self::SESSIONID, $testData );
536 $this->
store->deleteSession( self::SESSIONID );
539 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
543 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
546 $this->provider = $neverProvider;
547 $this->onSessionMetadataCalled =
false;
549 $this->
store->setSessionData( self::SESSIONID, $testData );
551 $this->
store->deleteSession( self::SESSIONID );
552 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
556 $this->assertTrue( $this->onSessionMetadataCalled );
557 $blob = $this->
store->getSession( self::SESSIONID );
558 $this->assertInternalType(
'array',
$blob );
559 $this->assertArrayHasKey(
'metadata',
$blob );
560 $metadata =
$blob[
'metadata'];
561 $this->assertInternalType(
'array', $metadata );
562 $this->assertArrayHasKey(
'???', $metadata );
563 $this->assertSame(
'!!!', $metadata[
'???'] );
564 $this->assertFalse( $this->
store->getSessionFromBackend( self::SESSIONID ),
565 'making sure it didn\'t save to backend' );
568 $this->provider = $neverProvider;
570 $this->
store->setSessionData( self::SESSIONID, $testData );
572 $this->
store->deleteSession( self::SESSIONID );
574 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
578 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
581 $this->provider = $builder->getMock();
582 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
583 $this->provider->expects( $this->never() )->method(
'unpersistSession' );
585 $this->
store->setSessionData( self::SESSIONID, $testData );
587 $this->
store->deleteSession( self::SESSIONID );
590 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
594 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
597 $this->provider = $neverProvider;
598 $this->onSessionMetadataCalled =
false;
600 $this->
store->setSessionData( self::SESSIONID, $testData );
602 $this->
store->deleteSession( self::SESSIONID );
604 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
608 $this->assertTrue( $this->onSessionMetadataCalled );
609 $blob = $this->
store->getSession( self::SESSIONID );
610 $this->assertInternalType(
'array',
$blob );
611 $this->assertArrayHasKey(
'metadata',
$blob );
612 $metadata =
$blob[
'metadata'];
613 $this->assertInternalType(
'array', $metadata );
614 $this->assertArrayHasKey(
'???', $metadata );
615 $this->assertSame(
'!!!', $metadata[
'???'] );
616 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
617 'making sure it did save to backend' );
620 $this->provider = $builder->getMock();
621 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
622 $this->provider->expects( $this->never() )->method(
'unpersistSession' );
623 $this->onSessionMetadataCalled =
false;
625 $this->
store->setSessionData( self::SESSIONID, $testData );
627 $this->
store->deleteSession( self::SESSIONID );
630 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
634 $this->assertTrue( $this->onSessionMetadataCalled );
635 $blob = $this->
store->getSession( self::SESSIONID );
636 $this->assertInternalType(
'array',
$blob );
637 $this->assertArrayHasKey(
'metadata',
$blob );
638 $metadata =
$blob[
'metadata'];
639 $this->assertInternalType(
'array', $metadata );
640 $this->assertArrayHasKey(
'???', $metadata );
641 $this->assertSame(
'!!!', $metadata[
'???'] );
642 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
643 'making sure it did save to backend' );
646 $this->provider = $builder->getMock();
647 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
648 $this->provider->expects( $this->never() )->method(
'unpersistSession' );
649 $this->onSessionMetadataCalled =
false;
651 $this->
store->setSessionData( self::SESSIONID, $testData );
653 $this->
store->deleteSession( self::SESSIONID );
655 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
659 $this->assertTrue( $this->onSessionMetadataCalled );
660 $blob = $this->
store->getSession( self::SESSIONID );
661 $this->assertInternalType(
'array',
$blob );
662 $this->assertArrayHasKey(
'metadata',
$blob );
663 $metadata =
$blob[
'metadata'];
664 $this->assertInternalType(
'array', $metadata );
665 $this->assertArrayHasKey(
'???', $metadata );
666 $this->assertSame(
'!!!', $metadata[
'???'] );
667 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
668 'making sure it did save to backend' );
672 $this->provider = $neverProvider;
673 $this->onSessionMetadataCalled =
false;
675 $this->
store->setSessionData( self::SESSIONID, $testData );
677 $this->
store->deleteSession( self::SESSIONID );
679 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
684 $this->assertTrue( $this->onSessionMetadataCalled );
685 $blob = $this->
store->getSession( self::SESSIONID );
686 $this->assertInternalType(
'array',
$blob );
687 $this->assertArrayHasKey(
'metadata',
$blob );
688 $metadata =
$blob[
'metadata'];
689 $this->assertInternalType(
'array', $metadata );
690 $this->assertArrayHasKey(
'???', $metadata );
691 $this->assertSame(
'!!!', $metadata[
'???'] );
692 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
693 'making sure it did save to backend' );
696 $this->provider = null;
697 $mockHook = $this->getMock( __CLASS__, [
'onSessionMetadata' ] );
698 $mockHook->expects( $this->any() )->method(
'onSessionMetadata' )
699 ->will( $this->returnCallback(
701 $metadata[
'userId']++;
705 $this->
store->setSessionData( self::SESSIONID, $testData );
710 $this->fail(
'Expected exception not thrown' );
713 'SessionMetadata hook changed metadata key "userId"',
720 $user->getName() =>
true,
722 $this->provider = $neverProvider;
724 $this->
store->setSessionData( self::SESSIONID, $testData );
726 $this->
store->deleteSession( self::SESSIONID );
728 $this->assertTrue( $backend->
isPersistent(),
'sanity check' );
732 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
736 $user = static::getTestSysop()->getUser();
738 $testData = [
'foo' =>
'foo!',
'bar', [
'baz', null ] ];
741 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
742 $this->provider->expects( $this->never() )->method(
'persistSession' );
743 $this->onSessionMetadataCalled =
false;
745 $this->
store->setSessionData( self::SESSIONID, $testData );
747 $this->
store->deleteSession( self::SESSIONID );
749 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
750 $wrap->metaDirty =
false;
751 $wrap->dataDirty =
false;
752 $wrap->forcePersist =
false;
755 $this->assertTrue( $this->onSessionMetadataCalled );
756 $blob = $this->
store->getSession( self::SESSIONID );
757 $this->assertInternalType(
'array',
$blob );
758 $this->assertArrayHasKey(
'metadata',
$blob );
759 $metadata =
$blob[
'metadata'];
760 $this->assertInternalType(
'array', $metadata );
761 $this->assertArrayHasKey(
'???', $metadata );
762 $this->assertSame(
'!!!', $metadata[
'???'] );
763 $this->assertNotEquals( 0, $wrap->expires );
766 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
767 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
768 $this->onSessionMetadataCalled =
false;
770 $this->
store->setSessionData( self::SESSIONID, $testData );
772 $this->
store->deleteSession( self::SESSIONID );
774 $wrap->persist =
true;
775 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
776 $wrap->metaDirty =
false;
777 $wrap->dataDirty =
false;
778 $wrap->forcePersist =
false;
781 $this->assertTrue( $this->onSessionMetadataCalled );
782 $blob = $this->
store->getSession( self::SESSIONID );
783 $this->assertInternalType(
'array',
$blob );
784 $this->assertArrayHasKey(
'metadata',
$blob );
785 $metadata =
$blob[
'metadata'];
786 $this->assertInternalType(
'array', $metadata );
787 $this->assertArrayHasKey(
'???', $metadata );
788 $this->assertSame(
'!!!', $metadata[
'???'] );
789 $this->assertNotEquals( 0, $wrap->expires );
792 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
793 $this->provider->expects( $this->never() )->method(
'persistSession' );
794 $this->onSessionMetadataCalled =
false;
796 $this->
store->setSessionData( self::SESSIONID, $testData );
798 $this->
store->deleteSession( self::SESSIONID );
800 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
801 $wrap->metaDirty =
false;
802 $wrap->dataDirty =
false;
803 $wrap->forcePersist =
false;
804 $expires = time() + $wrap->lifetime + 100;
805 $wrap->expires = $expires;
807 $this->assertFalse( $this->onSessionMetadataCalled );
808 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
809 $this->assertEquals( $expires, $wrap->expires );
813 $this->onSessionMetadataCalled =
true;
814 $metadata[
'???'] =
'!!!';
823 $rProp->setAccessible(
true );
825 $resetHandler = new \Wikimedia\ScopedCallback(
function ()
use (
$handler ) {
826 session_write_close();
832 $backend = $this->
getBackend( static::getTestSysop()->getUser() );
844 $this->assertSame( $backend->getId(), session_id() );
845 session_write_close();
854 $this->assertSame(
'', session_id() );
863 $rProp->setAccessible(
true );
865 $resetHandler = new \Wikimedia\ScopedCallback(
function ()
use (
$handler ) {
866 session_write_close();
882 session_id( self::SESSIONID );
883 \MediaWiki\quietCall(
'session_start' );
884 $_SESSION[
'foo'] = __METHOD__;
886 $this->assertNotEquals( self::SESSIONID, $backend->getId() );
887 $this->assertSame( $backend->getId(), session_id() );
888 $this->assertArrayHasKey(
'foo', $_SESSION );
889 $this->assertSame( __METHOD__, $_SESSION[
'foo'] );
890 session_write_close();
899 $rProp->setAccessible(
true );
901 $resetHandler = new \Wikimedia\ScopedCallback(
function ()
use (
$handler ) {
902 session_write_close();
910 $wrap->usePhpSessionHandling =
true;
911 $wrap->persist =
true;
920 session_id( self::SESSIONID .
'x' );
921 \MediaWiki\quietCall(
'session_start' );
922 $backend->unpersist();
923 $this->assertSame( self::SESSIONID .
'x', session_id() );
925 session_id( self::SESSIONID );
926 $wrap->persist =
true;
927 $backend->unpersist();
928 $this->assertSame(
'', session_id() );
932 $this->provider = $this->getMockBuilder(
'DummySessionProvider' )
933 ->setMethods( [
'getAllowedUserRights' ] )
935 $this->provider->expects( $this->any() )->method(
'getAllowedUserRights' )
936 ->will( $this->returnValue( [
'foo',
'bar' ] ) );
939 $this->assertSame( [
'foo',
'bar' ], $backend->getAllowedUserRights() );
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
the array() calling protocol came about after MediaWiki 1.4rc1.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database store
static getMain()
Static methods.
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks hooks can tweak the array to change how login etc forms should look $requests
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
error also a ContextSource you ll probably need to make sure the header is varied on $request
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
wfMemcKey()
Make a cache key for the local wiki.
static newFromObject($object)
Return the same object, without access restrictions.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler