MediaWiki  1.33.0
TemporaryPasswordPrimaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
6 use Wikimedia\ScopedCallback;
7 use Wikimedia\TestingAccessWrapper;
8 
15 
16  private $manager = null;
17  private $config = null;
18  private $validity = null;
19 
29  protected function getProvider( $params = [] ) {
30  if ( !$this->config ) {
31  $this->config = new \HashConfig( [
32  'EmailEnabled' => true,
33  ] );
34  }
35  $config = new \MultiConfig( [
36  $this->config,
37  MediaWikiServices::getInstance()->getMainConfig()
38  ] );
39 
40  if ( !$this->manager ) {
41  $this->manager = new AuthManager( new \FauxRequest(), $config );
42  }
43  $this->validity = \Status::newGood();
44 
45  $mockedMethods[] = 'checkPasswordValidity';
46  $provider = $this->getMockBuilder( TemporaryPasswordPrimaryAuthenticationProvider::class )
47  ->setMethods( $mockedMethods )
48  ->setConstructorArgs( [ $params ] )
49  ->getMock();
50  $provider->expects( $this->any() )->method( 'checkPasswordValidity' )
51  ->will( $this->returnCallback( function () {
52  return $this->validity;
53  } ) );
54  $provider->setConfig( $config );
55  $provider->setLogger( new \Psr\Log\NullLogger() );
56  $provider->setManager( $this->manager );
57 
58  return $provider;
59  }
60 
61  protected function hookMailer( $func = null ) {
62  \Hooks::clear( 'AlternateUserMailer' );
63  if ( $func ) {
64  \Hooks::register( 'AlternateUserMailer', $func );
65  // Safety
66  \Hooks::register( 'AlternateUserMailer', function () {
67  return false;
68  } );
69  } else {
70  \Hooks::register( 'AlternateUserMailer', function () {
71  $this->fail( 'AlternateUserMailer hook called unexpectedly' );
72  return false;
73  } );
74  }
75 
76  return new ScopedCallback( function () {
77  \Hooks::clear( 'AlternateUserMailer' );
78  \Hooks::register( 'AlternateUserMailer', function () {
79  return false;
80  } );
81  } );
82  }
83 
84  public function testBasics() {
86 
87  $this->assertSame(
89  $provider->accountCreationType()
90  );
91 
92  $this->assertTrue( $provider->testUserExists( 'UTSysop' ) );
93  $this->assertTrue( $provider->testUserExists( 'uTSysop' ) );
94  $this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
95  $this->assertFalse( $provider->testUserExists( '<invalid>' ) );
96 
99  $req->username = '<invalid>';
100  $provider->providerChangeAuthenticationData( $req );
101  }
102 
103  public function testConfig() {
104  $config = new \HashConfig( [
105  'EnableEmail' => false,
106  'NewPasswordExpiry' => 100,
107  'PasswordReminderResendTime' => 101,
108  ] );
109 
110  $p = TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider() );
111  $p->setConfig( $config );
112  $this->assertSame( false, $p->emailEnabled );
113  $this->assertSame( 100, $p->newPasswordExpiry );
114  $this->assertSame( 101, $p->passwordReminderResendTime );
115 
116  $p = TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider( [
117  'emailEnabled' => true,
118  'newPasswordExpiry' => 42,
119  'passwordReminderResendTime' => 43,
120  ] ) );
121  $p->setConfig( $config );
122  $this->assertSame( true, $p->emailEnabled );
123  $this->assertSame( 42, $p->newPasswordExpiry );
124  $this->assertSame( 43, $p->passwordReminderResendTime );
125  }
126 
127  public function testTestUserCanAuthenticate() {
128  $user = self::getMutableTestUser()->getUser();
129 
130  $dbw = wfGetDB( DB_MASTER );
131  $config = MediaWikiServices::getInstance()->getMainConfig();
132  // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
133  $passwordFactory = new \PasswordFactory( $config->get( 'PasswordConfig' ), 'A' );
134 
135  $pwhash = $passwordFactory->newFromPlaintext( 'password' )->toString();
136 
137  $provider = $this->getProvider();
138  $providerPriv = TestingAccessWrapper::newFromObject( $provider );
139 
140  $this->assertFalse( $provider->testUserCanAuthenticate( '<invalid>' ) );
141  $this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) );
142 
143  $dbw->update(
144  'user',
145  [
146  'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
147  'user_newpass_time' => null,
148  ],
149  [ 'user_id' => $user->getId() ]
150  );
151  $this->assertFalse( $provider->testUserCanAuthenticate( $user->getName() ) );
152 
153  $dbw->update(
154  'user',
155  [
156  'user_newpassword' => $pwhash,
157  'user_newpass_time' => null,
158  ],
159  [ 'user_id' => $user->getId() ]
160  );
161  $this->assertTrue( $provider->testUserCanAuthenticate( $user->getName() ) );
162  $this->assertTrue( $provider->testUserCanAuthenticate( lcfirst( $user->getName() ) ) );
163 
164  $dbw->update(
165  'user',
166  [
167  'user_newpassword' => $pwhash,
168  'user_newpass_time' => $dbw->timestamp( time() - 10 ),
169  ],
170  [ 'user_id' => $user->getId() ]
171  );
172  $providerPriv->newPasswordExpiry = 100;
173  $this->assertTrue( $provider->testUserCanAuthenticate( $user->getName() ) );
174  $providerPriv->newPasswordExpiry = 1;
175  $this->assertFalse( $provider->testUserCanAuthenticate( $user->getName() ) );
176 
177  $dbw->update(
178  'user',
179  [
180  'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
181  'user_newpass_time' => null,
182  ],
183  [ 'user_id' => $user->getId() ]
184  );
185  }
186 
193  public function testGetAuthenticationRequests( $action, $options, $expected ) {
194  $actual = $this->getProvider()->getAuthenticationRequests( $action, $options );
195  foreach ( $actual as $req ) {
196  if ( $req instanceof TemporaryPasswordAuthenticationRequest && $req->password !== null ) {
197  $req->password = 'random';
198  }
199  }
200  $this->assertEquals( $expected, $actual );
201  }
202 
203  public static function provideGetAuthenticationRequests() {
204  $anon = [ 'username' => null ];
205  $loggedIn = [ 'username' => 'UTSysop' ];
206 
207  return [
208  [ AuthManager::ACTION_LOGIN, $anon, [
210  ] ],
211  [ AuthManager::ACTION_LOGIN, $loggedIn, [
213  ] ],
214  [ AuthManager::ACTION_CREATE, $anon, [] ],
215  [ AuthManager::ACTION_CREATE, $loggedIn, [
217  ] ],
218  [ AuthManager::ACTION_LINK, $anon, [] ],
219  [ AuthManager::ACTION_LINK, $loggedIn, [] ],
220  [ AuthManager::ACTION_CHANGE, $anon, [
222  ] ],
223  [ AuthManager::ACTION_CHANGE, $loggedIn, [
225  ] ],
226  [ AuthManager::ACTION_REMOVE, $anon, [
228  ] ],
229  [ AuthManager::ACTION_REMOVE, $loggedIn, [
231  ] ],
232  ];
233  }
234 
235  public function testAuthentication() {
236  $user = self::getMutableTestUser()->getUser();
237 
238  $password = 'TemporaryPassword';
239  $hash = ':A:' . md5( $password );
240  $dbw = wfGetDB( DB_MASTER );
241  $dbw->update(
242  'user',
243  [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ],
244  [ 'user_id' => $user->getId() ]
245  );
246 
250 
251  $provider = $this->getProvider();
252  $providerPriv = TestingAccessWrapper::newFromObject( $provider );
253 
254  $providerPriv->newPasswordExpiry = 100;
255 
256  // General failures
257  $this->assertEquals(
259  $provider->beginPrimaryAuthentication( [] )
260  );
261 
262  $req->username = 'foo';
263  $req->password = null;
264  $this->assertEquals(
266  $provider->beginPrimaryAuthentication( $reqs )
267  );
268 
269  $req->username = null;
270  $req->password = 'bar';
271  $this->assertEquals(
273  $provider->beginPrimaryAuthentication( $reqs )
274  );
275 
276  $req->username = '<invalid>';
277  $req->password = 'WhoCares';
278  $ret = $provider->beginPrimaryAuthentication( $reqs );
279  $this->assertEquals(
281  $provider->beginPrimaryAuthentication( $reqs )
282  );
283 
284  $req->username = 'DoesNotExist';
285  $req->password = 'DoesNotExist';
286  $ret = $provider->beginPrimaryAuthentication( $reqs );
287  $this->assertEquals(
289  $provider->beginPrimaryAuthentication( $reqs )
290  );
291 
292  // Validation failure
293  $req->username = $user->getName();
294  $req->password = $password;
295  $this->validity = \Status::newFatal( 'arbitrary-failure' );
296  $ret = $provider->beginPrimaryAuthentication( $reqs );
297  $this->assertEquals(
299  $ret->status
300  );
301  $this->assertEquals(
302  'arbitrary-failure',
303  $ret->message->getKey()
304  );
305 
306  // Successful auth
307  $this->manager->removeAuthenticationSessionData( null );
308  $this->validity = \Status::newGood();
309  $this->assertEquals(
311  $provider->beginPrimaryAuthentication( $reqs )
312  );
313  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
314 
315  $this->manager->removeAuthenticationSessionData( null );
316  $this->validity = \Status::newGood();
317  $req->username = lcfirst( $user->getName() );
318  $this->assertEquals(
320  $provider->beginPrimaryAuthentication( $reqs )
321  );
322  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
323  $req->username = $user->getName();
324 
325  // Expired password
326  $providerPriv->newPasswordExpiry = 1;
327  $ret = $provider->beginPrimaryAuthentication( $reqs );
328  $this->assertEquals(
330  $ret->status
331  );
332  $this->assertEquals(
333  'wrongpassword',
334  $ret->message->getKey()
335  );
336 
337  // Bad password
338  $providerPriv->newPasswordExpiry = 100;
339  $this->validity = \Status::newGood();
340  $req->password = 'Wrong';
341  $ret = $provider->beginPrimaryAuthentication( $reqs );
342  $this->assertEquals(
344  $ret->status
345  );
346  $this->assertEquals(
347  'wrongpassword',
348  $ret->message->getKey()
349  );
350  }
351 
361  \StatusValue $expect1, \StatusValue $expect2
362  ) {
365  ) {
366  $req = new $type();
367  } else {
368  $req = $this->createMock( $type );
369  }
371  $req->username = $user;
372  $req->password = 'NewPassword';
373 
374  $provider = $this->getProvider();
375  $this->validity = $validity;
376  $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange( $req, false ) );
377  $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange( $req, true ) );
378  }
379 
381  $err = \StatusValue::newGood();
382  $err->error( 'arbitrary-warning' );
383 
384  return [
386  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
388  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
394  \StatusValue::newGood(), $err ],
396  \Status::newFatal( 'arbitrary-error' ), \StatusValue::newGood(),
397  \StatusValue::newFatal( 'arbitrary-error' ) ],
402  ];
403  }
404 
411  public function testProviderChangeAuthenticationData( $user, $type, $changed ) {
412  $cuser = ucfirst( $user );
413  $oldpass = 'OldTempPassword';
414  $newpass = 'NewTempPassword';
415 
416  $dbw = wfGetDB( DB_MASTER );
417  $oldHash = $dbw->selectField( 'user', 'user_newpassword', [ 'user_name' => $cuser ] );
418  $cb = new ScopedCallback( function () use ( $dbw, $cuser, $oldHash ) {
419  $dbw->update( 'user', [ 'user_newpassword' => $oldHash ], [ 'user_name' => $cuser ] );
420  } );
421 
422  $hash = ':A:' . md5( $oldpass );
423  $dbw->update(
424  'user',
425  [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() + 10 ) ],
426  [ 'user_name' => $cuser ]
427  );
428 
429  $provider = $this->getProvider();
430 
431  // Sanity check
432  $loginReq = new PasswordAuthenticationRequest();
433  $loginReq->action = AuthManager::ACTION_CHANGE;
434  $loginReq->username = $user;
435  $loginReq->password = $oldpass;
436  $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
437  $this->assertEquals(
439  $provider->beginPrimaryAuthentication( $loginReqs ),
440  'Sanity check'
441  );
442 
445  ) {
446  $changeReq = new $type();
447  } else {
448  $changeReq = $this->createMock( $type );
449  }
450  $changeReq->action = AuthManager::ACTION_CHANGE;
451  $changeReq->username = $user;
452  $changeReq->password = $newpass;
453  $resetMailer = $this->hookMailer();
454  $provider->providerChangeAuthenticationData( $changeReq );
455  ScopedCallback::consume( $resetMailer );
456 
457  $loginReq->password = $oldpass;
458  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
459  $this->assertEquals(
461  $ret->status,
462  'old password should fail'
463  );
464  $this->assertEquals(
465  'wrongpassword',
466  $ret->message->getKey(),
467  'old password should fail'
468  );
469 
470  $loginReq->password = $newpass;
471  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
472  if ( $changed ) {
473  $this->assertEquals(
475  $ret,
476  'new password should pass'
477  );
478  $this->assertNotNull(
479  $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $cuser ] )
480  );
481  } else {
482  $this->assertEquals(
484  $ret->status,
485  'new password should fail'
486  );
487  $this->assertEquals(
488  'wrongpassword',
489  $ret->message->getKey(),
490  'new password should fail'
491  );
492  $this->assertNull(
493  $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $cuser ] )
494  );
495  }
496  }
497 
498  public static function provideProviderChangeAuthenticationData() {
499  return [
500  [ 'UTSysop', AuthenticationRequest::class, false ],
503  ];
504  }
505 
507  $user = self::getMutableTestUser()->getUser();
508 
509  $dbw = wfGetDB( DB_MASTER );
510  $dbw->update(
511  'user',
512  [ 'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ],
513  [ 'user_id' => $user->getId() ]
514  );
515 
517  $req->username = $user->getName();
518  $req->mailpassword = true;
519 
520  $provider = $this->getProvider( [ 'emailEnabled' => false ] );
521  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
522  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-emaildisabled' ), $status );
523 
524  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 10 ] );
525  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
526  $this->assertEquals( \StatusValue::newFatal( 'throttled-mailpassword', 10 ), $status );
527 
528  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 3 ] );
529  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
530  $this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
531 
532  $dbw->update(
533  'user',
534  [ 'user_newpass_time' => $dbw->timestamp( time() + 5 * 3600 ) ],
535  [ 'user_id' => $user->getId() ]
536  );
537  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 0 ] );
538  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
539  $this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
540 
541  $req->caller = null;
542  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
543  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nocaller' ), $status );
544 
545  $req->caller = '127.0.0.256';
546  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
547  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nosuchcaller', '127.0.0.256' ),
548  $status );
549 
550  $req->caller = '<Invalid>';
551  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
552  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nosuchcaller', '<Invalid>' ),
553  $status );
554 
555  $req->caller = '127.0.0.1';
556  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
557  $this->assertEquals( \StatusValue::newGood(), $status );
558 
559  $req->caller = $user->getName();
560  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
561  $this->assertEquals( \StatusValue::newGood(), $status );
562 
563  $mailed = false;
564  $resetMailer = $this->hookMailer( function ( $headers, $to, $from, $subject, $body )
565  use ( &$mailed, $req, $user )
566  {
567  $mailed = true;
568  $this->assertSame( $user->getEmail(), $to[0]->address );
569  $this->assertContains( $req->password, $body );
570  return false;
571  } );
572  $provider->providerChangeAuthenticationData( $req );
573  ScopedCallback::consume( $resetMailer );
574  $this->assertTrue( $mailed );
575 
576  $priv = TestingAccessWrapper::newFromObject( $provider );
577  $req->username = '<invalid>';
578  $status = $priv->sendPasswordResetEmail( $req );
579  $this->assertEquals( \Status::newFatal( 'noname' ), $status );
580  }
581 
582  public function testTestForAccountCreation() {
583  $user = \User::newFromName( 'foo' );
585  $req->username = 'Foo';
586  $req->password = 'Bar';
588 
589  $provider = $this->getProvider();
590  $this->assertEquals(
592  $provider->testForAccountCreation( $user, $user, [] ),
593  'No password request'
594  );
595 
596  $this->assertEquals(
598  $provider->testForAccountCreation( $user, $user, $reqs ),
599  'Password request, validated'
600  );
601 
602  $this->validity->error( 'arbitrary warning' );
603  $expect = \StatusValue::newGood();
604  $expect->error( 'arbitrary warning' );
605  $this->assertEquals(
606  $expect,
607  $provider->testForAccountCreation( $user, $user, $reqs ),
608  'Password request, not validated'
609  );
610  }
611 
612  public function testAccountCreation() {
613  $resetMailer = $this->hookMailer();
614 
615  $user = \User::newFromName( 'Foo' );
616 
619 
620  $authreq = new PasswordAuthenticationRequest();
621  $authreq->action = AuthManager::ACTION_CREATE;
622  $authreqs = [ PasswordAuthenticationRequest::class => $authreq ];
623 
624  $provider = $this->getProvider();
625 
626  $this->assertEquals(
628  $provider->beginPrimaryAccountCreation( $user, $user, [] )
629  );
630 
631  $req->username = 'foo';
632  $req->password = null;
633  $this->assertEquals(
635  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
636  );
637 
638  $req->username = null;
639  $req->password = 'bar';
640  $this->assertEquals(
642  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
643  );
644 
645  $req->username = 'foo';
646  $req->password = 'bar';
647 
648  $expect = AuthenticationResponse::newPass( 'Foo' );
649  $expect->createRequest = clone $req;
650  $expect->createRequest->username = 'Foo';
651  $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) );
652  $this->assertNull( $this->manager->getAuthenticationSessionData( 'no-email' ) );
653 
654  $user = self::getMutableTestUser()->getUser();
655  $req->username = $authreq->username = $user->getName();
656  $req->password = $authreq->password = 'NewPassword';
657  $expect = AuthenticationResponse::newPass( $user->getName() );
658  $expect->createRequest = $req;
659 
660  $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
661  $this->assertEquals( $expect, $res2, 'Sanity check' );
662 
663  $ret = $provider->beginPrimaryAuthentication( $authreqs );
664  $this->assertEquals( AuthenticationResponse::FAIL, $ret->status, 'sanity check' );
665 
666  $this->assertSame( null, $provider->finishAccountCreation( $user, $user, $res2 ) );
667 
668  $ret = $provider->beginPrimaryAuthentication( $authreqs );
669  $this->assertEquals( AuthenticationResponse::PASS, $ret->status, 'new password is set' );
670  }
671 
672  public function testAccountCreationEmail() {
673  $creator = \User::newFromName( 'Foo' );
674 
675  $user = self::getMutableTestUser()->getUser();
676  $user->setEmail( null );
677 
679  $req->username = $user->getName();
680  $req->mailpassword = true;
681 
682  $provider = $this->getProvider( [ 'emailEnabled' => false ] );
683  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
684  $this->assertEquals( \StatusValue::newFatal( 'emaildisabled' ), $status );
685 
686  $provider = $this->getProvider( [ 'emailEnabled' => true ] );
687  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
688  $this->assertEquals( \StatusValue::newFatal( 'noemailcreate' ), $status );
689 
690  $user->setEmail( 'test@localhost.localdomain' );
691  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
692  $this->assertEquals( \StatusValue::newGood(), $status );
693 
694  $mailed = false;
695  $resetMailer = $this->hookMailer( function ( $headers, $to, $from, $subject, $body )
696  use ( &$mailed, $req )
697  {
698  $mailed = true;
699  $this->assertSame( 'test@localhost.localdomain', $to[0]->address );
700  $this->assertContains( $req->password, $body );
701  return false;
702  } );
703 
704  $expect = AuthenticationResponse::newPass( $user->getName() );
705  $expect->createRequest = clone $req;
706  $expect->createRequest->username = $user->getName();
707  $res = $provider->beginPrimaryAccountCreation( $user, $creator, [ $req ] );
708  $this->assertEquals( $expect, $res );
709  $this->assertTrue( $this->manager->getAuthenticationSessionData( 'no-email' ) );
710  $this->assertFalse( $mailed );
711 
712  $this->assertSame( 'byemail', $provider->finishAccountCreation( $user, $creator, $res ) );
713  $this->assertTrue( $mailed );
714 
715  ScopedCallback::consume( $resetMailer );
716  $this->assertTrue( $mailed );
717  }
718 
719 }
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideGetAuthenticationRequests
static provideGetAuthenticationRequests()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:203
$status
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1266
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_CREATE
const TYPE_CREATE
Provider can create accounts.
Definition: PrimaryAuthenticationProvider.php:77
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:42
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\getProvider
getProvider( $params=[])
Get an instance of the provider.
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:29
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAccountCreation
testAccountCreation()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:612
$req
this hook is for auditing only $req
Definition: hooks.txt:979
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$params
$params
Definition: styleTest.css.php:44
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation
testTestForAccountCreation()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:582
$res
$res
Definition: database.txt:21
Hooks\clear
static clear( $name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:63
php
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
Definition: injection.txt:35
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
MediaWiki\Auth\PasswordAuthenticationRequest
This is a value object for authentication requests with a username and password.
Definition: PasswordAuthenticationRequest.php:29
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest
AuthManager Database \MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider.
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:14
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testGetAuthenticationRequests
testGetAuthenticationRequests( $action, $options, $expected)
provideGetAuthenticationRequests
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:193
Status\wrap
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:55
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationData
testProviderChangeAuthenticationData( $user, $type, $changed)
provideProviderChangeAuthenticationData
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:411
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\$manager
$manager
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:16
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange
testProviderAllowsAuthenticationDataChange( $type, $user, \Status $validity, \StatusValue $expect1, \StatusValue $expect2)
provideProviderAllowsAuthenticationDataChange
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:360
MediaWiki\Auth\AuthenticationResponse\FAIL
const FAIL
Indicates that the authentication failed.
Definition: AuthenticationResponse.php:42
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\$config
$config
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:17
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:124
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
MediaWiki\Auth\AuthManager\ACTION_CREATE
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:91
Hooks\register
static register( $name, $callback)
Attach an event handler to a given hook.
Definition: Hooks.php:49
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testConfig
testConfig()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:103
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:192
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAuthentication
testAuthentication()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:235
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider
A primary authentication provider that uses the temporary password field in the 'user' table.
Definition: TemporaryPasswordPrimaryAuthenticationProvider.php:37
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:101
$ret
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
Definition: hooks.txt:1985
MediaWiki\Auth\AuthManager\ACTION_LINK
const ACTION_LINK
Link an existing user to a third-party account.
Definition: AuthManager.php:96
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\hookMailer
hookMailer( $func=null)
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:61
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:84
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderChangeAuthenticationData
static provideProviderChangeAuthenticationData()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:498
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testBasics
testBasics()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:84
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:103
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:48
PasswordFactory\newInvalidPassword
static newInvalidPassword()
Create an InvalidPassword.
Definition: PasswordFactory.php:241
$options
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 & $options
Definition: hooks.txt:1985
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAccountCreationEmail
testAccountCreationEmail()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:672
as
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
Definition: distributors.txt:9
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
This represents the intention to set a temporary password for the user.
Definition: TemporaryPasswordAuthenticationRequest.php:31
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:86
true
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
Definition: hooks.txt:1985
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange
static provideProviderAllowsAuthenticationDataChange()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:380
class
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
Definition: maintenance.txt:52
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
MediaWiki\Auth\AuthenticationResponse\PASS
const PASS
Indicates that the authentication succeeded.
Definition: AuthenticationResponse.php:39
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newRandom
static newRandom()
Return an instance with a new, random password.
Definition: TemporaryPasswordAuthenticationRequest.php:65
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\$validity
$validity
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:18
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testTestUserCanAuthenticate
testTestUserCanAuthenticate()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:127
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationDataEmail
testProviderChangeAuthenticationDataEmail()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:506
$type
$type
Definition: testCompression.php:48