MediaWiki  1.30.0
UserTest.php
Go to the documentation of this file.
1 <?php
2 
3 define( 'NS_UNITTEST', 5600 );
4 define( 'NS_UNITTEST_TALK', 5601 );
5 
7 use Wikimedia\TestingAccessWrapper;
8 
12 class UserTest extends MediaWikiTestCase {
16  protected $user;
17 
18  protected function setUp() {
19  parent::setUp();
20 
21  $this->setMwGlobals( [
22  'wgGroupPermissions' => [],
23  'wgRevokePermissions' => [],
24  ] );
25 
26  $this->setUpPermissionGlobals();
27 
28  $this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
29  }
30 
31  private function setUpPermissionGlobals() {
33 
34  # Data for regular $wgGroupPermissions test
35  $wgGroupPermissions['unittesters'] = [
36  'test' => true,
37  'runtest' => true,
38  'writetest' => false,
39  'nukeworld' => false,
40  ];
41  $wgGroupPermissions['testwriters'] = [
42  'test' => true,
43  'writetest' => true,
44  'modifytest' => true,
45  ];
46 
47  # Data for regular $wgRevokePermissions test
48  $wgRevokePermissions['formertesters'] = [
49  'runtest' => true,
50  ];
51 
52  # For the options test
53  $wgGroupPermissions['*'] = [
54  'editmyoptions' => true,
55  ];
56  }
57 
61  public function testGroupPermissions() {
62  $rights = User::getGroupPermissions( [ 'unittesters' ] );
63  $this->assertContains( 'runtest', $rights );
64  $this->assertNotContains( 'writetest', $rights );
65  $this->assertNotContains( 'modifytest', $rights );
66  $this->assertNotContains( 'nukeworld', $rights );
67 
68  $rights = User::getGroupPermissions( [ 'unittesters', 'testwriters' ] );
69  $this->assertContains( 'runtest', $rights );
70  $this->assertContains( 'writetest', $rights );
71  $this->assertContains( 'modifytest', $rights );
72  $this->assertNotContains( 'nukeworld', $rights );
73  }
74 
78  public function testRevokePermissions() {
79  $rights = User::getGroupPermissions( [ 'unittesters', 'formertesters' ] );
80  $this->assertNotContains( 'runtest', $rights );
81  $this->assertNotContains( 'writetest', $rights );
82  $this->assertNotContains( 'modifytest', $rights );
83  $this->assertNotContains( 'nukeworld', $rights );
84  }
85 
89  public function testUserPermissions() {
90  $rights = $this->user->getRights();
91  $this->assertContains( 'runtest', $rights );
92  $this->assertNotContains( 'writetest', $rights );
93  $this->assertNotContains( 'modifytest', $rights );
94  $this->assertNotContains( 'nukeworld', $rights );
95  }
96 
100  public function testUserGetRightsHooks() {
101  $user = $this->getTestUser( [ 'unittesters', 'testwriters' ] )->getUser();
102  $userWrapper = TestingAccessWrapper::newFromObject( $user );
103 
104  $rights = $user->getRights();
105  $this->assertContains( 'test', $rights, 'sanity check' );
106  $this->assertContains( 'runtest', $rights, 'sanity check' );
107  $this->assertContains( 'writetest', $rights, 'sanity check' );
108  $this->assertNotContains( 'nukeworld', $rights, 'sanity check' );
109 
110  // Add a hook manipluating the rights
111  $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserGetRights' => [ function ( $user, &$rights ) {
112  $rights[] = 'nukeworld';
113  $rights = array_diff( $rights, [ 'writetest' ] );
114  } ] ] );
115 
116  $userWrapper->mRights = null;
117  $rights = $user->getRights();
118  $this->assertContains( 'test', $rights );
119  $this->assertContains( 'runtest', $rights );
120  $this->assertNotContains( 'writetest', $rights );
121  $this->assertContains( 'nukeworld', $rights );
122 
123  // Add a Session that limits rights
124  $mock = $this->getMockBuilder( stdclass::class )
125  ->setMethods( [ 'getAllowedUserRights', 'deregisterSession', 'getSessionId' ] )
126  ->getMock();
127  $mock->method( 'getAllowedUserRights' )->willReturn( [ 'test', 'writetest' ] );
128  $mock->method( 'getSessionId' )->willReturn(
129  new MediaWiki\Session\SessionId( str_repeat( 'X', 32 ) )
130  );
132  $mockRequest = $this->getMockBuilder( FauxRequest::class )
133  ->setMethods( [ 'getSession' ] )
134  ->getMock();
135  $mockRequest->method( 'getSession' )->willReturn( $session );
136  $userWrapper->mRequest = $mockRequest;
137 
138  $userWrapper->mRights = null;
139  $rights = $user->getRights();
140  $this->assertContains( 'test', $rights );
141  $this->assertNotContains( 'runtest', $rights );
142  $this->assertNotContains( 'writetest', $rights );
143  $this->assertNotContains( 'nukeworld', $rights );
144  }
145 
150  public function testGetGroupsWithPermission( $expected, $right ) {
152  sort( $result );
153  sort( $expected );
154 
155  $this->assertEquals( $expected, $result, "Groups with permission $right" );
156  }
157 
158  public static function provideGetGroupsWithPermission() {
159  return [
160  [
161  [ 'unittesters', 'testwriters' ],
162  'test'
163  ],
164  [
165  [ 'unittesters' ],
166  'runtest'
167  ],
168  [
169  [ 'testwriters' ],
170  'writetest'
171  ],
172  [
173  [ 'testwriters' ],
174  'modifytest'
175  ],
176  ];
177  }
178 
183  public function testIsIP( $value, $result, $message ) {
184  $this->assertEquals( $this->user->isIP( $value ), $result, $message );
185  }
186 
187  public static function provideIPs() {
188  return [
189  [ '', false, 'Empty string' ],
190  [ ' ', false, 'Blank space' ],
191  [ '10.0.0.0', true, 'IPv4 private 10/8' ],
192  [ '10.255.255.255', true, 'IPv4 private 10/8' ],
193  [ '192.168.1.1', true, 'IPv4 private 192.168/16' ],
194  [ '203.0.113.0', true, 'IPv4 example' ],
195  [ '2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff', true, 'IPv6 example' ],
196  // Not valid IPs but classified as such by MediaWiki for negated asserting
197  // of whether this might be the identifier of a logged-out user or whether
198  // to allow usernames like it.
199  [ '300.300.300.300', true, 'Looks too much like an IPv4 address' ],
200  [ '203.0.113.xxx', true, 'Assigned by UseMod to cloaked logged-out users' ],
201  ];
202  }
203 
208  public function testIsValidUserName( $username, $result, $message ) {
209  $this->assertEquals( $this->user->isValidUserName( $username ), $result, $message );
210  }
211 
212  public static function provideUserNames() {
213  return [
214  [ '', false, 'Empty string' ],
215  [ ' ', false, 'Blank space' ],
216  [ 'abcd', false, 'Starts with small letter' ],
217  [ 'Ab/cd', false, 'Contains slash' ],
218  [ 'Ab cd', true, 'Whitespace' ],
219  [ '192.168.1.1', false, 'IP' ],
220  [ '116.17.184.5/32', false, 'IP range' ],
221  [ '::e:f:2001/96', false, 'IPv6 range' ],
222  [ 'User:Abcd', false, 'Reserved Namespace' ],
223  [ '12abcd232', true, 'Starts with Numbers' ],
224  [ '?abcd', true, 'Start with ? mark' ],
225  [ '#abcd', false, 'Start with #' ],
226  [ 'Abcdകഖഗഘ', true, ' Mixed scripts' ],
227  [ 'ജോസ്‌തോമസ്', false, 'ZWNJ- Format control character' ],
228  [ 'Ab cd', false, ' Ideographic space' ],
229  [ '300.300.300.300', false, 'Looks too much like an IPv4 address' ],
230  [ '302.113.311.900', false, 'Looks too much like an IPv4 address' ],
231  [ '203.0.113.xxx', false, 'Reserved for usage by UseMod for cloaked logged-out users' ],
232  ];
233  }
234 
240  public function testAllRightsWithMessage() {
241  // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
242  $allRights = User::getAllRights();
243  $allMessageKeys = Language::getMessageKeysFor( 'en' );
244 
245  $rightsWithMessage = [];
246  foreach ( $allMessageKeys as $message ) {
247  // === 0: must be at beginning of string (position 0)
248  if ( strpos( $message, 'right-' ) === 0 ) {
249  $rightsWithMessage[] = substr( $message, strlen( 'right-' ) );
250  }
251  }
252 
253  sort( $allRights );
254  sort( $rightsWithMessage );
255 
256  $this->assertEquals(
257  $allRights,
258  $rightsWithMessage,
259  'Each user rights (core/extensions) has a corresponding right- message.'
260  );
261  }
262 
268  public function testGetEditCount() {
269  $user = $this->getMutableTestUser()->getUser();
270 
271  // let the user have a few (3) edits
272  $page = WikiPage::factory( Title::newFromText( 'Help:UserTest_EditCount' ) );
273  for ( $i = 0; $i < 3; $i++ ) {
274  $page->doEditContent(
275  ContentHandler::makeContent( (string)$i, $page->getTitle() ),
276  'test',
277  0,
278  false,
279  $user
280  );
281  }
282 
283  $this->assertEquals(
284  3,
285  $user->getEditCount(),
286  'After three edits, the user edit count should be 3'
287  );
288 
289  // increase the edit count
290  $user->incEditCount();
291 
292  $this->assertEquals(
293  4,
294  $user->getEditCount(),
295  'After increasing the edit count manually, the user edit count should be 4'
296  );
297  }
298 
304  public function testGetEditCountForAnons() {
305  $user = User::newFromName( 'Anonymous' );
306 
307  $this->assertNull(
308  $user->getEditCount(),
309  'Edit count starts null for anonymous users.'
310  );
311 
312  $user->incEditCount();
313 
314  $this->assertNull(
315  $user->getEditCount(),
316  'Edit count remains null for anonymous users despite calls to increase it.'
317  );
318  }
319 
325  public function testIncEditCount() {
326  $user = $this->getMutableTestUser()->getUser();
327  $user->incEditCount();
328 
329  $reloadedUser = User::newFromId( $user->getId() );
330  $reloadedUser->incEditCount();
331 
332  $this->assertEquals(
333  2,
334  $reloadedUser->getEditCount(),
335  'Increasing the edit count after a fresh load leaves the object up to date.'
336  );
337  }
338 
344  public function testOptions() {
345  $user = $this->getMutableTestUser()->getUser();
346 
347  $user->setOption( 'userjs-someoption', 'test' );
348  $user->setOption( 'rclimit', 200 );
349  $user->saveSettings();
350 
352  $user->load( User::READ_LATEST );
353  $this->assertEquals( 'test', $user->getOption( 'userjs-someoption' ) );
354  $this->assertEquals( 200, $user->getOption( 'rclimit' ) );
355 
357  MediaWikiServices::getInstance()->getMainWANObjectCache()->clearProcessCache();
358  $this->assertEquals( 'test', $user->getOption( 'userjs-someoption' ) );
359  $this->assertEquals( 200, $user->getOption( 'rclimit' ) );
360  }
361 
367  public function testAnonOptions() {
369  $this->user->setOption( 'userjs-someoption', 'test' );
370  $this->assertEquals( $wgDefaultUserOptions['rclimit'], $this->user->getOption( 'rclimit' ) );
371  $this->assertEquals( 'test', $this->user->getOption( 'userjs-someoption' ) );
372  }
373 
383  public function testCheckPasswordValidity() {
384  $this->setMwGlobals( [
385  'wgPasswordPolicy' => [
386  'policies' => [
387  'sysop' => [
388  'MinimalPasswordLength' => 8,
389  'MinimumPasswordLengthToLogin' => 1,
390  'PasswordCannotMatchUsername' => 1,
391  ],
392  'default' => [
393  'MinimalPasswordLength' => 6,
394  'PasswordCannotMatchUsername' => true,
395  'PasswordCannotMatchBlacklist' => true,
396  'MaximalPasswordLength' => 40,
397  ],
398  ],
399  'checks' => [
400  'MinimalPasswordLength' => 'PasswordPolicyChecks::checkMinimalPasswordLength',
401  'MinimumPasswordLengthToLogin' => 'PasswordPolicyChecks::checkMinimumPasswordLengthToLogin',
402  'PasswordCannotMatchUsername' => 'PasswordPolicyChecks::checkPasswordCannotMatchUsername',
403  'PasswordCannotMatchBlacklist' => 'PasswordPolicyChecks::checkPasswordCannotMatchBlacklist',
404  'MaximalPasswordLength' => 'PasswordPolicyChecks::checkMaximalPasswordLength',
405  ],
406  ],
407  ] );
408 
409  $user = static::getTestUser()->getUser();
410 
411  // Sanity
412  $this->assertTrue( $user->isValidPassword( 'Password1234' ) );
413 
414  // Minimum length
415  $this->assertFalse( $user->isValidPassword( 'a' ) );
416  $this->assertFalse( $user->checkPasswordValidity( 'a' )->isGood() );
417  $this->assertTrue( $user->checkPasswordValidity( 'a' )->isOK() );
418  $this->assertEquals( 'passwordtooshort', $user->getPasswordValidity( 'a' ) );
419 
420  // Maximum length
421  $longPass = str_repeat( 'a', 41 );
422  $this->assertFalse( $user->isValidPassword( $longPass ) );
423  $this->assertFalse( $user->checkPasswordValidity( $longPass )->isGood() );
424  $this->assertFalse( $user->checkPasswordValidity( $longPass )->isOK() );
425  $this->assertEquals( 'passwordtoolong', $user->getPasswordValidity( $longPass ) );
426 
427  // Matches username
428  $this->assertFalse( $user->checkPasswordValidity( $user->getName() )->isGood() );
429  $this->assertTrue( $user->checkPasswordValidity( $user->getName() )->isOK() );
430  $this->assertEquals( 'password-name-match', $user->getPasswordValidity( $user->getName() ) );
431 
432  // On the forbidden list
433  $user = User::newFromName( 'Useruser' );
434  $this->assertFalse( $user->checkPasswordValidity( 'Passpass' )->isGood() );
435  $this->assertEquals( 'password-login-forbidden', $user->getPasswordValidity( 'Passpass' ) );
436  }
437 
442  public function testGetCanonicalName( $name, $expectedArray ) {
443  // fake interwiki map for the 'Interwiki prefix' testcase
444  $this->mergeMwGlobalArrayValue( 'wgHooks', [
445  'InterwikiLoadPrefix' => [
446  function ( $prefix, &$iwdata ) {
447  if ( $prefix === 'interwiki' ) {
448  $iwdata = [
449  'iw_url' => 'http://example.com/',
450  'iw_local' => 0,
451  'iw_trans' => 0,
452  ];
453  return false;
454  }
455  },
456  ],
457  ] );
458 
459  foreach ( $expectedArray as $validate => $expected ) {
460  $this->assertEquals(
461  $expected,
462  User::getCanonicalName( $name, $validate === 'false' ? false : $validate ), $validate );
463  }
464  }
465 
466  public static function provideGetCanonicalName() {
467  return [
468  'Leading space' => [ ' Leading space', [ 'creatable' => 'Leading space' ] ],
469  'Trailing space ' => [ 'Trailing space ', [ 'creatable' => 'Trailing space' ] ],
470  'Namespace prefix' => [ 'Talk:Username', [ 'creatable' => false, 'usable' => false,
471  'valid' => false, 'false' => 'Talk:Username' ] ],
472  'Interwiki prefix' => [ 'interwiki:Username', [ 'creatable' => false, 'usable' => false,
473  'valid' => false, 'false' => 'Interwiki:Username' ] ],
474  'With hash' => [ 'name with # hash', [ 'creatable' => false, 'usable' => false ] ],
475  'Multi spaces' => [ 'Multi spaces', [ 'creatable' => 'Multi spaces',
476  'usable' => 'Multi spaces' ] ],
477  'Lowercase' => [ 'lowercase', [ 'creatable' => 'Lowercase' ] ],
478  'Invalid character' => [ 'in[]valid', [ 'creatable' => false, 'usable' => false,
479  'valid' => false, 'false' => 'In[]valid' ] ],
480  'With slash' => [ 'with / slash', [ 'creatable' => false, 'usable' => false, 'valid' => false,
481  'false' => 'With / slash' ] ],
482  ];
483  }
484 
488  public function testEquals() {
489  $first = $this->getMutableTestUser()->getUser();
490  $second = User::newFromName( $first->getName() );
491 
492  $this->assertTrue( $first->equals( $first ) );
493  $this->assertTrue( $first->equals( $second ) );
494  $this->assertTrue( $second->equals( $first ) );
495 
496  $third = $this->getMutableTestUser()->getUser();
497  $fourth = $this->getMutableTestUser()->getUser();
498 
499  $this->assertFalse( $third->equals( $fourth ) );
500  $this->assertFalse( $fourth->equals( $third ) );
501 
502  // Test users loaded from db with id
503  $user = $this->getMutableTestUser()->getUser();
504  $fifth = User::newFromId( $user->getId() );
505  $sixth = User::newFromName( $user->getName() );
506  $this->assertTrue( $fifth->equals( $sixth ) );
507  }
508 
512  public function testGetId() {
513  $user = static::getTestUser()->getUser();
514  $this->assertTrue( $user->getId() > 0 );
515  }
516 
521  public function testLoggedIn() {
522  $user = $this->getMutableTestUser()->getUser();
523  $this->assertTrue( $user->isLoggedIn() );
524  $this->assertFalse( $user->isAnon() );
525 
526  // Non-existent users are perceived as anonymous
527  $user = User::newFromName( 'UTNonexistent' );
528  $this->assertFalse( $user->isLoggedIn() );
529  $this->assertTrue( $user->isAnon() );
530 
531  $user = new User;
532  $this->assertFalse( $user->isLoggedIn() );
533  $this->assertTrue( $user->isAnon() );
534  }
535 
539  public function testCheckAndSetTouched() {
540  $user = $this->getMutableTestUser()->getUser();
541  $user = TestingAccessWrapper::newFromObject( $user );
542  $this->assertTrue( $user->isLoggedIn() );
543 
544  $touched = $user->getDBTouched();
545  $this->assertTrue(
546  $user->checkAndSetTouched(), "checkAndSetTouched() succeded" );
547  $this->assertGreaterThan(
548  $touched, $user->getDBTouched(), "user_touched increased with casOnTouched()" );
549 
550  $touched = $user->getDBTouched();
551  $this->assertTrue(
552  $user->checkAndSetTouched(), "checkAndSetTouched() succeded #2" );
553  $this->assertGreaterThan(
554  $touched, $user->getDBTouched(), "user_touched increased with casOnTouched() #2" );
555  }
556 
560  public function testFindUsersByGroup() {
562  $this->assertEquals( 0, iterator_count( $users ) );
563 
564  $users = User::findUsersByGroup( 'foo' );
565  $this->assertEquals( 0, iterator_count( $users ) );
566 
567  $user = $this->getMutableTestUser( [ 'foo' ] )->getUser();
568  $users = User::findUsersByGroup( 'foo' );
569  $this->assertEquals( 1, iterator_count( $users ) );
570  $users->rewind();
571  $this->assertTrue( $user->equals( $users->current() ) );
572 
573  // arguments have OR relationship
574  $user2 = $this->getMutableTestUser( [ 'bar' ] )->getUser();
575  $users = User::findUsersByGroup( [ 'foo', 'bar' ] );
576  $this->assertEquals( 2, iterator_count( $users ) );
577  $users->rewind();
578  $this->assertTrue( $user->equals( $users->current() ) );
579  $users->next();
580  $this->assertTrue( $user2->equals( $users->current() ) );
581 
582  // users are not duplicated
583  $user = $this->getMutableTestUser( [ 'baz', 'boom' ] )->getUser();
584  $users = User::findUsersByGroup( [ 'baz', 'boom' ] );
585  $this->assertEquals( 1, iterator_count( $users ) );
586  $users->rewind();
587  $this->assertTrue( $user->equals( $users->current() ) );
588  }
589 
595  public function testAutoblockCookies() {
596  // Set up the bits of global configuration that we use.
597  $this->setMwGlobals( [
598  'wgCookieSetOnAutoblock' => true,
599  'wgCookiePrefix' => 'wmsitetitle',
600  'wgSecretKey' => MWCryptRand::generateHex( 64, true ),
601  ] );
602 
603  // 1. Log in a test user, and block them.
604  $user1tmp = $this->getTestUser()->getUser();
605  $request1 = new FauxRequest();
606  $request1->getSession()->setUser( $user1tmp );
607  $expiryFiveHours = wfTimestamp() + ( 5 * 60 * 60 );
608  $block = new Block( [
609  'enableAutoblock' => true,
610  'expiry' => wfTimestamp( TS_MW, $expiryFiveHours ),
611  ] );
612  $block->setTarget( $user1tmp );
613  $block->insert();
614  $user1 = User::newFromSession( $request1 );
615  $user1->mBlock = $block;
616  $user1->load();
617 
618  // Confirm that the block has been applied as required.
619  $this->assertTrue( $user1->isLoggedIn() );
620  $this->assertTrue( $user1->isBlocked() );
621  $this->assertEquals( Block::TYPE_USER, $block->getType() );
622  $this->assertTrue( $block->isAutoblocking() );
623  $this->assertGreaterThanOrEqual( 1, $block->getId() );
624 
625  // Test for the desired cookie name, value, and expiry.
626  $cookies = $request1->response()->getCookies();
627  $this->assertArrayHasKey( 'wmsitetitleBlockID', $cookies );
628  $this->assertEquals( $expiryFiveHours, $cookies['wmsitetitleBlockID']['expire'] );
629  $cookieValue = Block::getIdFromCookieValue( $cookies['wmsitetitleBlockID']['value'] );
630  $this->assertEquals( $block->getId(), $cookieValue );
631 
632  // 2. Create a new request, set the cookies, and see if the (anon) user is blocked.
633  $request2 = new FauxRequest();
634  $request2->setCookie( 'BlockID', $block->getCookieValue() );
635  $user2 = User::newFromSession( $request2 );
636  $user2->load();
637  $this->assertNotEquals( $user1->getId(), $user2->getId() );
638  $this->assertNotEquals( $user1->getToken(), $user2->getToken() );
639  $this->assertTrue( $user2->isAnon() );
640  $this->assertFalse( $user2->isLoggedIn() );
641  $this->assertTrue( $user2->isBlocked() );
642  $this->assertEquals( true, $user2->getBlock()->isAutoblocking() ); // Non-strict type-check.
643  // Can't directly compare the objects becuase of member type differences.
644  // One day this will work: $this->assertEquals( $block, $user2->getBlock() );
645  $this->assertEquals( $block->getId(), $user2->getBlock()->getId() );
646  $this->assertEquals( $block->getExpiry(), $user2->getBlock()->getExpiry() );
647 
648  // 3. Finally, set up a request as a new user, and the block should still be applied.
649  $user3tmp = $this->getTestUser()->getUser();
650  $request3 = new FauxRequest();
651  $request3->getSession()->setUser( $user3tmp );
652  $request3->setCookie( 'BlockID', $block->getId() );
653  $user3 = User::newFromSession( $request3 );
654  $user3->load();
655  $this->assertTrue( $user3->isLoggedIn() );
656  $this->assertTrue( $user3->isBlocked() );
657  $this->assertEquals( true, $user3->getBlock()->isAutoblocking() ); // Non-strict type-check.
658 
659  // Clean up.
660  $block->delete();
661  }
662 
667  public function testAutoblockCookiesDisabled() {
668  // Set up the bits of global configuration that we use.
669  $this->setMwGlobals( [
670  'wgCookieSetOnAutoblock' => false,
671  'wgCookiePrefix' => 'wm_no_cookies',
672  'wgSecretKey' => MWCryptRand::generateHex( 64, true ),
673  ] );
674 
675  // 1. Log in a test user, and block them.
676  $testUser = $this->getTestUser()->getUser();
677  $request1 = new FauxRequest();
678  $request1->getSession()->setUser( $testUser );
679  $block = new Block( [ 'enableAutoblock' => true ] );
680  $block->setTarget( $testUser );
681  $block->insert();
682  $user = User::newFromSession( $request1 );
683  $user->mBlock = $block;
684  $user->load();
685 
686  // 2. Test that the cookie IS NOT present.
687  $this->assertTrue( $user->isLoggedIn() );
688  $this->assertTrue( $user->isBlocked() );
689  $this->assertEquals( Block::TYPE_USER, $block->getType() );
690  $this->assertTrue( $block->isAutoblocking() );
691  $this->assertGreaterThanOrEqual( 1, $user->getBlockId() );
692  $this->assertGreaterThanOrEqual( $block->getId(), $user->getBlockId() );
693  $cookies = $request1->response()->getCookies();
694  $this->assertArrayNotHasKey( 'wm_no_cookiesBlockID', $cookies );
695 
696  // Clean up.
697  $block->delete();
698  }
699 
706  $this->setMwGlobals( [
707  'wgCookieSetOnAutoblock' => true,
708  'wgCookiePrefix' => 'wm_infinite_block',
709  'wgSecretKey' => MWCryptRand::generateHex( 64, true ),
710  ] );
711  // 1. Log in a test user, and block them indefinitely.
712  $user1Tmp = $this->getTestUser()->getUser();
713  $request1 = new FauxRequest();
714  $request1->getSession()->setUser( $user1Tmp );
715  $block = new Block( [ 'enableAutoblock' => true, 'expiry' => 'infinity' ] );
716  $block->setTarget( $user1Tmp );
717  $block->insert();
718  $user1 = User::newFromSession( $request1 );
719  $user1->mBlock = $block;
720  $user1->load();
721 
722  // 2. Test the cookie's expiry timestamp.
723  $this->assertTrue( $user1->isLoggedIn() );
724  $this->assertTrue( $user1->isBlocked() );
725  $this->assertEquals( Block::TYPE_USER, $block->getType() );
726  $this->assertTrue( $block->isAutoblocking() );
727  $this->assertGreaterThanOrEqual( 1, $user1->getBlockId() );
728  $cookies = $request1->response()->getCookies();
729  // Test the cookie's expiry to the nearest minute.
730  $this->assertArrayHasKey( 'wm_infinite_blockBlockID', $cookies );
731  $expOneDay = wfTimestamp() + ( 24 * 60 * 60 );
732  // Check for expiry dates in a 10-second window, to account for slow testing.
733  $this->assertEquals(
734  $expOneDay,
735  $cookies['wm_infinite_blockBlockID']['expire'],
736  'Expiry date',
737  5.0
738  );
739 
740  // 3. Change the block's expiry (to 2 hours), and the cookie's should be changed also.
741  $newExpiry = wfTimestamp() + 2 * 60 * 60;
742  $block->mExpiry = wfTimestamp( TS_MW, $newExpiry );
743  $block->update();
744  $user2tmp = $this->getTestUser()->getUser();
745  $request2 = new FauxRequest();
746  $request2->getSession()->setUser( $user2tmp );
747  $user2 = User::newFromSession( $request2 );
748  $user2->mBlock = $block;
749  $user2->load();
750  $cookies = $request2->response()->getCookies();
751  $this->assertEquals( wfTimestamp( TS_MW, $newExpiry ), $block->getExpiry() );
752  $this->assertEquals( $newExpiry, $cookies['wm_infinite_blockBlockID']['expire'] );
753 
754  // Clean up.
755  $block->delete();
756  }
757 
758  public function testSoftBlockRanges() {
759  global $wgUser;
760 
761  $this->setMwGlobals( [
762  'wgSoftBlockRanges' => [ '10.0.0.0/8' ],
763  'wgUser' => null,
764  ] );
765 
766  // IP isn't in $wgSoftBlockRanges
767  $request = new FauxRequest();
768  $request->setIP( '192.168.0.1' );
770  $this->assertNull( $wgUser->getBlock() );
771 
772  // IP is in $wgSoftBlockRanges
773  $request = new FauxRequest();
774  $request->setIP( '10.20.30.40' );
776  $block = $wgUser->getBlock();
777  $this->assertInstanceOf( Block::class, $block );
778  $this->assertSame( 'wgSoftBlockRanges', $block->getSystemBlockType() );
779 
780  // Make sure the block is really soft
781  $request->getSession()->setUser( $this->getTestUser()->getUser() );
783  $this->assertFalse( $wgUser->isAnon(), 'sanity check' );
784  $this->assertNull( $wgUser->getBlock() );
785  }
786 
790  public function testAutoblockCookieInauthentic() {
791  // Set up the bits of global configuration that we use.
792  $this->setMwGlobals( [
793  'wgCookieSetOnAutoblock' => true,
794  'wgCookiePrefix' => 'wmsitetitle',
795  'wgSecretKey' => MWCryptRand::generateHex( 64, true ),
796  ] );
797 
798  // 1. Log in a blocked test user.
799  $user1tmp = $this->getTestUser()->getUser();
800  $request1 = new FauxRequest();
801  $request1->getSession()->setUser( $user1tmp );
802  $block = new Block( [ 'enableAutoblock' => true ] );
803  $block->setTarget( $user1tmp );
804  $block->insert();
805  $user1 = User::newFromSession( $request1 );
806  $user1->mBlock = $block;
807  $user1->load();
808 
809  // 2. Create a new request, set the cookie to an invalid value, and make sure the (anon)
810  // user not blocked.
811  $request2 = new FauxRequest();
812  $request2->setCookie( 'BlockID', $block->getId() . '!zzzzzzz' );
813  $user2 = User::newFromSession( $request2 );
814  $user2->load();
815  $this->assertTrue( $user2->isAnon() );
816  $this->assertFalse( $user2->isLoggedIn() );
817  $this->assertFalse( $user2->isBlocked() );
818 
819  // Clean up.
820  $block->delete();
821  }
822 
827  public function testAutoblockCookieNoSecretKey() {
828  // Set up the bits of global configuration that we use.
829  $this->setMwGlobals( [
830  'wgCookieSetOnAutoblock' => true,
831  'wgCookiePrefix' => 'wmsitetitle',
832  'wgSecretKey' => null,
833  ] );
834 
835  // 1. Log in a blocked test user.
836  $user1tmp = $this->getTestUser()->getUser();
837  $request1 = new FauxRequest();
838  $request1->getSession()->setUser( $user1tmp );
839  $block = new Block( [ 'enableAutoblock' => true ] );
840  $block->setTarget( $user1tmp );
841  $block->insert();
842  $user1 = User::newFromSession( $request1 );
843  $user1->mBlock = $block;
844  $user1->load();
845  $this->assertTrue( $user1->isBlocked() );
846 
847  // 2. Create a new request, set the cookie to just the block ID, and the user should
848  // still get blocked when they log in again.
849  $request2 = new FauxRequest();
850  $request2->setCookie( 'BlockID', $block->getId() );
851  $user2 = User::newFromSession( $request2 );
852  $user2->load();
853  $this->assertNotEquals( $user1->getId(), $user2->getId() );
854  $this->assertNotEquals( $user1->getToken(), $user2->getToken() );
855  $this->assertTrue( $user2->isAnon() );
856  $this->assertFalse( $user2->isLoggedIn() );
857  $this->assertTrue( $user2->isBlocked() );
858  $this->assertEquals( true, $user2->getBlock()->isAutoblocking() ); // Non-strict type-check.
859 
860  // Clean up.
861  $block->delete();
862  }
863 
864  public function testIsPingLimitable() {
865  $request = new FauxRequest();
866  $request->setIP( '1.2.3.4' );
868 
869  $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [] );
870  $this->assertTrue( $user->isPingLimitable() );
871 
872  $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [ '1.2.3.4' ] );
873  $this->assertFalse( $user->isPingLimitable() );
874 
875  $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [ '1.2.3.0/8' ] );
876  $this->assertFalse( $user->isPingLimitable() );
877 
878  $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [] );
879  $noRateLimitUser = $this->getMockBuilder( User::class )->disableOriginalConstructor()
880  ->setMethods( [ 'getIP', 'getRights' ] )->getMock();
881  $noRateLimitUser->expects( $this->any() )->method( 'getIP' )->willReturn( '1.2.3.4' );
882  $noRateLimitUser->expects( $this->any() )->method( 'getRights' )->willReturn( [ 'noratelimit' ] );
883  $this->assertFalse( $noRateLimitUser->isPingLimitable() );
884  }
885 
886  public function provideExperienceLevel() {
887  return [
888  [ 2, 2, 'newcomer' ],
889  [ 12, 3, 'newcomer' ],
890  [ 8, 5, 'newcomer' ],
891  [ 15, 10, 'learner' ],
892  [ 450, 20, 'learner' ],
893  [ 460, 33, 'learner' ],
894  [ 525, 28, 'learner' ],
895  [ 538, 33, 'experienced' ],
896  ];
897  }
898 
902  public function testExperienceLevel( $editCount, $memberSince, $expLevel ) {
903  $this->setMwGlobals( [
904  'wgLearnerEdits' => 10,
905  'wgLearnerMemberSince' => 4,
906  'wgExperiencedUserEdits' => 500,
907  'wgExperiencedUserMemberSince' => 30,
908  ] );
909 
910  $db = wfGetDB( DB_MASTER );
911 
912  $data = new stdClass();
913  $data->user_id = 1;
914  $data->user_name = 'name';
915  $data->user_real_name = 'Real Name';
916  $data->user_touched = 1;
917  $data->user_token = 'token';
918  $data->user_email = 'a@a.a';
919  $data->user_email_authenticated = null;
920  $data->user_email_token = 'token';
921  $data->user_email_token_expires = null;
922  $data->user_editcount = $editCount;
923  $data->user_registration = $db->timestamp( time() - $memberSince * 86400 );
924  $user = User::newFromRow( $data );
925 
926  $this->assertEquals( $expLevel, $user->getExperienceLevel() );
927  }
928 
929  public function testExperienceLevelAnon() {
930  $user = User::newFromName( '10.11.12.13', false );
931 
932  $this->assertFalse( $user->getExperienceLevel() );
933  }
934 
935  public static function provideIsLocallBlockedProxy() {
936  return [
937  [ '1.2.3.4', '1.2.3.4' ],
938  [ '1.2.3.4', '1.2.3.0/16' ],
939  ];
940  }
941 
946  public function testIsLocallyBlockedProxy( $ip, $blockListEntry ) {
947  $this->setMwGlobals(
948  'wgProxyList', []
949  );
950  $this->assertFalse( User::isLocallyBlockedProxy( $ip ) );
951 
952  $this->setMwGlobals(
953  'wgProxyList',
954  [
955  $blockListEntry
956  ]
957  );
958  $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
959 
960  $this->setMwGlobals(
961  'wgProxyList',
962  [
963  'test' => $blockListEntry
964  ]
965  );
966  $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
967 
968  $this->hideDeprecated(
969  'IP addresses in the keys of $wgProxyList (found the following IP ' .
970  'addresses in keys: ' . $blockListEntry . ', please move them to values)'
971  );
972  $this->setMwGlobals(
973  'wgProxyList',
974  [
975  $blockListEntry => 'test'
976  ]
977  );
978  $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
979  }
980 }
User\load
load( $flags=self::READ_NORMAL)
Load the user table data for this object from the source given by mFrom.
Definition: User.php:362
$wgUser
$wgUser
Definition: Setup.php:809
UserTest\testGetCanonicalName
testGetCanonicalName( $name, $expectedArray)
User::getCanonicalName() provideGetCanonicalName.
Definition: UserTest.php:442
UserTest\provideGetGroupsWithPermission
static provideGetGroupsWithPermission()
Definition: UserTest.php:158
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:573
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:268
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
UserTest\testSoftBlockRanges
testSoftBlockRanges()
Definition: UserTest.php:758
User\isValidPassword
isValidPassword( $password)
Is the input a valid password for this user?
Definition: User.php:1005
User\getId
getId()
Get the user's ID.
Definition: User.php:2224
UserTest\testCheckAndSetTouched
testCheckAndSetTouched()
User::checkAndSetTouched.
Definition: UserTest.php:539
User\isAnon
isAnon()
Get whether the user is anonymous.
Definition: User.php:3510
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:807
UserTest\testIsIP
testIsIP( $value, $result, $message)
provideIPs User::isIP
Definition: UserTest.php:183
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:148
User\isLocallyBlockedProxy
static isLocallyBlockedProxy( $ip)
Check if an IP address is in the local proxy list.
Definition: User.php:1855
$wgRevokePermissions
$wgRevokePermissions
Permission keys revoked from users in each group.
Definition: DefaultSettings.php:5268
User\getEditCount
getEditCount()
Get the user's edit count.
Definition: User.php:3401
User\incEditCount
incEditCount()
Deferred version of incEditCountImmediate()
Definition: User.php:5110
User\newFromSession
static newFromSession(WebRequest $request=null)
Create a new user object using data from session.
Definition: User.php:616
UserTest\testFindUsersByGroup
testFindUsersByGroup()
User::findUsersByGroup.
Definition: UserTest.php:560
User\getBlockId
getBlockId()
If user is blocked, return the ID for the block.
Definition: User.php:2128
UserTest\testUserGetRightsHooks
testUserGetRightsHooks()
User::getRights.
Definition: UserTest.php:100
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1963
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
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
$wgDefaultUserOptions
$wgDefaultUserOptions
Settings added to this array will override the default globals for the user preferences used by anony...
Definition: DefaultSettings.php:4862
UserTest\testLoggedIn
testLoggedIn()
User::isLoggedIn User::isAnon.
Definition: UserTest.php:521
UserTest\testAllRightsWithMessage
testAllRightsWithMessage()
Test, if for all rights a right- message exist, which is used on Special:ListGroupRights as help text...
Definition: UserTest.php:240
UserTest\testAutoblockCookieInauthentic
testAutoblockCookieInauthentic()
Test that a modified BlockID cookie doesn't actually load the relevant block (T152951).
Definition: UserTest.php:790
UserTest\$user
User $user
Definition: UserTest.php:16
UserTest\testOptions
testOptions()
Test changing user options.
Definition: UserTest.php:344
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:550
UserTest\provideIsLocallBlockedProxy
static provideIsLocallBlockedProxy()
Definition: UserTest.php:935
MWCryptRand\generateHex
static generateHex( $chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
Definition: MWCryptRand.php:76
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
User
User
Definition: All_system_messages.txt:425
User\newFromRow
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition: User.php:637
UserTest\testGetId
testGetId()
User::getId.
Definition: UserTest.php:512
UserTest\testExperienceLevel
testExperienceLevel( $editCount, $memberSince, $expLevel)
provideExperienceLevel
Definition: UserTest.php:902
UserTest\testIsLocallyBlockedProxy
testIsLocallyBlockedProxy( $ip, $blockListEntry)
provideIsLocallBlockedProxy User::isLocallyBlockedProxy
Definition: UserTest.php:946
User\equals
equals(User $user)
Checks if two user objects point to the same user.
Definition: User.php:5567
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
User\getRights
getRights()
Get the permissions this user has.
Definition: User.php:3258
UserTest\testGroupPermissions
testGroupPermissions()
User::getGroupPermissions.
Definition: UserTest.php:61
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:121
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
User\checkPasswordValidity
checkPasswordValidity( $password)
Check if this is a valid password for this user.
Definition: User.php:1052
UserTest\testAnonOptions
testAnonOptions()
T39963 Make sure defaults are loaded when setOption is called.
Definition: UserTest.php:367
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
UserTest\testGetEditCountForAnons
testGetEditCountForAnons()
Test User::editCount medium User::getEditCount.
Definition: UserTest.php:304
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
UserTest\testAutoblockCookieNoSecretKey
testAutoblockCookieNoSecretKey()
The BlockID cookie is normally verified with a HMAC, but not if wgSecretKey is not set.
Definition: UserTest.php:827
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:1467
UserTest\testCheckPasswordValidity
testCheckPasswordValidity()
Test password validity checks.
Definition: UserTest.php:383
MediaWiki
A helper class for throttling authentication attempts.
UserTest\setUpPermissionGlobals
setUpPermissionGlobals()
Definition: UserTest.php:31
User\isPingLimitable
isPingLimitable()
Is this user subject to rate limiting?
Definition: User.php:1901
MediaWikiTestCase\$users
static TestUser[] $users
Definition: MediaWikiTestCase.php:44
UserTest
Database.
Definition: UserTest.php:12
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
UserTest\testUserPermissions
testUserPermissions()
User::getRights.
Definition: UserTest.php:89
DB_MASTER
const DB_MASTER
Definition: defines.php:26
User\saveSettings
saveSettings()
Save this user's settings into the database.
Definition: User.php:4009
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:129
UserTest\testIsPingLimitable
testIsPingLimitable()
Definition: UserTest.php:864
$request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2581
UserTest\provideIPs
static provideIPs()
Definition: UserTest.php:187
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
Block\getIdFromCookieValue
static getIdFromCookieValue( $cookieValue)
Get the stored ID from the 'BlockID' cookie.
Definition: Block.php:1517
$value
$value
Definition: styleTest.css.php:45
User\getOption
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition: User.php:2882
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:160
MediaWiki\Session\TestUtils\getDummySession
static getDummySession( $backend=null, $index=-1, $logger=null)
If you need a Session for testing but don't want to create a backend to construct one,...
Definition: TestUtils.php:86
UserTest\testAutoblockCookiesDisabled
testAutoblockCookiesDisabled()
Make sure that no cookie is set to track autoblocked users when $wgCookieSetOnAutoblock is false.
Definition: UserTest.php:667
UserTest\provideGetCanonicalName
static provideGetCanonicalName()
Definition: UserTest.php:466
User\checkAndSetTouched
checkAndSetTouched()
Bump user_touched if it didn't change since this object was loaded.
Definition: User.php:1516
UserTest\provideExperienceLevel
provideExperienceLevel()
Definition: UserTest.php:886
User\getGroupPermissions
static getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
Definition: User.php:4741
UserTest\testIncEditCount
testIncEditCount()
Test User::editCount medium User::incEditCount.
Definition: UserTest.php:325
UserTest\testAutoblockCookieInfiniteExpiry
testAutoblockCookieInfiniteExpiry()
When a user is autoblocked and a cookie is set to track them, the expiry time of the cookie should ma...
Definition: UserTest.php:705
UserTest\setUp
setUp()
Definition: UserTest.php:18
User\getAllRights
static getAllRights()
Get a list of all available permissions.
Definition: User.php:4897
User\getDBTouched
getDBTouched()
Get the user_touched timestamp field (time of last DB updates)
Definition: User.php:2586
UserTest\testGetGroupsWithPermission
testGetGroupsWithPermission( $expected, $right)
provideGetGroupsWithPermission User::getGroupsWithPermission
Definition: UserTest.php:150
Block\TYPE_USER
const TYPE_USER
Definition: Block.php:83
User\getExperienceLevel
getExperienceLevel()
Compute experienced level based on edit count and registration date.
Definition: User.php:3816
User\isLoggedIn
isLoggedIn()
Get whether the user is logged in.
Definition: User.php:3502
$wgGroupPermissions
$wgGroupPermissions
Permission keys given to users in each group.
Definition: DefaultSettings.php:5129
User\findUsersByGroup
static findUsersByGroup( $groups, $limit=5000, $after=null)
Return the users who are members of the given group(s).
Definition: User.php:935
User\getCanonicalName
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
Definition: User.php:1092
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Block
Definition: Block.php:27
Language\getMessageKeysFor
static getMessageKeysFor( $code)
Get all message keys for a given language.
Definition: Language.php:4494
UserTest\testExperienceLevelAnon
testExperienceLevelAnon()
Definition: UserTest.php:929
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
User\isBlocked
isBlocked( $bFromSlave=true)
Check if user is blocked.
Definition: User.php:2067
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
User\setOption
setOption( $oname, $val)
Set the given option for a user.
Definition: User.php:2969
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:781
UserTest\provideUserNames
static provideUserNames()
Definition: UserTest.php:212
User\getPasswordValidity
getPasswordValidity( $password)
Given unvalidated password input, return error message on failure.
Definition: User.php:1016
UserTest\testRevokePermissions
testRevokePermissions()
User::getGroupPermissions.
Definition: UserTest.php:78
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2249
UserTest\testGetEditCount
testGetEditCount()
Test User::editCount medium User::getEditCount.
Definition: UserTest.php:268
UserTest\testEquals
testEquals()
User::equals.
Definition: UserTest.php:488
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:52
User\getGroupsWithPermission
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition: User.php:4768
UserTest\testIsValidUserName
testIsValidUserName( $username, $result, $message)
provideUserNames User::isValidUserName
Definition: UserTest.php:208
UserTest\testAutoblockCookies
testAutoblockCookies()
When a user is autoblocked a cookie is set with which to track them in case they log out and change I...
Definition: UserTest.php:595