22 $this->assertSame( $backend, $priv->backend );
23 $this->assertSame( 42, $priv->index );
27 $this->assertSame( $backend, $priv2->backend );
28 $this->assertNotSame( $priv->index, $priv2->index );
41 [ $m,
'deregisterSession' ] );
42 $mock->expects( $this->once() )->method(
'deregisterSession' )
43 ->with( $this->identicalTo( 42 ) );
45 $tmp = $mock->expects( $this->once() )->method( $m );
48 $expectArgs[] = $this->identicalTo( 42 );
51 $expectArgs[] = $this->identicalTo( $arg );
53 $tmp = call_user_func_array( [ $tmp,
'with' ], $expectArgs );
56 $tmp->will( $this->returnValue(
$retval ) );
61 $this->assertSame(
$retval, call_user_func_array( [ $session, $m ],
$args ) );
63 $this->assertNull( call_user_func_array( [ $session, $m ],
$args ) );
72 [
'getId', [],
false,
true ],
73 [
'getSessionId', [],
false,
true ],
74 [
'resetId', [],
false,
true ],
75 [
'getProvider', [],
false,
true ],
76 [
'isPersistent', [],
false,
true ],
77 [
'persist', [],
false,
false ],
78 [
'unpersist', [],
false,
false ],
79 [
'shouldRememberUser', [],
false,
true ],
80 [
'setRememberUser', [
true ],
false,
false ],
81 [
'getRequest', [],
true,
true ],
82 [
'getUser', [],
false,
true ],
83 [
'getAllowedUserRights', [],
false,
true ],
84 [
'canSetUser', [],
false,
true ],
85 [
'setUser', [ new \stdClass ],
false,
false ],
86 [
'suggestLoginUsername', [],
true,
true ],
87 [
'shouldForceHTTPS', [],
false,
true ],
88 [
'setForceHTTPS', [
true ],
false,
false ],
89 [
'getLoggedOutTimestamp', [],
false,
true ],
90 [
'setLoggedOutTimestamp', [ 123 ],
false,
false ],
91 [
'getProviderMetadata', [],
false,
true ],
92 [
'save', [],
false,
false ],
93 [
'delaySave', [],
false,
true ],
94 [
'renew', [],
false,
false ],
102 $this->assertEquals( 1, $session->get(
'foo' ) );
103 $this->assertEquals(
'zero', $session->get( 0 ) );
104 $this->assertFalse( $backend->dirty );
106 $this->assertEquals( null, $session->get(
'null' ) );
107 $this->assertEquals(
'default', $session->get(
'null',
'default' ) );
108 $this->assertFalse( $backend->dirty );
110 $session->set(
'foo', 55 );
111 $this->assertEquals( 55, $backend->data[
'foo'] );
112 $this->assertTrue( $backend->dirty );
113 $backend->dirty =
false;
115 $session->set( 1,
'one' );
116 $this->assertEquals(
'one', $backend->data[1] );
117 $this->assertTrue( $backend->dirty );
118 $backend->dirty =
false;
120 $session->set( 1,
'one' );
121 $this->assertFalse( $backend->dirty );
123 $this->assertTrue( $session->exists(
'foo' ) );
124 $this->assertTrue( $session->exists( 1 ) );
125 $this->assertFalse( $session->exists(
'null' ) );
126 $this->assertFalse( $session->exists( 100 ) );
127 $this->assertFalse( $backend->dirty );
129 $session->remove(
'foo' );
130 $this->assertArrayNotHasKey(
'foo', $backend->data );
131 $this->assertTrue( $backend->dirty );
132 $backend->dirty =
false;
133 $session->remove( 1 );
134 $this->assertArrayNotHasKey( 1, $backend->data );
135 $this->assertTrue( $backend->dirty );
136 $backend->dirty =
false;
138 $session->remove( 101 );
139 $this->assertFalse( $backend->dirty );
141 $backend->data = [
'a',
'b',
'?' =>
'c' ];
142 $this->assertSame( 3, $session->count() );
143 $this->assertSame( 3, count( $session ) );
144 $this->assertFalse( $backend->dirty );
147 foreach ( $session
as $key =>
$value ) {
150 $this->assertEquals( $backend->data, $data );
151 $this->assertFalse( $backend->dirty );
153 $this->assertEquals( $backend->data, iterator_to_array( $session ) );
154 $this->assertFalse( $backend->dirty );
158 $logger = new \TestLogger;
162 $this->assertEquals( 1, $session[
'foo'] );
163 $this->assertEquals(
'zero', $session[0] );
164 $this->assertFalse( $backend->dirty );
166 $logger->setCollect(
true );
167 $this->assertEquals( null, $session[
'null'] );
168 $logger->setCollect(
false );
169 $this->assertFalse( $backend->dirty );
171 [ LogLevel::DEBUG,
'Undefined index (auto-adds to session with a null value): null' ]
172 ], $logger->getBuffer() );
173 $logger->clearBuffer();
175 $session[
'foo'] = 55;
176 $this->assertEquals( 55, $backend->data[
'foo'] );
177 $this->assertTrue( $backend->dirty );
178 $backend->dirty =
false;
181 $this->assertEquals(
'one', $backend->data[1] );
182 $this->assertTrue( $backend->dirty );
183 $backend->dirty =
false;
186 $this->assertFalse( $backend->dirty );
188 $session[
'bar'] = [
'baz' => [] ];
189 $session[
'bar'][
'baz'][
'quux'] = 2;
190 $this->assertEquals( [
'baz' => [
'quux' => 2 ] ], $backend->data[
'bar'] );
192 $logger->setCollect(
true );
193 $session[
'bar2'][
'baz'][
'quux'] = 3;
194 $logger->setCollect(
false );
195 $this->assertEquals( [
'baz' => [
'quux' => 3 ] ], $backend->data[
'bar2'] );
197 [ LogLevel::DEBUG,
'Undefined index (auto-adds to session with a null value): bar2' ]
198 ], $logger->getBuffer() );
199 $logger->clearBuffer();
201 $backend->dirty =
false;
202 $this->assertTrue( isset( $session[
'foo'] ) );
203 $this->assertTrue( isset( $session[1] ) );
204 $this->assertFalse( isset( $session[
'null'] ) );
205 $this->assertFalse( isset( $session[
'missing'] ) );
206 $this->assertFalse( isset( $session[100] ) );
207 $this->assertFalse( $backend->dirty );
209 unset( $session[
'foo'] );
210 $this->assertArrayNotHasKey(
'foo', $backend->data );
211 $this->assertTrue( $backend->dirty );
212 $backend->dirty =
false;
213 unset( $session[1] );
214 $this->assertArrayNotHasKey( 1, $backend->data );
215 $this->assertTrue( $backend->dirty );
216 $backend->dirty =
false;
218 unset( $session[101] );
219 $this->assertFalse( $backend->dirty );
226 $backend = $this->getMock(
229 $backend->expects( $this->once() )->method(
'canSetUser' )
230 ->will( $this->returnValue(
true ) );
231 $backend->expects( $this->once() )->method(
'setUser' )
232 ->with( $this->callback(
function (
$user ) {
235 $backend->expects( $this->once() )->method(
'save' );
236 $priv->backend = $backend;
238 $this->assertSame( [], $backend->data );
239 $this->assertTrue( $backend->dirty );
241 $backend = $this->getMock(
245 $backend->expects( $this->once() )->method(
'canSetUser' )
246 ->will( $this->returnValue(
true ) );
247 $backend->expects( $this->once() )->method(
'setUser' )
248 ->with( $this->callback(
function (
$user ) {
251 $backend->expects( $this->once() )->method(
'save' );
252 $priv->backend = $backend;
254 $this->assertFalse( $backend->dirty );
256 $backend = $this->getMock(
259 $backend->expects( $this->once() )->method(
'canSetUser' )
260 ->will( $this->returnValue(
false ) );
261 $backend->expects( $this->never() )->method(
'setUser' );
262 $backend->expects( $this->once() )->method(
'save' );
263 $priv->backend = $backend;
265 $this->assertSame( [], $backend->data );
266 $this->assertTrue( $backend->dirty );
272 $backend = $priv->backend;
275 $this->assertArrayHasKey(
'wsTokenSecrets', $backend->data );
276 $this->assertArrayHasKey(
'default', $backend->data[
'wsTokenSecrets'] );
277 $secret = $backend->data[
'wsTokenSecrets'][
'default'];
278 $this->assertSame( $secret, $token->secret );
279 $this->assertSame(
'', $token->salt );
280 $this->assertTrue( $token->wasNew() );
283 $this->assertSame( $secret, $token->secret );
284 $this->assertSame(
'foo', $token->salt );
285 $this->assertFalse( $token->wasNew() );
287 $backend->data[
'wsTokenSecrets'][
'secret'] =
'sekret';
289 $session->getToken( [
'bar',
'baz' ],
'secret' )
291 $this->assertSame(
'sekret', $token->secret );
292 $this->assertSame(
'bar|baz', $token->salt );
293 $this->assertFalse( $token->wasNew() );
295 $session->resetToken(
'secret' );
296 $this->assertArrayHasKey(
'wsTokenSecrets', $backend->data );
297 $this->assertArrayHasKey(
'default', $backend->data[
'wsTokenSecrets'] );
298 $this->assertArrayNotHasKey(
'secret', $backend->data[
'wsTokenSecrets'] );
300 $session->resetAllTokens();
301 $this->assertArrayNotHasKey(
'wsTokenSecrets', $backend->data );
313 $session->setSecret(
'secret', $data );
314 $this->assertNotEquals( $data, $session->get(
'secret' ) );
315 $this->assertEquals( $data, $session->getSecret(
'secret',
'defaulted' ) );
322 [ [
'foo',
'bar' =>
'baz',
'subarray' => [ 1, 2, 3 ] ] ],
323 [ (
object)[
'foo',
'bar' =>
'baz',
'subarray' => [ 1, 2, 3 ] ] ],
331 $logger = new \TestLogger;
335 $this->assertEquals(
'defaulted', $session->getSecret(
'test',
'defaulted' ) );
338 $session->set(
'test',
'foobar' );
339 $logger->setCollect(
true );
340 $this->assertEquals(
'defaulted', $session->getSecret(
'test',
'defaulted' ) );
341 $logger->setCollect(
false );
343 [ LogLevel::WARNING,
'Invalid sealed-secret format' ]
344 ], $logger->getBuffer() );
345 $logger->clearBuffer();
348 $session->setSecret(
'test',
'foobar' );
349 $encrypted = $session->get(
'test' );
350 $session->set(
'test', $encrypted .
'x' );
351 $logger->setCollect(
true );
352 $this->assertEquals(
'defaulted', $session->getSecret(
'test',
'defaulted' ) );
353 $logger->setCollect(
false );
355 [ LogLevel::WARNING,
'Sealed secret has been tampered with, aborting.' ]
356 ], $logger->getBuffer() );
357 $logger->clearBuffer();
362 $ciphertext = openssl_encrypt(
'foobar',
'aes-256-ctr', $encKey, OPENSSL_RAW_DATA, $iv );
363 $sealed = base64_encode( $iv ) .
'.' . base64_encode( $ciphertext );
364 $hmac = hash_hmac(
'sha256', $sealed, $hmacKey,
true );
365 $encrypted = base64_encode( $hmac ) .
'.' . $sealed;
366 $session->set(
'test', $encrypted );
367 \MediaWiki\suppressWarnings();
368 $this->assertEquals(
'defaulted', $session->getSecret(
'test',
'defaulted' ) );
369 \MediaWiki\restoreWarnings();
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
processing should stop and the error should be shown to the user * false
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
getRequest()
Get the WebRequest object.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
A logger that may be configured to either buffer logs or to print them to the output where PHPUnit wi...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
static generate($bytes, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in raw binary form...
static newFromObject($object)
Return the same object, without access restrictions.
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 incomplete not yet checked for validity & $retval