MediaWiki  1.30.0
LocalPasswordPrimaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
6 use Wikimedia\TestingAccessWrapper;
7 
14 
15  private $manager = null;
16  private $config = null;
17  private $validity = null;
18 
28  protected function getProvider( $loginOnly = false ) {
29  if ( !$this->config ) {
30  $this->config = new \HashConfig();
31  }
32  $config = new \MultiConfig( [
33  $this->config,
34  MediaWikiServices::getInstance()->getMainConfig()
35  ] );
36 
37  if ( !$this->manager ) {
38  $this->manager = new AuthManager( new \FauxRequest(), $config );
39  }
40  $this->validity = \Status::newGood();
41 
42  $provider = $this->getMockBuilder( LocalPasswordPrimaryAuthenticationProvider::class )
43  ->setMethods( [ 'checkPasswordValidity' ] )
44  ->setConstructorArgs( [ [ 'loginOnly' => $loginOnly ] ] )
45  ->getMock();
46  $provider->expects( $this->any() )->method( 'checkPasswordValidity' )
47  ->will( $this->returnCallback( function () {
48  return $this->validity;
49  } ) );
50  $provider->setConfig( $config );
51  $provider->setLogger( new \Psr\Log\NullLogger() );
52  $provider->setManager( $this->manager );
53 
54  return $provider;
55  }
56 
57  public function testBasics() {
58  $user = $this->getMutableTestUser()->getUser();
59  $userName = $user->getName();
60  $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
61 
63 
64  $this->assertSame(
66  $provider->accountCreationType()
67  );
68 
69  $this->assertTrue( $provider->testUserExists( $userName ) );
70  $this->assertTrue( $provider->testUserExists( $lowerInitialUserName ) );
71  $this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
72  $this->assertFalse( $provider->testUserExists( '<invalid>' ) );
73 
74  $provider = new LocalPasswordPrimaryAuthenticationProvider( [ 'loginOnly' => true ] );
75 
76  $this->assertSame(
78  $provider->accountCreationType()
79  );
80 
81  $this->assertTrue( $provider->testUserExists( $userName ) );
82  $this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
83 
86  $req->username = '<invalid>';
87  $provider->providerChangeAuthenticationData( $req );
88  }
89 
90  public function testTestUserCanAuthenticate() {
91  $user = $this->getMutableTestUser()->getUser();
92  $userName = $user->getName();
93  $dbw = wfGetDB( DB_MASTER );
94 
95  $provider = $this->getProvider();
96 
97  $this->assertFalse( $provider->testUserCanAuthenticate( '<invalid>' ) );
98 
99  $this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) );
100 
101  $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
102  $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
103  $this->assertTrue( $provider->testUserCanAuthenticate( $lowerInitialUserName ) );
104 
105  $dbw->update(
106  'user',
107  [ 'user_password' => \PasswordFactory::newInvalidPassword()->toString() ],
108  [ 'user_name' => $userName ]
109  );
110  $this->assertFalse( $provider->testUserCanAuthenticate( $userName ) );
111 
112  // Really old format
113  $dbw->update(
114  'user',
115  [ 'user_password' => '0123456789abcdef0123456789abcdef' ],
116  [ 'user_name' => $userName ]
117  );
118  $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
119  }
120 
121  public function testSetPasswordResetFlag() {
122  // Set instance vars
123  $this->getProvider();
124 
126  $this->setMwGlobals( [ 'wgPasswordExpireGrace' => 100 ] );
127 
128  $this->config->set( 'PasswordExpireGrace', 100 );
129  $this->config->set( 'InvalidPasswordReset', true );
130 
132  $provider->setConfig( $this->config );
133  $provider->setLogger( new \Psr\Log\NullLogger() );
134  $provider->setManager( $this->manager );
135  $providerPriv = TestingAccessWrapper::newFromObject( $provider );
136 
137  $user = $this->getMutableTestUser()->getUser();
138  $userName = $user->getName();
139  $dbw = wfGetDB( DB_MASTER );
140  $row = $dbw->selectRow(
141  'user',
142  '*',
143  [ 'user_name' => $userName ],
144  __METHOD__
145  );
146 
147  $this->manager->removeAuthenticationSessionData( null );
148  $row->user_password_expires = wfTimestamp( TS_MW, time() + 200 );
149  $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
150  $this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
151 
152  $this->manager->removeAuthenticationSessionData( null );
153  $row->user_password_expires = wfTimestamp( TS_MW, time() - 200 );
154  $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
155  $ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
156  $this->assertNotNull( $ret );
157  $this->assertSame( 'resetpass-expired', $ret->msg->getKey() );
158  $this->assertTrue( $ret->hard );
159 
160  $this->manager->removeAuthenticationSessionData( null );
161  $row->user_password_expires = wfTimestamp( TS_MW, time() - 1 );
162  $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
163  $ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
164  $this->assertNotNull( $ret );
165  $this->assertSame( 'resetpass-expired-soft', $ret->msg->getKey() );
166  $this->assertFalse( $ret->hard );
167 
168  $this->manager->removeAuthenticationSessionData( null );
169  $row->user_password_expires = null;
171  $status->error( 'testing' );
172  $providerPriv->setPasswordResetFlag( $userName, $status, $row );
173  $ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
174  $this->assertNotNull( $ret );
175  $this->assertSame( 'resetpass-validity-soft', $ret->msg->getKey() );
176  $this->assertFalse( $ret->hard );
177  }
178 
179  public function testAuthentication() {
180  $testUser = $this->getMutableTestUser();
181  $userName = $testUser->getUser()->getName();
182 
183  $dbw = wfGetDB( DB_MASTER );
184  $id = \User::idFromName( $userName );
185 
189 
190  $provider = $this->getProvider();
191 
192  // General failures
193  $this->assertEquals(
195  $provider->beginPrimaryAuthentication( [] )
196  );
197 
198  $req->username = 'foo';
199  $req->password = null;
200  $this->assertEquals(
202  $provider->beginPrimaryAuthentication( $reqs )
203  );
204 
205  $req->username = null;
206  $req->password = 'bar';
207  $this->assertEquals(
209  $provider->beginPrimaryAuthentication( $reqs )
210  );
211 
212  $req->username = '<invalid>';
213  $req->password = 'WhoCares';
214  $ret = $provider->beginPrimaryAuthentication( $reqs );
215  $this->assertEquals(
217  $provider->beginPrimaryAuthentication( $reqs )
218  );
219 
220  $req->username = 'DoesNotExist';
221  $req->password = 'DoesNotExist';
222  $ret = $provider->beginPrimaryAuthentication( $reqs );
223  $this->assertEquals(
225  $ret->status
226  );
227  $this->assertEquals(
228  'wrongpassword',
229  $ret->message->getKey()
230  );
231 
232  // Validation failure
233  $req->username = $userName;
234  $req->password = $testUser->getPassword();
235  $this->validity = \Status::newFatal( 'arbitrary-failure' );
236  $ret = $provider->beginPrimaryAuthentication( $reqs );
237  $this->assertEquals(
239  $ret->status
240  );
241  $this->assertEquals(
242  'arbitrary-failure',
243  $ret->message->getKey()
244  );
245 
246  // Successful auth
247  $this->manager->removeAuthenticationSessionData( null );
248  $this->validity = \Status::newGood();
249  $this->assertEquals(
250  AuthenticationResponse::newPass( $userName ),
251  $provider->beginPrimaryAuthentication( $reqs )
252  );
253  $this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
254 
255  // Successful auth after normalizing name
256  $this->manager->removeAuthenticationSessionData( null );
257  $this->validity = \Status::newGood();
258  $req->username = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
259  $this->assertEquals(
260  AuthenticationResponse::newPass( $userName ),
261  $provider->beginPrimaryAuthentication( $reqs )
262  );
263  $this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
264  $req->username = $userName;
265 
266  // Successful auth with reset
267  $this->manager->removeAuthenticationSessionData( null );
268  $this->validity->error( 'arbitrary-warning' );
269  $this->assertEquals(
270  AuthenticationResponse::newPass( $userName ),
271  $provider->beginPrimaryAuthentication( $reqs )
272  );
273  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
274 
275  // Wrong password
276  $this->validity = \Status::newGood();
277  $req->password = 'Wrong';
278  $ret = $provider->beginPrimaryAuthentication( $reqs );
279  $this->assertEquals(
281  $ret->status
282  );
283  $this->assertEquals(
284  'wrongpassword',
285  $ret->message->getKey()
286  );
287 
288  // Correct handling of legacy encodings
289  $password = ':B:salt:' . md5( 'salt-' . md5( "\xe1\xe9\xed\xf3\xfa" ) );
290  $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
291  $req->password = 'áéíóú';
292  $ret = $provider->beginPrimaryAuthentication( $reqs );
293  $this->assertEquals(
295  $ret->status
296  );
297  $this->assertEquals(
298  'wrongpassword',
299  $ret->message->getKey()
300  );
301 
302  $this->config->set( 'LegacyEncoding', true );
303  $this->assertEquals(
304  AuthenticationResponse::newPass( $userName ),
305  $provider->beginPrimaryAuthentication( $reqs )
306  );
307 
308  $req->password = 'áéíóú Wrong';
309  $ret = $provider->beginPrimaryAuthentication( $reqs );
310  $this->assertEquals(
312  $ret->status
313  );
314  $this->assertEquals(
315  'wrongpassword',
316  $ret->message->getKey()
317  );
318 
319  // Correct handling of really old password hashes
320  $this->config->set( 'PasswordSalt', false );
321  $password = md5( 'FooBar' );
322  $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
323  $req->password = 'FooBar';
324  $this->assertEquals(
325  AuthenticationResponse::newPass( $userName ),
326  $provider->beginPrimaryAuthentication( $reqs )
327  );
328 
329  $this->config->set( 'PasswordSalt', true );
330  $password = md5( "$id-" . md5( 'FooBar' ) );
331  $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
332  $req->password = 'FooBar';
333  $this->assertEquals(
334  AuthenticationResponse::newPass( $userName ),
335  $provider->beginPrimaryAuthentication( $reqs )
336  );
337  }
338 
348  \StatusValue $expect1, \StatusValue $expect2
349  ) {
351  $req = new $type();
353  $req = new $type( [] );
354  } else {
355  $req = $this->createMock( $type );
356  }
358  $req->username = $user;
359  $req->password = 'NewPassword';
360  $req->retype = 'NewPassword';
361 
362  $provider = $this->getProvider();
363  $this->validity = $validity;
364  $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange( $req, false ) );
365  $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange( $req, true ) );
366 
367  $req->retype = 'BadRetype';
368  $this->assertEquals(
369  $expect1,
370  $provider->providerAllowsAuthenticationDataChange( $req, false )
371  );
372  $this->assertEquals(
373  $expect2->getValue() === 'ignored' ? $expect2 : \StatusValue::newFatal( 'badretype' ),
374  $provider->providerAllowsAuthenticationDataChange( $req, true )
375  );
376 
377  $provider = $this->getProvider( true );
378  $this->assertEquals(
379  \StatusValue::newGood( 'ignored' ),
380  $provider->providerAllowsAuthenticationDataChange( $req, true ),
381  'loginOnly mode should claim to ignore all changes'
382  );
383  }
384 
386  $err = \StatusValue::newGood();
387  $err->error( 'arbitrary-warning' );
388 
389  return [
391  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
397  \StatusValue::newGood(), $err ],
398  [ PasswordAuthenticationRequest::class, 'UTSysop', \Status::newFatal( 'arbitrary-error' ),
399  \StatusValue::newGood(), \StatusValue::newFatal( 'arbitrary-error' ) ],
403  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
404  ];
405  }
406 
415  $usernameTransform, $type, $loginOnly, $changed ) {
416  $testUser = $this->getMutableTestUser();
417  $user = $testUser->getUser()->getName();
418  if ( is_callable( $usernameTransform ) ) {
419  $user = call_user_func( $usernameTransform, $user );
420  }
421  $cuser = ucfirst( $user );
422  $oldpass = $testUser->getPassword();
423  $newpass = 'NewPassword';
424 
425  $dbw = wfGetDB( DB_MASTER );
426  $oldExpiry = $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] );
427 
428  $this->mergeMwGlobalArrayValue( 'wgHooks', [
429  'ResetPasswordExpiration' => [ function ( $user, &$expires ) {
430  $expires = '30001231235959';
431  } ]
432  ] );
433 
434  $provider = $this->getProvider( $loginOnly );
435 
436  // Sanity check
437  $loginReq = new PasswordAuthenticationRequest();
438  $loginReq->action = AuthManager::ACTION_LOGIN;
439  $loginReq->username = $user;
440  $loginReq->password = $oldpass;
441  $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
442  $this->assertEquals(
444  $provider->beginPrimaryAuthentication( $loginReqs ),
445  'Sanity check'
446  );
447 
449  $changeReq = new $type();
450  } else {
451  $changeReq = $this->createMock( $type );
452  }
453  $changeReq->action = AuthManager::ACTION_CHANGE;
454  $changeReq->username = $user;
455  $changeReq->password = $newpass;
456  $provider->providerChangeAuthenticationData( $changeReq );
457 
458  if ( $loginOnly && $changed ) {
459  $old = 'fail';
460  $new = 'fail';
461  $expectExpiry = null;
462  } elseif ( $changed ) {
463  $old = 'fail';
464  $new = 'pass';
465  $expectExpiry = '30001231235959';
466  } else {
467  $old = 'pass';
468  $new = 'fail';
469  $expectExpiry = $oldExpiry;
470  }
471 
472  $loginReq->password = $oldpass;
473  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
474  if ( $old === 'pass' ) {
475  $this->assertEquals(
477  $ret,
478  'old password should pass'
479  );
480  } else {
481  $this->assertEquals(
483  $ret->status,
484  'old password should fail'
485  );
486  $this->assertEquals(
487  'wrongpassword',
488  $ret->message->getKey(),
489  'old password should fail'
490  );
491  }
492 
493  $loginReq->password = $newpass;
494  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
495  if ( $new === 'pass' ) {
496  $this->assertEquals(
498  $ret,
499  'new password should pass'
500  );
501  } else {
502  $this->assertEquals(
504  $ret->status,
505  'new password should fail'
506  );
507  $this->assertEquals(
508  'wrongpassword',
509  $ret->message->getKey(),
510  'new password should fail'
511  );
512  }
513 
514  $this->assertSame(
515  $expectExpiry,
517  TS_MW,
518  $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] )
519  )
520  );
521  }
522 
523  public static function provideProviderChangeAuthenticationData() {
524  return [
525  [ false, AuthenticationRequest::class, false, false ],
526  [ false, PasswordAuthenticationRequest::class, false, true ],
527  [ false, AuthenticationRequest::class, true, false ],
528  [ false, PasswordAuthenticationRequest::class, true, true ],
529  [ 'ucfirst', PasswordAuthenticationRequest::class, false, true ],
530  [ 'ucfirst', PasswordAuthenticationRequest::class, true, true ],
531  ];
532  }
533 
534  public function testTestForAccountCreation() {
535  $user = \User::newFromName( 'foo' );
538  $req->username = 'Foo';
539  $req->password = 'Bar';
540  $req->retype = 'Bar';
542 
543  $provider = $this->getProvider();
544  $this->assertEquals(
546  $provider->testForAccountCreation( $user, $user, [] ),
547  'No password request'
548  );
549 
550  $this->assertEquals(
552  $provider->testForAccountCreation( $user, $user, $reqs ),
553  'Password request, validated'
554  );
555 
556  $req->retype = 'Baz';
557  $this->assertEquals(
558  \StatusValue::newFatal( 'badretype' ),
559  $provider->testForAccountCreation( $user, $user, $reqs ),
560  'Password request, bad retype'
561  );
562  $req->retype = 'Bar';
563 
564  $this->validity->error( 'arbitrary warning' );
565  $expect = \StatusValue::newGood();
566  $expect->error( 'arbitrary warning' );
567  $this->assertEquals(
568  $expect,
569  $provider->testForAccountCreation( $user, $user, $reqs ),
570  'Password request, not validated'
571  );
572 
573  $provider = $this->getProvider( true );
574  $this->validity->error( 'arbitrary warning' );
575  $this->assertEquals(
577  $provider->testForAccountCreation( $user, $user, $reqs ),
578  'Password request, not validated, loginOnly'
579  );
580  }
581 
582  public function testAccountCreation() {
583  $user = \User::newFromName( 'Foo' );
584 
588 
589  $provider = $this->getProvider( true );
590  try {
591  $provider->beginPrimaryAccountCreation( $user, $user, [] );
592  $this->fail( 'Expected exception was not thrown' );
593  } catch ( \BadMethodCallException $ex ) {
594  $this->assertSame(
595  'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
596  );
597  }
598 
599  try {
600  $provider->finishAccountCreation( $user, $user, AuthenticationResponse::newPass() );
601  $this->fail( 'Expected exception was not thrown' );
602  } catch ( \BadMethodCallException $ex ) {
603  $this->assertSame(
604  'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
605  );
606  }
607 
608  $provider = $this->getProvider( false );
609 
610  $this->assertEquals(
612  $provider->beginPrimaryAccountCreation( $user, $user, [] )
613  );
614 
615  $req->username = 'foo';
616  $req->password = null;
617  $this->assertEquals(
619  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
620  );
621 
622  $req->username = null;
623  $req->password = 'bar';
624  $this->assertEquals(
626  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
627  );
628 
629  $req->username = 'foo';
630  $req->password = 'bar';
631 
632  $expect = AuthenticationResponse::newPass( 'Foo' );
633  $expect->createRequest = clone $req;
634  $expect->createRequest->username = 'Foo';
635  $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) );
636 
637  // We have to cheat a bit to avoid having to add a new user to
638  // the database to test the actual setting of the password works right
639  $dbw = wfGetDB( DB_MASTER );
640 
641  $user = \User::newFromName( 'UTSysop' );
642  $req->username = $user->getName();
643  $req->password = 'NewPassword';
644  $expect = AuthenticationResponse::newPass( 'UTSysop' );
645  $expect->createRequest = $req;
646 
647  $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
648  $this->assertEquals( $expect, $res2, 'Sanity check' );
649 
650  $ret = $provider->beginPrimaryAuthentication( $reqs );
651  $this->assertEquals( AuthenticationResponse::FAIL, $ret->status, 'sanity check' );
652 
653  $this->assertNull( $provider->finishAccountCreation( $user, $user, $res2 ) );
654  $ret = $provider->beginPrimaryAuthentication( $reqs );
655  $this->assertEquals( AuthenticationResponse::PASS, $ret->status, 'new password is set' );
656  }
657 
658 }
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\$manager
$manager
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:15
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange
testProviderAllowsAuthenticationDataChange( $type, $user, \Status $validity, \StatusValue $expect1, \StatusValue $expect2)
provideProviderAllowsAuthenticationDataChange
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:347
$user
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 account $user
Definition: hooks.txt:244
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
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testAccountCreation
testAccountCreation()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:582
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:42
MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_NONE
const TYPE_NONE
Provider cannot create or link to accounts.
Definition: PrimaryAuthenticationProvider.php:81
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:807
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation
testTestForAccountCreation()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:534
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\$validity
$validity
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:17
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
$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. '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). '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:1245
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
$req
this hook is for auditing only $req
Definition: hooks.txt:988
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:550
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testTestUserCanAuthenticate
testTestUserCanAuthenticate()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:90
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
StatusValue\getValue
getValue()
Definition: StatusValue.php:137
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\LocalPasswordPrimaryAuthenticationProvider
A primary authentication provider that uses the password field in the 'user' table.
Definition: LocalPasswordPrimaryAuthenticationProvider.php:31
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:2856
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testBasics
testBasics()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:57
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
Definition: GlobalFunctions.php:2056
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWiki\Auth\AuthenticationResponse\FAIL
const FAIL
Indicates that the authentication failed.
Definition: AuthenticationResponse.php:42
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:99
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:89
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\getProvider
getProvider( $loginOnly=false)
Get an instance of the provider.
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:28
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:160
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderChangeAuthenticationData
static provideProviderChangeAuthenticationData()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:523
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:99
$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:1965
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testSetPasswordResetFlag
testSetPasswordResetFlag()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:121
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:82
PasswordFactory\newInvalidPassword
static newInvalidPassword()
Create an InvalidPassword.
Definition: PasswordFactory.php:214
User\idFromName
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:765
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:84
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:1965
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testAuthentication
testAuthentication()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:179
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange
static provideProviderAllowsAuthenticationDataChange()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:385
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\LocalPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationData
testProviderChangeAuthenticationData( $usernameTransform, $type, $loginOnly, $changed)
provideProviderChangeAuthenticationData
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:414
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\$config
$config
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:16
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest
AuthManager Database MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider.
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:13
$type
$type
Definition: testCompression.php:48