18 set_error_handler(
function ( $errno, $errstr )
use ( &$warnings ) {
19 if ( preg_match(
'/headers already sent/', $errstr ) ) {
24 $reset[] = new \Wikimedia\ScopedCallback(
'restore_error_handler' );
27 $rProp->setAccessible(
true );
28 if ( $rProp->getValue() ) {
30 $oldManager = $old->manager;
31 $oldStore = $old->store;
32 $oldLogger = $old->logger;
33 $reset[] = new \Wikimedia\ScopedCallback(
35 [ $oldManager, $oldStore, $oldLogger ]
46 ->disableOriginalConstructor()
51 $rProp->setAccessible(
true );
52 $reset = new \Wikimedia\ScopedCallback( [ $rProp,
'setValue' ], [ $rProp->getValue() ] );
55 $handler->setEnableFlags(
'enable' );
56 $this->assertTrue(
$handler->enable );
57 $this->assertFalse(
$handler->warn );
61 $this->assertTrue(
$handler->enable );
65 $handler->setEnableFlags(
'disable' );
66 $this->assertFalse(
$handler->enable );
69 $rProp->setValue( null );
75 $rProp->setValue( null );
77 session_write_close();
78 ini_set(
'session.use_cookies', 1 );
79 ini_set(
'session.use_trans_sid', 1 );
82 $logger = new \TestLogger();
92 $this->assertFalse(
wfIniGetBool(
'session.use_cookies' ) );
93 $this->assertFalse(
wfIniGetBool(
'session.use_trans_sid' ) );
95 $this->assertNotNull( $rProp->getValue() );
97 $this->assertSame( $manager, $priv->manager );
98 $this->assertSame( $store, $priv->store );
99 $this->assertSame( $logger, $priv->logger );
111 'wgSessionProviders' => [ [
'class' =>
'DummySessionProvider' ] ],
112 'wgObjectCacheSessionExpiry' => 2,
116 $logger = new \TestLogger(
true,
function ( $m ) {
118 return preg_match(
'/^SessionBackend "\{session\}" /', $m ) ? null : $m;
126 $reset[] = new \Wikimedia\ScopedCallback(
127 [ $wrap,
'setEnableFlags' ],
128 [ $wrap->enable ? $wrap->warn ?
'warn' :
'enable' :
'disable' ]
130 $wrap->setEnableFlags(
'warn' );
132 \MediaWiki\suppressWarnings();
133 ini_set(
'session.serialize_handler',
$handler );
134 \MediaWiki\restoreWarnings();
135 if ( ini_get(
'session.serialize_handler' ) !==
$handler ) {
136 $this->markTestSkipped(
"Cannot set session.serialize_handler to \"$handler\"" );
140 $sessionA = str_repeat(
'a', 32 );
141 $sessionB = str_repeat(
'b', 32 );
142 $sessionC = str_repeat(
'c', 32 );
145 $_SESSION[
'AuthenticationSessionTest'] =
'bogus';
147 session_id( $sessionA );
149 $this->assertSame( [], $_SESSION );
150 $this->assertSame( $sessionA, session_id() );
154 $_SESSION[
'AuthenticationSessionTest'] = $rand;
155 $expect = [
'AuthenticationSessionTest' => $rand ];
156 session_write_close();
158 [ LogLevel::WARNING,
'Something wrote to $_SESSION!' ],
159 ], $logger->getBuffer() );
163 $_SESSION[
'AuthenticationSessionTest'] =
'bogus';
167 $this->assertSame( $expect, $_SESSION );
170 if ( function_exists(
'session_reset' ) ) {
171 $_SESSION[
'AuthenticationSessionTest'] =
'bogus';
173 $this->assertSame( $expect, $_SESSION );
177 $_SESSION[
'AuthenticationSessionTest'] = $rand;
178 session_write_close();
180 $this->assertSame( $expect, $_SESSION );
182 session_id( $sessionA );
184 $this->assertSame( [], $_SESSION );
185 session_write_close();
188 session_id( $sessionB );
190 $this->assertSame( $sessionB, session_id() );
191 $_SESSION[
'id'] =
'B';
192 session_write_close();
194 session_id( $sessionC );
196 $this->assertSame( [], $_SESSION );
197 $_SESSION[
'id'] =
'C';
198 session_write_close();
200 session_id( $sessionB );
202 $this->assertSame( [
'id' =>
'B' ], $_SESSION );
203 session_write_close();
205 session_id( $sessionC );
207 $this->assertSame( [
'id' =>
'C' ], $_SESSION );
210 session_id( $sessionB );
212 $this->assertSame( [
'id' =>
'B' ], $_SESSION );
215 session_write_close();
217 $session = $manager->getEmptySession();
218 $session->set(
'Unchanged',
'setup' );
219 $session->set(
'Unchanged, null', null );
220 $session->set(
'Changed in $_SESSION',
'setup' );
221 $session->set(
'Changed in Session',
'setup' );
222 $session->set(
'Changed in both',
'setup' );
223 $session->set(
'Deleted in Session',
'setup' );
224 $session->set(
'Deleted in $_SESSION',
'setup' );
225 $session->set(
'Deleted in both',
'setup' );
226 $session->set(
'Deleted in Session, changed in $_SESSION',
'setup' );
227 $session->set(
'Deleted in $_SESSION, changed in Session',
'setup' );
231 session_id( $session->getId() );
233 $session->set(
'Added in Session',
'Session' );
234 $session->set(
'Added in both',
'Session' );
235 $session->set(
'Changed in Session',
'Session' );
236 $session->set(
'Changed in both',
'Session' );
237 $session->set(
'Deleted in $_SESSION, changed in Session',
'Session' );
238 $session->remove(
'Deleted in Session' );
239 $session->remove(
'Deleted in both' );
240 $session->remove(
'Deleted in Session, changed in $_SESSION' );
242 $_SESSION[
'Added in $_SESSION'] =
'$_SESSION';
243 $_SESSION[
'Added in both'] =
'$_SESSION';
244 $_SESSION[
'Changed in $_SESSION'] =
'$_SESSION';
245 $_SESSION[
'Changed in both'] =
'$_SESSION';
246 $_SESSION[
'Deleted in Session, changed in $_SESSION'] =
'$_SESSION';
247 unset( $_SESSION[
'Deleted in $_SESSION'] );
248 unset( $_SESSION[
'Deleted in both'] );
249 unset( $_SESSION[
'Deleted in $_SESSION, changed in Session'] );
250 session_write_close();
252 $this->assertEquals( [
253 'Added in Session' =>
'Session',
254 'Added in $_SESSION' =>
'$_SESSION',
255 'Added in both' =>
'Session',
256 'Unchanged' =>
'setup',
257 'Unchanged, null' => null,
258 'Changed in Session' =>
'Session',
259 'Changed in $_SESSION' =>
'$_SESSION',
260 'Changed in both' =>
'Session',
261 'Deleted in Session, changed in $_SESSION' =>
'$_SESSION',
262 'Deleted in $_SESSION, changed in Session' =>
'Session',
263 ], iterator_to_array( $session ) );
266 $session->set( 42,
'forty-two' );
267 $session->set(
'forty-two', 42 );
268 $session->set(
'wrong', 43 );
273 $this->assertArrayHasKey(
'forty-two', $_SESSION );
274 $this->assertSame( 42, $_SESSION[
'forty-two'] );
275 $this->assertArrayHasKey(
'wrong', $_SESSION );
276 unset( $_SESSION[
'wrong'] );
277 session_write_close();
279 $this->assertEquals( [
282 ], iterator_to_array( $session ) );
285 $session = $manager->getEmptySession();
287 $id = $session->getId();
292 'SessionCheckInfo' => [
function ( &$reason ) {
297 $this->assertNull( $manager->getSessionById( $id,
true ),
'sanity check' );
298 session_write_close();
301 'SessionCheckInfo' => [],
303 $this->assertNotNull( $manager->getSessionById( $id,
true ),
'sanity check' );
321 $rProp->setAccessible(
true );
324 ->disableOriginalConstructor()
327 $oldValue = $rProp->getValue();
329 $reset = new \Wikimedia\ScopedCallback( [ $rProp,
'setValue' ], [ $oldValue ] );
336 [
'open', [
'',
'' ] ],
338 [
'write', [
'',
'' ] ],
339 [
'destroy', [
'' ] ],
351 ->disableOriginalConstructor()
360 [
'open', [
'',
'' ] ],
363 [
'write', [
'',
'' ] ],
364 [
'destroy', [
'' ] ],
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfIniGetBool($setting)
Safety wrapper around ini_get() for boolean settings.
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
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
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