4define(
'NS_UNITTEST_TALK', 5601 );
29 'wgGroupPermissions' => [],
30 'wgRevokePermissions' => [],
37 $this->user = $this->
getTestUser( [
'unittesters' ] )->getUser();
43 # Data for regular $wgGroupPermissions test
56 # Data for regular $wgRevokePermissions test
61 # For the options test
63 'editmyoptions' =>
true,
99 $rights = $this->user->getRights();
110 $user = $this->
getTestUser( [
'unittesters',
'testwriters' ] )->getUser();
111 $userWrapper = TestingAccessWrapper::newFromObject( $user );
113 $rights = $user->getRights();
121 $rights[] =
'nukeworld';
122 $rights =
array_diff( $rights, [
'writetest' ] );
125 $userWrapper->mRights =
null;
126 $rights = $user->getRights();
134 ->setMethods( [
'getAllowedUserRights',
'deregisterSession',
'getSessionId' ] )
136 $mock->method(
'getAllowedUserRights' )->willReturn( [
'test',
'writetest' ] );
137 $mock->method(
'getSessionId' )->willReturn(
140 $session = MediaWiki\Session\TestUtils::getDummySession( $mock );
142 ->setMethods( [
'getSession' ] )
144 $mockRequest->method(
'getSession' )->willReturn( $session );
147 $userWrapper->mRights =
null;
148 $rights = $user->getRights();
164 $this->
assertEquals( $expected, $result,
"Groups with permission $right" );
170 [
'unittesters',
'testwriters' ],
198 [
'',
false,
'Empty string' ],
199 [
' ',
false,
'Blank space' ],
200 [
'10.0.0.0',
true,
'IPv4 private 10/8' ],
201 [
'10.255.255.255',
true,
'IPv4 private 10/8' ],
202 [
'192.168.1.1',
true,
'IPv4 private 192.168/16' ],
203 [
'203.0.113.0',
true,
'IPv4 example' ],
204 [
'2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
true,
'IPv6 example' ],
208 [
'300.300.300.300',
true,
'Looks too much like an IPv4 address' ],
209 [
'203.0.113.xxx',
true,
'Assigned by UseMod to cloaked logged-out users' ],
223 [
'',
false,
'Empty string' ],
224 [
' ',
false,
'Blank space' ],
225 [
'abcd',
false,
'Starts with small letter' ],
226 [
'Ab/cd',
false,
'Contains slash' ],
227 [
'Ab cd',
true,
'Whitespace' ],
228 [
'192.168.1.1',
false,
'IP' ],
229 [
'116.17.184.5/32',
false,
'IP range' ],
230 [
'::e:f:2001/96',
false,
'IPv6 range' ],
231 [
'User:Abcd',
false,
'Reserved Namespace' ],
232 [
'12abcd232',
true,
'Starts with Numbers' ],
233 [
'?abcd',
true,
'Start with ? mark' ],
234 [
'#abcd',
false,
'Start with #' ],
235 [
'Abcdകഖഗഘ',
true,
' Mixed scripts' ],
236 [
'ജോസ്തോമസ്',
false,
'ZWNJ- Format control character' ],
237 [
'Ab cd',
false,
' Ideographic space' ],
238 [
'300.300.300.300',
false,
'Looks too much like an IPv4 address' ],
239 [
'302.113.311.900',
false,
'Looks too much like an IPv4 address' ],
240 [
'203.0.113.xxx',
false,
'Reserved for usage by UseMod for cloaked logged-out users' ],
253 $page = WikiPage::factory( Title::newFromText(
'Help:UserTest_EditCount' ) );
254 for ( $i = 0; $i < 3; $i++ ) {
255 $page->doEditContent(
256 ContentHandler::makeContent( (
string)$i, $page->getTitle() ),
266 $user->getEditCount(),
267 'After three edits, the user edit count should be 3'
271 $user->incEditCount();
272 $user->clearInstanceCache();
276 $user->getEditCount(),
277 'After increasing the edit count manually, the user edit count should be 4'
290 $user->getEditCount(),
291 'Edit count starts null for anonymous users.'
294 $user->incEditCount();
297 $user->getEditCount(),
298 'Edit count remains null for anonymous users despite calls to increase it.'
309 $user->incEditCount();
312 $reloadedUser->incEditCount();
316 $reloadedUser->getEditCount(),
317 'Increasing the edit count after a fresh load leaves the object up to date.'
329 $user->setOption(
'userjs-someoption',
'test' );
330 $user->setOption(
'rclimit', 200 );
331 $user->setOption(
'wpwatchlistdays',
'0' );
332 $user->saveSettings();
335 $user->load( User::READ_LATEST );
336 $this->
assertEquals(
'test', $user->getOption(
'userjs-someoption' ) );
337 $this->
assertEquals( 200, $user->getOption(
'rclimit' ) );
340 MediaWikiServices::getInstance()->getMainWANObjectCache()->clearProcessCache();
341 $this->
assertEquals(
'test', $user->getOption(
'userjs-someoption' ) );
342 $this->
assertEquals( 200, $user->getOption(
'rclimit' ) );
346 $user->load( User::READ_LATEST );
347 $this->
assertSame( 0, $user->getOption(
'wpwatchlistdays' ) );
357 $this->user->setOption(
'userjs-someoption',
'test' );
358 $this->
assertEquals( $wgDefaultUserOptions[
'rclimit'], $this->user->getOption(
'rclimit' ) );
359 $this->
assertEquals(
'test', $this->user->getOption(
'userjs-someoption' ) );
373 'wgPasswordPolicy' => [
376 'MinimalPasswordLength' => 8,
377 'MinimumPasswordLengthToLogin' => 1,
378 'PasswordCannotMatchUsername' => 1,
381 'MinimalPasswordLength' => 6,
382 'PasswordCannotMatchUsername' =>
true,
383 'PasswordCannotMatchBlacklist' =>
true,
384 'MaximalPasswordLength' => 40,
388 'MinimalPasswordLength' =>
'PasswordPolicyChecks::checkMinimalPasswordLength',
389 'MinimumPasswordLengthToLogin' =>
'PasswordPolicyChecks::checkMinimumPasswordLengthToLogin',
390 'PasswordCannotMatchUsername' =>
'PasswordPolicyChecks::checkPasswordCannotMatchUsername',
391 'PasswordCannotMatchBlacklist' =>
'PasswordPolicyChecks::checkPasswordCannotMatchBlacklist',
392 'MaximalPasswordLength' =>
'PasswordPolicyChecks::checkMaximalPasswordLength',
398 $user = static::getTestUser()->getUser();
401 $this->
assertTrue( $user->isValidPassword(
'Password1234' ) );
404 $this->
assertFalse( $user->isValidPassword(
'a' ) );
405 $this->
assertFalse( $user->checkPasswordValidity(
'a' )->isGood() );
406 $this->
assertTrue( $user->checkPasswordValidity(
'a' )->isOK() );
407 $this->
assertEquals(
'passwordtooshort', $user->getPasswordValidity(
'a' ) );
411 $this->
assertFalse( $user->isValidPassword( $longPass ) );
412 $this->
assertFalse( $user->checkPasswordValidity( $longPass )->isGood() );
413 $this->
assertFalse( $user->checkPasswordValidity( $longPass )->isOK() );
414 $this->
assertEquals(
'passwordtoolong', $user->getPasswordValidity( $longPass ) );
417 $this->
assertFalse( $user->checkPasswordValidity( $user->getName() )->isGood() );
418 $this->
assertTrue( $user->checkPasswordValidity( $user->getName() )->isOK() );
419 $this->
assertEquals(
'password-name-match', $user->getPasswordValidity( $user->getName() ) );
423 $this->
assertFalse( $user->checkPasswordValidity(
'Passpass' )->isGood() );
424 $this->
assertEquals(
'password-login-forbidden', $user->getPasswordValidity(
'Passpass' ) );
434 'InterwikiLoadPrefix' => [
435 function ( $prefix, &$iwdata ) {
436 if ( $prefix ===
'interwiki' ) {
438 'iw_url' =>
'http://example.com/',
448 foreach ( $expectedArray as $validate => $expected ) {
457 'Leading space' => [
' Leading space', [
'creatable' =>
'Leading space' ] ],
458 'Trailing space ' => [
'Trailing space ', [
'creatable' =>
'Trailing space' ] ],
459 'Namespace prefix' => [
'Talk:Username', [
'creatable' =>
false,
'usable' =>
false,
460 'valid' =>
false,
'false' =>
'Talk:Username' ] ],
461 'Interwiki prefix' => [
'interwiki:Username', [
'creatable' =>
false,
'usable' =>
false,
462 'valid' =>
false,
'false' =>
'Interwiki:Username' ] ],
463 'With hash' => [
'name with # hash', [
'creatable' =>
false,
'usable' =>
false ] ],
464 'Multi spaces' => [
'Multi spaces', [
'creatable' =>
'Multi spaces',
465 'usable' =>
'Multi spaces' ] ],
466 'Lowercase' => [
'lowercase', [
'creatable' =>
'Lowercase' ] ],
467 'Invalid character' => [
'in[]valid', [
'creatable' =>
false,
'usable' =>
false,
468 'valid' =>
false,
'false' =>
'In[]valid' ] ],
469 'With slash' => [
'with / slash', [
'creatable' =>
false,
'usable' =>
false,
'valid' =>
false,
470 'false' =>
'With / slash' ] ],
481 $this->
assertTrue( $first->equals( $first ) );
482 $this->
assertTrue( $first->equals( $second ) );
483 $this->
assertTrue( $second->equals( $first ) );
495 $this->
assertTrue( $fifth->equals( $sixth ) );
502 $user = static::getTestUser()->getUser();
530 $user = TestingAccessWrapper::newFromObject( $user );
533 $touched = $user->getDBTouched();
535 $user->checkAndSetTouched(),
"checkAndSetTouched() succedeed" );
537 $touched, $user->getDBTouched(),
"user_touched increased with casOnTouched()" );
539 $touched = $user->getDBTouched();
541 $user->checkAndSetTouched(),
"checkAndSetTouched() succedeed #2" );
543 $touched, $user->getDBTouched(),
"user_touched increased with casOnTouched() #2" );
591 'wgCookieSetOnAutoblock' =>
true,
592 'wgCookiePrefix' =>
'wmsitetitle',
598 'PerformRetroactiveAutoblock' => []
604 $request1->getSession()->setUser( $user1tmp );
605 $expiryFiveHours =
wfTimestamp() + ( 5 * 60 * 60 );
606 $block =
new Block( [
607 'enableAutoblock' =>
true,
608 'expiry' =>
wfTimestamp( TS_MW, $expiryFiveHours ),
611 $block->setTarget( $user1tmp );
612 $res = $block->insert();
615 $user1->mBlock = $block;
622 $this->
assertTrue( $block->isAutoblocking() );
626 $cookies = $request1->response()->getCookies();
628 $this->
assertEquals( $expiryFiveHours, $cookies[
'wmsitetitleBlockID'][
'expire'] );
634 $request2->setCookie(
'BlockID', $block->getCookieValue() );
643 $this->
assertEquals(
true, $user2->getBlock()->isAutoblocking(),
'Autoblock does not work' );
646 $this->
assertEquals( $block->getId(), $user2->getBlock()->getId() );
647 $this->
assertEquals( $block->getExpiry(), $user2->getBlock()->getExpiry() );
652 $request3->getSession()->setUser( $user3tmp );
653 $request3->setCookie(
'BlockID', $block->getId() );
658 $this->
assertEquals(
true, $user3->getBlock()->isAutoblocking() );
672 'wgCookieSetOnAutoblock' =>
false,
673 'wgCookiePrefix' =>
'wm_no_cookies',
679 'PerformRetroactiveAutoblock' => []
685 $request1->getSession()->setUser( $testUser );
686 $block =
new Block( [
'enableAutoblock' =>
true ] );
688 $block->setTarget( $testUser );
689 $res = $block->insert();
692 $user->mBlock = $block;
699 $this->
assertTrue( $block->isAutoblocking() );
702 $cookies = $request1->response()->getCookies();
717 'wgCookieSetOnAutoblock' =>
true,
718 'wgCookiePrefix' =>
'wm_infinite_block',
724 'PerformRetroactiveAutoblock' => []
730 $request1->getSession()->setUser( $user1Tmp );
731 $block =
new Block( [
'enableAutoblock' =>
true,
'expiry' =>
'infinity' ] );
733 $block->setTarget( $user1Tmp );
734 $res = $block->insert();
737 $user1->mBlock = $block;
744 $this->
assertTrue( $block->isAutoblocking() );
746 $cookies = $request1->response()->getCookies();
753 $cookies[
'wm_infinite_blockBlockID'][
'expire'],
760 $block->setExpiry(
wfTimestamp( TS_MW, $newExpiry ) );
764 $request2->getSession()->setUser( $user2tmp );
766 $user2->mBlock = $block;
768 $cookies = $request2->response()->getCookies();
770 $this->
assertEquals( $newExpiry, $cookies[
'wm_infinite_blockBlockID'][
'expire'] );
782 RequestContext::getMain()->setUser( $user );
783 RequestContext::getMain()->setRequest(
$request );
784 TestingAccessWrapper::newFromObject( $user )->mRequest =
$request;
785 $request->getSession()->setUser( $user );
787 $this->
setMwGlobals(
'wgSoftBlockRanges', [
'10.0.0.0/8' ] );
790 $wgUser =
new User();
797 $wgUser =
new User();
801 $block = $wgUser->getBlock();
803 $this->
assertSame(
'wgSoftBlockRanges', $block->getSystemBlockType() );
810 $this->
assertFalse( $wgUser->isAnon(),
'sanity check' );
821 'wgCookieSetOnAutoblock' =>
true,
822 'wgCookiePrefix' =>
'wmsitetitle',
828 'PerformRetroactiveAutoblock' => []
834 $request1->getSession()->setUser( $user1tmp );
835 $block =
new Block( [
'enableAutoblock' =>
true ] );
837 $block->setTarget( $user1tmp );
838 $res = $block->insert();
841 $user1->mBlock = $block;
847 $request2->setCookie(
'BlockID', $block->getId() .
'!zzzzzzz' );
866 'wgCookieSetOnAutoblock' =>
true,
867 'wgCookiePrefix' =>
'wmsitetitle',
868 'wgSecretKey' =>
null,
873 'PerformRetroactiveAutoblock' => []
879 $request1->getSession()->setUser( $user1tmp );
880 $block =
new Block( [
'enableAutoblock' =>
true ] );
882 $block->setTarget( $user1tmp );
883 $res = $block->insert();
886 $user1->mBlock = $block;
893 $request2->setCookie(
'BlockID', $block->getId() );
901 $this->
assertEquals(
true, $user2->getBlock()->isAutoblocking() );
916 $this->
assertTrue( $user->isPingLimitable() );
918 $this->
setMwGlobals(
'wgRateLimitsExcludedIPs', [
'1.2.3.4' ] );
921 $this->
setMwGlobals(
'wgRateLimitsExcludedIPs', [
'1.2.3.0/8' ] );
925 $noRateLimitUser = $this->
getMockBuilder( User::class )->disableOriginalConstructor()
926 ->setMethods( [
'getIP',
'getRights' ] )->getMock();
927 $noRateLimitUser->expects( $this->
any() )->method(
'getIP' )->willReturn(
'1.2.3.4' );
928 $noRateLimitUser->expects( $this->
any() )->method(
'getRights' )->willReturn( [
'noratelimit' ] );
929 $this->
assertFalse( $noRateLimitUser->isPingLimitable() );
934 [ 2, 2,
'newcomer' ],
935 [ 12, 3,
'newcomer' ],
936 [ 8, 5,
'newcomer' ],
937 [ 15, 10,
'learner' ],
938 [ 450, 20,
'learner' ],
939 [ 460, 33,
'learner' ],
940 [ 525, 28,
'learner' ],
941 [ 538, 33,
'experienced' ],
951 'wgLearnerEdits' => 10,
952 'wgLearnerMemberSince' => 4,
953 'wgExperiencedUserEdits' => 500,
954 'wgExperiencedUserMemberSince' => 30,
960 $userQuery[
'tables'],
961 $userQuery[
'fields'],
962 [
'user_id' => $this->
getTestUser()->getUser()->getId() ],
968 $row->user_registration =
$db->
timestamp( time() - $memberSince * 86400 );
971 $this->
assertEquals( $expLevel, $user->getExperienceLevel() );
985 [
'1.2.3.4',
'1.2.3.4' ],
986 [
'1.2.3.4',
'1.2.3.0/16' ],
1011 'test' => $blockListEntry
1017 'IP addresses in the keys of $wgProxyList (found the following IP ' .
1018 'addresses in keys: ' . $blockListEntry .
', please move them to values)'
1023 $blockListEntry =>
'test'
1033 $domain = MediaWikiServices::getInstance()->getDBLoadBalancer()->getLocalDomainID();
1038 $id = $user->getId();
1039 $this->
assertTrue( $user->getActorId() > 0,
'User::createNew sets an actor ID' );
1042 $user->addToDatabase();
1043 $this->
assertTrue( $user->getActorId() > 0,
'User::addToDatabase sets an actor ID' );
1046 $this->
assertTrue( $user->getActorId() > 0,
'Actor ID can be retrieved for user loaded by name' );
1049 $this->
assertTrue( $user->getActorId() > 0,
'Actor ID can be retrieved for user loaded by ID' );
1053 'User::newFromActorId works for an existing user' );
1055 $row = $this->db->selectRow(
'user',
User::selectFields(), [
'user_id' => $id ], __METHOD__ );
1058 'Actor ID can be retrieved for user loaded with User::selectFields()' );
1061 $user->setName(
'UserTestActorId4-renamed' );
1062 $user->saveSettings();
1065 $this->db->selectField(
1066 'actor',
'actor_name', [
'actor_id' => $user->getActorId() ], __METHOD__
1068 'User::saveSettings updates actor table for name change'
1072 $ip =
'192.168.12.34';
1073 $this->db->delete(
'actor', [
'actor_name' => $ip ], __METHOD__ );
1076 $this->
assertFalse( $user->getActorId() > 0,
'Anonymous user has no actor ID by default' );
1077 $this->
assertTrue( $user->getActorId( $this->db ) > 0,
1078 'Actor ID can be created for an anonymous user' );
1081 $this->
assertTrue( $user->getActorId() > 0,
'Actor ID can be loaded for an anonymous user' );
1083 $this->
assertEquals( $user->getName(), $user2->getName(),
1084 'User::newFromActorId works for an anonymous user' );
1102 $domain = MediaWikiServices::getInstance()->getDBLoadBalancer()->getLocalDomainID();
1107 $id = $user->getId();
1108 $this->
assertTrue( $user->getActorId() > 0,
'User::createNew sets an actor ID' );
1111 $user->addToDatabase();
1112 $this->
assertTrue( $user->getActorId() > 0,
'User::addToDatabase sets an actor ID' );
1115 $this->
assertTrue( $user->getActorId() > 0,
'Actor ID can be retrieved for user loaded by name' );
1118 $this->
assertTrue( $user->getActorId() > 0,
'Actor ID can be retrieved for user loaded by ID' );
1122 'User::newFromActorId works for an existing user' );
1124 $row = $this->db->selectRow(
'user',
User::selectFields(), [
'user_id' => $id ], __METHOD__ );
1127 'Actor ID can be retrieved for user loaded with User::selectFields()' );
1129 $this->db->delete(
'actor', [
'actor_user' => $id ], __METHOD__ );
1132 ObjectCache::getMainWANInstance()->clearProcessCache();
1135 $this->
assertFalse( $user->getActorId() > 0,
'No Actor ID by default if none in database' );
1136 $this->
assertTrue( $user->getActorId( $this->db ) > 0,
'Actor ID can be created if none in db' );
1138 $user->setName(
'UserTestActorIdOld4-renamed' );
1139 $user->saveSettings();
1142 $this->db->selectField(
1143 'actor',
'actor_name', [
'actor_id' => $user->getActorId() ], __METHOD__
1145 'User::saveSettings updates actor table for name change'
1149 $ip =
'192.168.12.34';
1150 $this->db->delete(
'actor', [
'actor_name' => $ip ], __METHOD__ );
1153 $this->
assertFalse( $user->getActorId() > 0,
'Anonymous user has no actor ID by default' );
1154 $this->
assertTrue( $user->getActorId( $this->db ) > 0,
1155 'Actor ID can be created for an anonymous user' );
1158 $this->
assertTrue( $user->getActorId() > 0,
'Actor ID can be loaded for an anonymous user' );
1160 $this->
assertEquals( $user->getName(), $user2->getName(),
1161 'User::newFromActorId works for an anonymous user' );
1170 for ( $i = 1; $i <= 7; $i++ ) {
1172 ( $i & 1 ) ? $user->getId() :
null,
1173 ( $i & 2 ) ? $user->getName() :
null,
1174 ( $i & 4 ) ? $user->getActorId() :
null
1176 $this->
assertSame( $user->getId(), $test->getId() );
1177 $this->
assertSame( $user->getName(), $test->getName() );
1178 $this->
assertSame( $user->getActorId(), $test->getActorId() );
1183 $user->getActorId( $this->db );
1186 $this->
assertSame( $user->getId(), $test->getId() );
1187 $this->
assertSame( $user->getName(), $test->getName() );
1188 $this->
assertSame( $user->getActorId(), $test->getActorId() );
1190 $this->
assertSame( $user->getId(), $test->getId() );
1191 $this->
assertSame( $user->getName(), $test->getName() );
1192 $this->
assertSame( $user->getActorId(), $test->getActorId() );
1198 $this->
assertSame(
'Bogus', $test->getName() );
1199 $this->
assertSame( 654321, $test->getActorId() );
1204 $this->fail(
'Expected exception not thrown' );
1205 }
catch ( InvalidArgumentException $ex ) {
1209 $this->fail(
'Expected exception not thrown' );
1210 }
catch ( InvalidArgumentException $ex ) {
1227 $this->
assertSame( $user->getId(), $result->getId(),
'ID' );
1228 $this->
assertSame( $user->getName(), $result->getName(),
'Name' );
1229 $this->
assertSame( $user->getActorId(), $result->getActorId(),
'Actor' );
1235 $this->
assertSame( $user->getId(), $result->getId(),
'ID' );
1236 $this->
assertSame( $user->getName(), $result->getName(),
'Name' );
1237 $this->
assertSame( $user->getActorId(), $result->getActorId(),
'Actor' );
1243 $this->
assertSame( $user->getId(), $result->getId(),
'ID' );
1244 $this->
assertSame( $user->getName(), $result->getName(),
'Name' );
1245 $this->
assertSame( $user->getActorId(), $result->getActorId(),
'Actor' );
1259 $ut = Title::makeTitle(
NS_USER_TALK, $user->getName() );
1260 $this->
assertNull( $user->getBlock(
false ),
'sanity check' );
1261 $this->
assertSame(
'', $user->blockedBy(),
'sanity check' );
1262 $this->
assertSame(
'', $user->blockedFor(),
'sanity check' );
1263 $this->
assertFalse( (
bool)$user->isHidden(),
'sanity check' );
1264 $this->
assertFalse( $user->isBlockedFrom( $ut ),
'sanity check' );
1268 $block =
new Block( [
1270 'allowUsertalk' =>
false,
1271 'reason' =>
'Because',
1273 $block->setTarget( $user );
1274 $block->setBlocker( $blocker );
1275 $res = $block->insert();
1276 $this->
assertTrue( (
bool)
$res[
'id'],
'sanity check: Failed to insert block' );
1279 $user->clearInstanceCache();
1281 $this->
assertSame( $blocker->getName(), $user->blockedBy() );
1282 $this->
assertSame(
'Because', $user->blockedFor() );
1283 $this->
assertTrue( (
bool)$user->isHidden() );
1284 $this->
assertTrue( $user->isBlockedFrom( $ut ) );
1290 $user->clearInstanceCache();
1291 $this->
assertNull( $user->getBlock(
false ) );
1293 $this->
assertSame(
'', $user->blockedFor() );
1295 $this->
assertFalse( $user->isBlockedFrom( $ut ) );
1310 'wgBlockAllowsUTEdit' =>
$options[
'blockAllowsUTEdit'] ??
true,
1315 if ( $title === self::USER_TALK_PAGE ) {
1316 $title = $user->getTalkPage();
1318 $title = Title::newFromText( $title );
1322 foreach (
$options[
'pageRestrictions'] ?? [] as $pagestr ) {
1324 $pagestr === self::USER_TALK_PAGE ? $user->getTalkPage() :
$pagestr
1328 foreach (
$options[
'namespaceRestrictions'] ?? [] as $ns ) {
1332 $block =
new Block( [
1334 'allowUsertalk' =>
$options[
'allowUsertalk'] ??
false,
1335 'sitewide' => !$restrictions,
1337 $block->setTarget( $user );
1338 $block->setBlocker( $this->
getTestSysop()->getUser() );
1339 if ( $restrictions ) {
1340 $block->setRestrictions( $restrictions );
1345 $this->
assertSame( $expect, $user->isBlockedFrom( $title ) );
1353 'Sitewide block, basic operation' => [
'Test page',
true ],
1354 'Sitewide block, not allowing user talk' => [
1356 'allowUsertalk' =>
false,
1359 'Sitewide block, allowing user talk' => [
1361 'allowUsertalk' =>
true,
1364 'Sitewide block, allowing user talk but $wgBlockAllowsUTEdit is false' => [
1366 'allowUsertalk' =>
true,
1367 'blockAllowsUTEdit' =>
false,
1370 'Partial block, blocking the page' => [
1371 'Test page',
true, [
1372 'pageRestrictions' => [
'Test page' ],
1375 'Partial block, not blocking the page' => [
1376 'Test page 2',
false, [
1377 'pageRestrictions' => [
'Test page' ],
1380 'Partial block, not allowing user talk but user talk page is not blocked' => [
1382 'allowUsertalk' =>
false,
1383 'pageRestrictions' => [
'Test page' ],
1386 'Partial block, allowing user talk but user talk page is blocked' => [
1388 'allowUsertalk' =>
true,
1392 'Partial block, user talk page is not blocked but $wgBlockAllowsUTEdit is false' => [
1394 'allowUsertalk' =>
false,
1395 'pageRestrictions' => [
'Test page' ],
1396 'blockAllowsUTEdit' =>
false,
1399 'Partial block, user talk page is blocked and $wgBlockAllowsUTEdit is false' => [
1401 'allowUsertalk' =>
true,
1403 'blockAllowsUTEdit' =>
false,
1406 'Partial user talk namespace block, not allowing user talk' => [
1408 'allowUsertalk' =>
false,
1412 'Partial user talk namespace block, allowing user talk' => [
1414 'allowUsertalk' =>
true,
1418 'Partial user talk namespace block, where $wgBlockAllowsUTEdit is false' => [
1420 'allowUsertalk' =>
true,
1422 'blockAllowsUTEdit' =>
false,
1435 'wgCookieSetOnIpBlock' =>
true,
1436 'wgCookiePrefix' =>
'wiki',
1441 $block =
new Block( [
1444 $block->setTarget(
'1.2.3.4' );
1445 $block->setBlocker( $this->
getTestSysop()->getUser() );
1454 $user->trackBlockWithCookie();
1457 $cookies =
$request->response()->getCookies();
1471 'wgCookieSetOnIpBlock' =>
false,
1472 'wgCookiePrefix' =>
'wiki',
1477 $block =
new Block( [
1480 $block->setTarget(
'1.2.3.4' );
1481 $block->setBlocker( $this->
getTestSysop()->getUser() );
1490 $user->trackBlockWithCookie();
1493 $cookies =
$request->response()->getCookies();
1507 'wgAutoblockExpiry' => 8000,
1508 'wgCookieSetOnIpBlock' =>
true,
1509 'wgCookiePrefix' =>
'wiki',
1514 $block =
new Block( [
1517 $block->setTarget(
'1.2.3.4' );
1518 $block->setBlocker( $this->
getTestSysop()->getUser() );
1525 $request->setCookie(
'BlockID', $block->getCookieValue() );
1534 $cookies =
$request->response()->getCookies();
1535 $this->
assertEquals(
'', $cookies[
'wikiBlockID'][
'value'] );
1546 $clock = MWTimestamp::convert( TS_UNIX,
'20100101000000' );
1547 MWTimestamp::setFakeTime(
function () use ( &$clock ) {
1548 return $clock += 1000;
1552 $firstRevision =
self::makeEdit( $user,
'Help:UserTest_GetEditTimestamp',
'one',
'test' );
1553 $secondRevision =
self::makeEdit( $user,
'Help:UserTest_GetEditTimestamp',
'two',
'test' );
1555 $this->
assertNotEquals( $firstRevision->getTimestamp(), $secondRevision->getTimestamp() );
1557 $this->
assertEquals( $firstRevision->getTimestamp(), $user->getFirstEditTimestamp() );
1558 $this->
assertEquals( $secondRevision->getTimestamp(), $user->getLatestEditTimestamp() );
1560 MWTimestamp::setFakeTime(
false );
1572 $page = WikiPage::factory( Title::newFromText( $title ) );
1574 $updater = $page->newPageUpdater( $user );
1576 return $updater->saveRevision( CommentStoreComment::newUnsavedComment( $comment ) );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
$wgDefaultUserOptions
Settings added to this array will override the default globals for the user preferences used by anony...
$wgRevokePermissions
Permission keys revoked from users in each group.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$wgGroupPermissions['sysop']['replacetext']
static getIdFromCookieValue( $cookieValue)
Get the stored ID from the 'BlockID' cookie.
WebRequest clone which takes values from a provided array.
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
testUserPermissions()
User::getRights.
testGetGroupsWithPermission( $expected, $right)
provideGetGroupsWithPermission User::getGroupsWithPermission
testIpBlockCookieSet()
Block cookie should be set for IP Blocks if wgCookieSetOnIpBlock is set to true User::trackBlockWithC...
testActorId_old()
Actor tests with SCHEMA_COMPAT_READ_OLD.
testExperienceLevelAnon()
User::getExperienceLevel.
testUserGetRightsHooks()
User::getRights.
testOptions()
Test changing user options.
const USER_TALK_PAGE
Constant for self::testIsBlockedFrom.
testGetFirstLatestEditTimestamp()
User::getFirstEditTimestamp User::getLatestEditTimestamp.
testGetCanonicalName( $name, $expectedArray)
User::getCanonicalName() provideGetCanonicalName.
testNewFromAnyId()
User::newFromAnyId.
testAutoblockCookies()
When a user is autoblocked a cookie is set with which to track them in case they log out and change I...
static makeEdit(User $user, $title, $content, $comment)
testAutoblockCookieInfiniteExpiry()
When a user is autoblocked and a cookie is set to track them, the expiry time of the cookie should ma...
testAutoblockCookieInauthentic()
Test that a modified BlockID cookie doesn't actually load the relevant block (T152951).
testExperienceLevel( $editCount, $memberSince, $expLevel)
User::getExperienceLevel provideExperienceLevel.
testIsPingLimitable()
User::isPingLimitable.
static provideGetGroupsWithPermission()
testIsValidUserName( $username, $result, $message)
provideUserNames User::isValidUserName
testIsIP( $value, $result, $message)
provideIPs User::isIP
testGetEditCount()
Test User::editCount medium User::getEditCount.
testAutoblockCookieNoSecretKey()
The BlockID cookie is normally verified with a HMAC, but not if wgSecretKey is not set.
testSoftBlockRanges()
User::getBlockedStatus.
static provideGetCanonicalName()
testAnonOptions()
T39963 Make sure defaults are loaded when setOption is called.
testIncEditCount()
Test User::editCount medium User::incEditCount.
testIpBlockCookieIgnoredWhenUserLoggedIn()
When an ip user is blocked and then they log in, cookie block should be invalid and the cookie remove...
testIpBlockCookieNotSet()
Block cookie should NOT be set when wgCookieSetOnIpBlock is disabled User::trackBlockWithCookie.
testGetEditCountForAnons()
Test User::editCount medium User::getEditCount.
testRevokePermissions()
User::getGroupPermissions.
static provideIsLocallBlockedProxy()
testNewFromIdentity()
User::newFromIdentity.
testEquals()
User::equals.
static provideIsBlockedFrom()
testCheckPasswordValidity()
Test password validity checks.
testIsLocallyBlockedProxy( $ip, $blockListEntry)
provideIsLocallBlockedProxy User::isLocallyBlockedProxy
testBlockInstanceCache()
User::getBlockedStatus User::getBlock User::blockedBy User::blockedFor User::isHidden User::isBlocked...
testCheckAndSetTouched()
User::checkAndSetTouched.
testLoggedIn()
User::isLoggedIn User::isAnon.
testAutoblockCookiesDisabled()
Make sure that no cookie is set to track autoblocked users when $wgCookieSetOnAutoblock is false.
testGroupPermissions()
User::getGroupPermissions.
testFindUsersByGroup()
User::findUsersByGroup.
testIsBlockedFrom( $title, $expect, array $options=[])
User::isBlockedFrom provideIsBlockedFrom.
testActorId()
User::newFromActorId.
static provideUserNames()
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getPasswordValidity( $password)
Given unvalidated password input, return error message on failure.
getName()
Get the user name, or the IP of an anonymous user.
getExperienceLevel()
Compute experienced level based on edit count and registration date.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
equals(UserIdentity $user)
Checks if two user objects point to the same user.
getId()
Get the user's ID.
static isLocallyBlockedProxy( $ip)
Check if an IP address is in the local proxy list.
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
static purge( $wikiId, $userId)
clearInstanceCache( $reloadFrom=false)
Clear various cached data stored in this object.
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
isPingLimitable()
Is this user subject to rate limiting?
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
static newFromId( $id)
Static factory method for creation from a given user ID.
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
static getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
static findUsersByGroup( $groups, $limit=5000, $after=null)
Return the users who are members of the given group(s).
static selectFields()
Return the list of user fields that should be selected to create a new user object.
isHidden()
Check if user account is hidden.
checkPasswordValidity( $password)
Check if this is a valid password for this user.
static newFromSession(WebRequest $request=null)
Create a new user object using data from session.
setOption( $oname, $val)
Set the given option for a user.
getEditCount()
Get the user's edit count.
getActorId(IDatabase $dbw=null)
Get the user's actor ID.
isValidPassword( $password)
Is the input a valid password for this user?
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
checkAndSetTouched()
Bump user_touched if it didn't change since this object was loaded.
getBlockId()
If user is blocked, return the ID for the block.
isLoggedIn()
Get whether the user is logged in.
blockedBy()
If user is blocked, return the name of the user who placed the block.
static createNew( $name, $params=[])
Add a user to the database, return the user object.
incEditCount()
Schedule a deferred update to update the user's edit count.
blockedFor()
If user is blocked, return the specified reason for the block.
getBlock( $fromReplica=true)
Get the block affecting the user, or null if the user is not blocked.
isBlocked( $fromReplica=true)
Check if user is blocked.
isAnon()
Get whether the user is anonymous.
isBlockedFrom( $title, $fromReplica=false)
Check if user is blocked from editing a particular article.
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
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
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
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
this hook is for auditing only or null if authentication failed before getting that far $username
processing should stop and the error should be shown to the user * false
const SCHEMA_COMPAT_WRITE_BOTH
const SCHEMA_COMPAT_READ_OLD
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$page->newPageUpdater($user) $updater