MediaWiki  master
LocalPasswordPrimaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
7 
13 class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
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  $provider = $this->getMockBuilder( LocalPasswordPrimaryAuthenticationProvider::class )
42  ->setMethods( [ 'checkPasswordValidity' ] )
43  ->setConstructorArgs( [ [ 'loginOnly' => $loginOnly ] ] )
44  ->getMock();
45 
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 
85  $req->action = AuthManager::ACTION_CHANGE;
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;
170  $status = \Status::newGood( [ 'suggestChangeOnLogin' => true ] );
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  $this->manager->removeAuthenticationSessionData( null );
179  $row->user_password_expires = null;
180  $status = \Status::newGood( [ 'forceChange' => true ] );
181  $status->error( 'testing' );
182  $providerPriv->setPasswordResetFlag( $userName, $status, $row );
183  $ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
184  $this->assertNotNull( $ret );
185  $this->assertSame( 'resetpass-validity', $ret->msg->getKey() );
186  $this->assertTrue( $ret->hard );
187 
188  $this->manager->removeAuthenticationSessionData( null );
189  $row->user_password_expires = null;
190  $status = \Status::newGood( [ 'suggestChangeOnLogin' => false, ] );
191  $status->error( 'testing' );
192  $providerPriv->setPasswordResetFlag( $userName, $status, $row );
193  $ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
194  $this->assertNull( $ret );
195  }
196 
197  public function testAuthentication() {
198  $testUser = $this->getMutableTestUser();
199  $userName = $testUser->getUser()->getName();
200 
201  $dbw = wfGetDB( DB_MASTER );
202  $id = \User::idFromName( $userName );
203 
207 
208  $provider = $this->getProvider();
209 
210  // General failures
211  $this->assertEquals(
213  $provider->beginPrimaryAuthentication( [] )
214  );
215 
216  $req->username = 'foo';
217  $req->password = null;
218  $this->assertEquals(
220  $provider->beginPrimaryAuthentication( $reqs )
221  );
222 
223  $req->username = null;
224  $req->password = 'bar';
225  $this->assertEquals(
227  $provider->beginPrimaryAuthentication( $reqs )
228  );
229 
230  $req->username = '<invalid>';
231  $req->password = 'WhoCares';
232  $ret = $provider->beginPrimaryAuthentication( $reqs );
233  $this->assertEquals(
235  $provider->beginPrimaryAuthentication( $reqs )
236  );
237 
238  $req->username = 'DoesNotExist';
239  $req->password = 'DoesNotExist';
240  $ret = $provider->beginPrimaryAuthentication( $reqs );
241  $this->assertEquals(
243  $ret->status
244  );
245  $this->assertEquals(
246  'wrongpassword',
247  $ret->message->getKey()
248  );
249 
250  // Validation failure
251  $req->username = $userName;
252  $req->password = $testUser->getPassword();
253  $this->validity = \Status::newFatal( 'arbitrary-failure' );
254  $ret = $provider->beginPrimaryAuthentication( $reqs );
255  $this->assertEquals(
257  $ret->status
258  );
259  $this->assertEquals(
260  'arbitrary-failure',
261  $ret->message->getKey()
262  );
263 
264  // Successful auth
265  $this->manager->removeAuthenticationSessionData( null );
266  $this->validity = \Status::newGood();
267  $this->assertEquals(
268  AuthenticationResponse::newPass( $userName ),
269  $provider->beginPrimaryAuthentication( $reqs )
270  );
271  $this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
272 
273  // Successful auth after normalizing name
274  $this->manager->removeAuthenticationSessionData( null );
275  $this->validity = \Status::newGood();
276  $req->username = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
277  $this->assertEquals(
278  AuthenticationResponse::newPass( $userName ),
279  $provider->beginPrimaryAuthentication( $reqs )
280  );
281  $this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
282  $req->username = $userName;
283 
284  // Successful auth with reset
285  $this->manager->removeAuthenticationSessionData( null );
286  $this->validity = \Status::newGood( [ 'suggestChangeOnLogin' => true ] );
287  $this->validity->error( 'arbitrary-warning' );
288  $this->assertEquals(
289  AuthenticationResponse::newPass( $userName ),
290  $provider->beginPrimaryAuthentication( $reqs )
291  );
292  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
293 
294  // Wrong password
295  $this->validity = \Status::newGood();
296  $req->password = 'Wrong';
297  $ret = $provider->beginPrimaryAuthentication( $reqs );
298  $this->assertEquals(
300  $ret->status
301  );
302  $this->assertEquals(
303  'wrongpassword',
304  $ret->message->getKey()
305  );
306 
307  // Correct handling of legacy encodings
308  $password = ':B:salt:' . md5( 'salt-' . md5( "\xe1\xe9\xed\xf3\xfa" ) );
309  $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
310  $req->password = 'áéíóú';
311  $ret = $provider->beginPrimaryAuthentication( $reqs );
312  $this->assertEquals(
314  $ret->status
315  );
316  $this->assertEquals(
317  'wrongpassword',
318  $ret->message->getKey()
319  );
320 
321  $this->config->set( 'LegacyEncoding', true );
322  $this->assertEquals(
323  AuthenticationResponse::newPass( $userName ),
324  $provider->beginPrimaryAuthentication( $reqs )
325  );
326 
327  $req->password = 'áéíóú Wrong';
328  $ret = $provider->beginPrimaryAuthentication( $reqs );
329  $this->assertEquals(
331  $ret->status
332  );
333  $this->assertEquals(
334  'wrongpassword',
335  $ret->message->getKey()
336  );
337 
338  // Correct handling of really old password hashes
339  $this->config->set( 'PasswordSalt', true );
340  $password = md5( "$id-" . md5( 'FooBar' ) );
341  $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
342  $req->password = 'FooBar';
343  $this->assertEquals(
344  AuthenticationResponse::newPass( $userName ),
345  $provider->beginPrimaryAuthentication( $reqs )
346  );
347  }
348 
358  \StatusValue $expect1, \StatusValue $expect2
359  ) {
361  $req = new $type();
363  $req = new $type( [] );
364  } else {
365  $req = $this->createMock( $type );
366  }
368  $req->username = $user;
369  $req->password = 'NewPassword';
370  $req->retype = 'NewPassword';
371 
372  $provider = $this->getProvider();
373  $this->validity = $validity;
374  $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange( $req, false ) );
375  $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange( $req, true ) );
376 
377  $req->retype = 'BadRetype';
378  $this->assertEquals(
379  $expect1,
380  $provider->providerAllowsAuthenticationDataChange( $req, false )
381  );
382  $this->assertEquals(
383  $expect2->getValue() === 'ignored' ? $expect2 : \StatusValue::newFatal( 'badretype' ),
384  $provider->providerAllowsAuthenticationDataChange( $req, true )
385  );
386 
387  $provider = $this->getProvider( true );
388  $this->assertEquals(
389  \StatusValue::newGood( 'ignored' ),
390  $provider->providerAllowsAuthenticationDataChange( $req, true ),
391  'loginOnly mode should claim to ignore all changes'
392  );
393  }
394 
396  $err = \StatusValue::newGood();
397  $err->error( 'arbitrary-warning' );
398 
399  return [
401  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
407  \StatusValue::newGood(), $err ],
408  [ PasswordAuthenticationRequest::class, 'UTSysop', \Status::newFatal( 'arbitrary-error' ),
409  \StatusValue::newGood(), \StatusValue::newFatal( 'arbitrary-error' ) ],
413  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
414  ];
415  }
416 
425  $usernameTransform, $type, $loginOnly, $changed ) {
426  $testUser = $this->getMutableTestUser();
427  $user = $testUser->getUser()->getName();
428  if ( is_callable( $usernameTransform ) ) {
429  $user = call_user_func( $usernameTransform, $user );
430  }
431  $cuser = ucfirst( $user );
432  $oldpass = $testUser->getPassword();
433  $newpass = 'NewPassword';
434 
435  $dbw = wfGetDB( DB_MASTER );
436  $oldExpiry = $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] );
437 
438  $this->mergeMwGlobalArrayValue( 'wgHooks', [
439  'ResetPasswordExpiration' => [ function ( $user, &$expires ) {
440  $expires = '30001231235959';
441  } ]
442  ] );
443 
444  $provider = $this->getProvider( $loginOnly );
445 
446  // Sanity check
447  $loginReq = new PasswordAuthenticationRequest();
448  $loginReq->action = AuthManager::ACTION_LOGIN;
449  $loginReq->username = $user;
450  $loginReq->password = $oldpass;
451  $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
452  $this->assertEquals(
454  $provider->beginPrimaryAuthentication( $loginReqs ),
455  'Sanity check'
456  );
457 
459  $changeReq = new $type();
460  } else {
461  $changeReq = $this->createMock( $type );
462  }
463  $changeReq->action = AuthManager::ACTION_CHANGE;
464  $changeReq->username = $user;
465  $changeReq->password = $newpass;
466  $provider->providerChangeAuthenticationData( $changeReq );
467 
468  if ( $loginOnly && $changed ) {
469  $old = 'fail';
470  $new = 'fail';
471  $expectExpiry = null;
472  } elseif ( $changed ) {
473  $old = 'fail';
474  $new = 'pass';
475  $expectExpiry = '30001231235959';
476  } else {
477  $old = 'pass';
478  $new = 'fail';
479  $expectExpiry = $oldExpiry;
480  }
481 
482  $loginReq->password = $oldpass;
483  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
484  if ( $old === 'pass' ) {
485  $this->assertEquals(
487  $ret,
488  'old password should pass'
489  );
490  } else {
491  $this->assertEquals(
493  $ret->status,
494  'old password should fail'
495  );
496  $this->assertEquals(
497  'wrongpassword',
498  $ret->message->getKey(),
499  'old password should fail'
500  );
501  }
502 
503  $loginReq->password = $newpass;
504  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
505  if ( $new === 'pass' ) {
506  $this->assertEquals(
508  $ret,
509  'new password should pass'
510  );
511  } else {
512  $this->assertEquals(
514  $ret->status,
515  'new password should fail'
516  );
517  $this->assertEquals(
518  'wrongpassword',
519  $ret->message->getKey(),
520  'new password should fail'
521  );
522  }
523 
524  $this->assertSame(
525  $expectExpiry,
527  TS_MW,
528  $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] )
529  )
530  );
531  }
532 
533  public static function provideProviderChangeAuthenticationData() {
534  return [
535  [ false, AuthenticationRequest::class, false, false ],
536  [ false, PasswordAuthenticationRequest::class, false, true ],
537  [ false, AuthenticationRequest::class, true, false ],
538  [ false, PasswordAuthenticationRequest::class, true, true ],
539  [ 'ucfirst', PasswordAuthenticationRequest::class, false, true ],
540  [ 'ucfirst', PasswordAuthenticationRequest::class, true, true ],
541  ];
542  }
543 
544  public function testTestForAccountCreation() {
545  $user = \User::newFromName( 'foo' );
548  $req->username = 'Foo';
549  $req->password = 'Bar';
550  $req->retype = 'Bar';
552 
553  $provider = $this->getProvider();
554  $this->assertEquals(
556  $provider->testForAccountCreation( $user, $user, [] ),
557  'No password request'
558  );
559 
560  $this->assertEquals(
562  $provider->testForAccountCreation( $user, $user, $reqs ),
563  'Password request, validated'
564  );
565 
566  $req->retype = 'Baz';
567  $this->assertEquals(
568  \StatusValue::newFatal( 'badretype' ),
569  $provider->testForAccountCreation( $user, $user, $reqs ),
570  'Password request, bad retype'
571  );
572  $req->retype = 'Bar';
573 
574  $this->validity->error( 'arbitrary warning' );
575  $expect = \StatusValue::newGood();
576  $expect->error( 'arbitrary warning' );
577  $this->assertEquals(
578  $expect,
579  $provider->testForAccountCreation( $user, $user, $reqs ),
580  'Password request, not validated'
581  );
582 
583  $provider = $this->getProvider( true );
584  $this->validity->error( 'arbitrary warning' );
585  $this->assertEquals(
587  $provider->testForAccountCreation( $user, $user, $reqs ),
588  'Password request, not validated, loginOnly'
589  );
590  }
591 
592  public function testAccountCreation() {
593  $user = \User::newFromName( 'Foo' );
594 
598 
599  $provider = $this->getProvider( true );
600  try {
601  $provider->beginPrimaryAccountCreation( $user, $user, [] );
602  $this->fail( 'Expected exception was not thrown' );
603  } catch ( \BadMethodCallException $ex ) {
604  $this->assertSame(
605  'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
606  );
607  }
608 
609  try {
610  $provider->finishAccountCreation( $user, $user, AuthenticationResponse::newPass() );
611  $this->fail( 'Expected exception was not thrown' );
612  } catch ( \BadMethodCallException $ex ) {
613  $this->assertSame(
614  'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
615  );
616  }
617 
618  $provider = $this->getProvider( false );
619 
620  $this->assertEquals(
622  $provider->beginPrimaryAccountCreation( $user, $user, [] )
623  );
624 
625  $req->username = 'foo';
626  $req->password = null;
627  $this->assertEquals(
629  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
630  );
631 
632  $req->username = null;
633  $req->password = 'bar';
634  $this->assertEquals(
636  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
637  );
638 
639  $req->username = 'foo';
640  $req->password = 'bar';
641 
642  $expect = AuthenticationResponse::newPass( 'Foo' );
643  $expect->createRequest = clone $req;
644  $expect->createRequest->username = 'Foo';
645  $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) );
646 
647  // We have to cheat a bit to avoid having to add a new user to
648  // the database to test the actual setting of the password works right
649  $dbw = wfGetDB( DB_MASTER );
650 
651  $user = \User::newFromName( 'UTSysop' );
652  $req->username = $user->getName();
653  $req->password = 'NewPassword';
654  $expect = AuthenticationResponse::newPass( 'UTSysop' );
655  $expect->createRequest = $req;
656 
657  $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
658  $this->assertEquals( $expect, $res2, 'Sanity check' );
659 
660  $ret = $provider->beginPrimaryAuthentication( $reqs );
661  $this->assertEquals( AuthenticationResponse::FAIL, $ret->status, 'sanity check' );
662 
663  $this->assertNull( $provider->finishAccountCreation( $user, $user, $res2 ) );
664  $ret = $provider->beginPrimaryAuthentication( $reqs );
665  $this->assertEquals( AuthenticationResponse::PASS, $ret->status, 'new password is set' );
666  }
667 }
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:193
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:1983
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
A primary authentication provider that uses the password field in the &#39;user&#39; table.
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
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:864
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
static getInstance()
Returns the global default instance of the top level service locator.
const DB_MASTER
Definition: defines.php:26
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:1983
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
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 '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:1250
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const FAIL
Indicates that the authentication failed.
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
const ACTION_CHANGE
Change a user&#39;s credentials.
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:773
const PASS
Indicates that the authentication succeeded.
This serves as the entry point to the authentication system.
Definition: AuthManager.php:85
const TYPE_NONE
Provider cannot create or link to accounts.
static newInvalidPassword()
Create an InvalidPassword.
This is a value object for authentication requests with a username and password.
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:55
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
this hook is for auditing only $req
Definition: hooks.txt:966
testProviderChangeAuthenticationData( $usernameTransform, $type, $loginOnly, $changed)
provideProviderChangeAuthenticationData
AuthManager Database \MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider.
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
testProviderAllowsAuthenticationDataChange( $type, $user, \Status $validity, \StatusValue $expect1, \StatusValue $expect2)
provideProviderAllowsAuthenticationDataChange
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:93
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:535
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:87
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1460