MediaWiki  1.33.1
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  $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 
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', false );
340  $password = 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  $this->config->set( 'PasswordSalt', true );
349  $password = md5( "$id-" . md5( 'FooBar' ) );
350  $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
351  $req->password = 'FooBar';
352  $this->assertEquals(
353  AuthenticationResponse::newPass( $userName ),
354  $provider->beginPrimaryAuthentication( $reqs )
355  );
356  }
357 
367  \StatusValue $expect1, \StatusValue $expect2
368  ) {
370  $req = new $type();
372  $req = new $type( [] );
373  } else {
374  $req = $this->createMock( $type );
375  }
377  $req->username = $user;
378  $req->password = 'NewPassword';
379  $req->retype = 'NewPassword';
380 
381  $provider = $this->getProvider();
382  $this->validity = $validity;
383  $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange( $req, false ) );
384  $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange( $req, true ) );
385 
386  $req->retype = 'BadRetype';
387  $this->assertEquals(
388  $expect1,
389  $provider->providerAllowsAuthenticationDataChange( $req, false )
390  );
391  $this->assertEquals(
392  $expect2->getValue() === 'ignored' ? $expect2 : \StatusValue::newFatal( 'badretype' ),
393  $provider->providerAllowsAuthenticationDataChange( $req, true )
394  );
395 
396  $provider = $this->getProvider( true );
397  $this->assertEquals(
398  \StatusValue::newGood( 'ignored' ),
399  $provider->providerAllowsAuthenticationDataChange( $req, true ),
400  'loginOnly mode should claim to ignore all changes'
401  );
402  }
403 
405  $err = \StatusValue::newGood();
406  $err->error( 'arbitrary-warning' );
407 
408  return [
410  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
416  \StatusValue::newGood(), $err ],
417  [ PasswordAuthenticationRequest::class, 'UTSysop', \Status::newFatal( 'arbitrary-error' ),
418  \StatusValue::newGood(), \StatusValue::newFatal( 'arbitrary-error' ) ],
422  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
423  ];
424  }
425 
434  $usernameTransform, $type, $loginOnly, $changed ) {
435  $testUser = $this->getMutableTestUser();
436  $user = $testUser->getUser()->getName();
437  if ( is_callable( $usernameTransform ) ) {
438  $user = call_user_func( $usernameTransform, $user );
439  }
440  $cuser = ucfirst( $user );
441  $oldpass = $testUser->getPassword();
442  $newpass = 'NewPassword';
443 
444  $dbw = wfGetDB( DB_MASTER );
445  $oldExpiry = $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] );
446 
447  $this->mergeMwGlobalArrayValue( 'wgHooks', [
448  'ResetPasswordExpiration' => [ function ( $user, &$expires ) {
449  $expires = '30001231235959';
450  } ]
451  ] );
452 
453  $provider = $this->getProvider( $loginOnly );
454 
455  // Sanity check
456  $loginReq = new PasswordAuthenticationRequest();
457  $loginReq->action = AuthManager::ACTION_LOGIN;
458  $loginReq->username = $user;
459  $loginReq->password = $oldpass;
460  $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
461  $this->assertEquals(
463  $provider->beginPrimaryAuthentication( $loginReqs ),
464  'Sanity check'
465  );
466 
468  $changeReq = new $type();
469  } else {
470  $changeReq = $this->createMock( $type );
471  }
472  $changeReq->action = AuthManager::ACTION_CHANGE;
473  $changeReq->username = $user;
474  $changeReq->password = $newpass;
475  $provider->providerChangeAuthenticationData( $changeReq );
476 
477  if ( $loginOnly && $changed ) {
478  $old = 'fail';
479  $new = 'fail';
480  $expectExpiry = null;
481  } elseif ( $changed ) {
482  $old = 'fail';
483  $new = 'pass';
484  $expectExpiry = '30001231235959';
485  } else {
486  $old = 'pass';
487  $new = 'fail';
488  $expectExpiry = $oldExpiry;
489  }
490 
491  $loginReq->password = $oldpass;
492  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
493  if ( $old === 'pass' ) {
494  $this->assertEquals(
496  $ret,
497  'old password should pass'
498  );
499  } else {
500  $this->assertEquals(
502  $ret->status,
503  'old password should fail'
504  );
505  $this->assertEquals(
506  'wrongpassword',
507  $ret->message->getKey(),
508  'old password should fail'
509  );
510  }
511 
512  $loginReq->password = $newpass;
513  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
514  if ( $new === 'pass' ) {
515  $this->assertEquals(
517  $ret,
518  'new password should pass'
519  );
520  } else {
521  $this->assertEquals(
523  $ret->status,
524  'new password should fail'
525  );
526  $this->assertEquals(
527  'wrongpassword',
528  $ret->message->getKey(),
529  'new password should fail'
530  );
531  }
532 
533  $this->assertSame(
534  $expectExpiry,
536  TS_MW,
537  $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] )
538  )
539  );
540  }
541 
542  public static function provideProviderChangeAuthenticationData() {
543  return [
544  [ false, AuthenticationRequest::class, false, false ],
545  [ false, PasswordAuthenticationRequest::class, false, true ],
546  [ false, AuthenticationRequest::class, true, false ],
547  [ false, PasswordAuthenticationRequest::class, true, true ],
548  [ 'ucfirst', PasswordAuthenticationRequest::class, false, true ],
549  [ 'ucfirst', PasswordAuthenticationRequest::class, true, true ],
550  ];
551  }
552 
553  public function testTestForAccountCreation() {
554  $user = \User::newFromName( 'foo' );
557  $req->username = 'Foo';
558  $req->password = 'Bar';
559  $req->retype = 'Bar';
561 
562  $provider = $this->getProvider();
563  $this->assertEquals(
565  $provider->testForAccountCreation( $user, $user, [] ),
566  'No password request'
567  );
568 
569  $this->assertEquals(
571  $provider->testForAccountCreation( $user, $user, $reqs ),
572  'Password request, validated'
573  );
574 
575  $req->retype = 'Baz';
576  $this->assertEquals(
577  \StatusValue::newFatal( 'badretype' ),
578  $provider->testForAccountCreation( $user, $user, $reqs ),
579  'Password request, bad retype'
580  );
581  $req->retype = 'Bar';
582 
583  $this->validity->error( 'arbitrary warning' );
584  $expect = \StatusValue::newGood();
585  $expect->error( 'arbitrary warning' );
586  $this->assertEquals(
587  $expect,
588  $provider->testForAccountCreation( $user, $user, $reqs ),
589  'Password request, not validated'
590  );
591 
592  $provider = $this->getProvider( true );
593  $this->validity->error( 'arbitrary warning' );
594  $this->assertEquals(
596  $provider->testForAccountCreation( $user, $user, $reqs ),
597  'Password request, not validated, loginOnly'
598  );
599  }
600 
601  public function testAccountCreation() {
602  $user = \User::newFromName( 'Foo' );
603 
607 
608  $provider = $this->getProvider( true );
609  try {
610  $provider->beginPrimaryAccountCreation( $user, $user, [] );
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  try {
619  $provider->finishAccountCreation( $user, $user, AuthenticationResponse::newPass() );
620  $this->fail( 'Expected exception was not thrown' );
621  } catch ( \BadMethodCallException $ex ) {
622  $this->assertSame(
623  'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
624  );
625  }
626 
627  $provider = $this->getProvider( false );
628 
629  $this->assertEquals(
631  $provider->beginPrimaryAccountCreation( $user, $user, [] )
632  );
633 
634  $req->username = 'foo';
635  $req->password = null;
636  $this->assertEquals(
638  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
639  );
640 
641  $req->username = null;
642  $req->password = 'bar';
643  $this->assertEquals(
645  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
646  );
647 
648  $req->username = 'foo';
649  $req->password = 'bar';
650 
651  $expect = AuthenticationResponse::newPass( 'Foo' );
652  $expect->createRequest = clone $req;
653  $expect->createRequest->username = 'Foo';
654  $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) );
655 
656  // We have to cheat a bit to avoid having to add a new user to
657  // the database to test the actual setting of the password works right
658  $dbw = wfGetDB( DB_MASTER );
659 
660  $user = \User::newFromName( 'UTSysop' );
661  $req->username = $user->getName();
662  $req->password = 'NewPassword';
663  $expect = AuthenticationResponse::newPass( 'UTSysop' );
664  $expect->createRequest = $req;
665 
666  $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
667  $this->assertEquals( $expect, $res2, 'Sanity check' );
668 
669  $ret = $provider->beginPrimaryAuthentication( $reqs );
670  $this->assertEquals( AuthenticationResponse::FAIL, $ret->status, 'sanity check' );
671 
672  $this->assertNull( $provider->finishAccountCreation( $user, $user, $res2 ) );
673  $ret = $provider->beginPrimaryAuthentication( $reqs );
674  $this->assertEquals( AuthenticationResponse::PASS, $ret->status, 'new password is set' );
675  }
676 }
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\$manager
$manager
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:15
$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
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange
testProviderAllowsAuthenticationDataChange( $type, $user, \Status $validity, \StatusValue $expect1, \StatusValue $expect2)
provideProviderAllowsAuthenticationDataChange
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:366
$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
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testAccountCreation
testAccountCreation()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:601
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:904
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation
testTestForAccountCreation()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:553
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:1912
$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
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
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:2636
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:709
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testBasics
testBasics()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:57
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
Definition: GlobalFunctions.php:1928
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
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: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
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:192
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderChangeAuthenticationData
static provideProviderChangeAuthenticationData()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:542
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:1993
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:84
PasswordFactory\newInvalidPassword
static newInvalidPassword()
Create an InvalidPassword.
Definition: PasswordFactory.php:241
User\idFromName
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:905
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:1993
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testAuthentication
testAuthentication()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:197
MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange
static provideProviderAllowsAuthenticationDataChange()
Definition: LocalPasswordPrimaryAuthenticationProviderTest.php:404
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:433
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