109 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
115 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
116 $this->assertEquals( [],
$res );
120 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
121 $this->assertEquals( [ [
"nocreatetext" ] ],
$res );
125 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
126 $this->assertEquals( [ [
'nocreatetext' ] ],
$res );
130 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
131 $this->assertEquals( [],
$res );
135 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
136 $this->assertEquals( [ [
'nocreatetext' ] ],
$res );
138 $this->
setUser( $this->userName );
141 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
142 $this->assertEquals( [],
$res );
146 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
147 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
151 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
152 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
156 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
157 $this->assertEquals( [],
$res );
161 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
162 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
166 $res = $this->title->getUserPermissionsErrors(
'create', $this->user );
167 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
170 $this->
setTitle( NS_USER, $this->userName .
'' );
172 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
173 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
175 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
177 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
178 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
180 $this->
setTitle( NS_USER, $this->userName .
'' );
182 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
183 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
185 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
187 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
188 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
190 $this->
setTitle( NS_USER, $this->userName .
'' );
192 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
193 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
195 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
197 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
198 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
200 $this->
setTitle( NS_USER, $this->userName .
'' );
202 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
203 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
205 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
207 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
208 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
210 $this->
setUser( $this->userName );
213 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
214 $this->assertEquals( [ [
'movenotallowedfile' ], [
'movenotallowed' ] ],
$res );
218 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
219 $this->assertEquals( [ [
'movenotallowed' ] ],
$res );
224 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
225 $this->assertEquals( [ [
'movenotallowedfile' ], [
'movenologintext' ] ],
$res );
229 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
230 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
232 $this->
setUser( $this->userName );
239 [ [
'movenotallowedfile' ], [
'movenotallowed' ] ]
249 [ [
'movenotallowedfile' ], [
'movenotallowed' ] ],
250 [ [
'movenotallowedfile' ], [
'movenologintext' ] ]
264 [ [
'movenologintext' ] ] );
266 $this->
setUser( $this->userName );
275 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
276 $this->assertEquals( [],
$res );
279 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
280 $this->assertEquals( [ [
'movenotallowed' ] ],
$res );
284 $this->
setUser( $this->userName );
285 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
286 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
287 $this->assertEquals( [],
$res );
290 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
291 $this->assertEquals( [ [
'cant-move-to-user-page' ] ],
$res );
294 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
295 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
296 $this->assertEquals( [],
$res );
298 $this->
setTitle( NS_USER,
"User/subpage" );
299 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
300 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
301 $this->assertEquals( [],
$res );
304 $res = $this->title->getUserPermissionsErrors(
'move-target', $this->user );
305 $this->assertEquals( [],
$res );
310 [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ] ],
311 [ [
'badaccess-group0' ] ],
318 "[[$prefix:Administrators|Administrators]]", 1 ],
321 [ [
'badaccess-group0' ], [
'protect-cantedit' ] ],
322 [ [
'protect-cantedit' ] ],
325 '' => [ [], [], [],
true ]
328 foreach ( [
"edit",
"protect",
"" ] as $action ) {
330 $this->assertEquals( $check[$action][0],
331 $this->title->getUserPermissionsErrors( $action, $this->user,
true ) );
332 $this->assertEquals( $check[$action][0],
333 $this->title->getUserPermissionsErrors( $action, $this->user,
'full' ) );
334 $this->assertEquals( $check[$action][0],
335 $this->title->getUserPermissionsErrors( $action, $this->user,
'secure' ) );
341 $this->assertEquals( $check[$action][1],
342 $this->title->getUserPermissionsErrors( $action, $this->user,
true ) );
343 $this->assertEquals( $check[$action][1],
344 $this->title->getUserPermissionsErrors( $action, $this->user,
'full' ) );
345 $this->assertEquals( $check[$action][1],
346 $this->title->getUserPermissionsErrors( $action, $this->user,
'secure' ) );
350 $this->assertEquals( $check[$action][2],
351 $this->title->getUserPermissionsErrors( $action, $this->user,
true ) );
352 $this->assertEquals( $check[$action][2],
353 $this->title->getUserPermissionsErrors( $action, $this->user,
'full' ) );
354 $this->assertEquals( $check[$action][2],
355 $this->title->getUserPermissionsErrors( $action, $this->user,
'secure' ) );
358 $this->assertEquals( $check[$action][3],
359 $this->title->userCan( $action, $this->user,
true ) );
360 $this->assertEquals( $check[$action][3],
361 $this->title->quickUserCan( $action, $this->user ) );
362 # count( User::getGroupsWithPermissions( $action ) ) < 1
646 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
647 $this->assertEquals( $resultNone, $result );
650 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
651 $this->assertEquals( $resultMyCss, $result );
654 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
655 $this->assertEquals( $resultMyJson, $result );
658 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
659 $this->assertEquals( $resultMyJs, $result );
662 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
663 $this->assertEquals( $resultUserCss, $result );
666 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
667 $this->assertEquals( $resultUserJson, $result );
670 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
671 $this->assertEquals( $resultUserJs, $result );
674 $result = $this->title->getUserPermissionsErrors(
'patrol', $this->user );
675 $this->assertEquals( reset( $resultPatrol[0] ), reset( $result[0] ) );
677 $this->
setUserPerm( [
'edituserjs',
'edituserjson',
'editusercss' ] );
678 $result = $this->title->getUserPermissionsErrors(
'bogus', $this->user );
679 $this->assertEquals( [ [
'badaccess-group0' ] ], $result );
692 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
696 $this->title->mRestrictionsLoaded =
true;
698 $this->title->mRestrictions = [
"bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
700 $this->assertEquals( [],
701 $this->title->getUserPermissionsErrors(
'edit',
704 $this->assertEquals(
true,
705 $this->title->quickUserCan(
'edit', $this->user ) );
706 $this->title->mRestrictions = [
"edit" => [
'bogus',
"sysop",
"protect",
"" ],
707 "bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
709 $this->assertEquals( [ [
'badaccess-group0' ],
710 [
'protectedpagetext',
'bogus',
'bogus' ],
711 [
'protectedpagetext',
'editprotected',
'bogus' ],
712 [
'protectedpagetext',
'protect',
'bogus' ] ],
713 $this->title->getUserPermissionsErrors(
'bogus',
715 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
716 [
'protectedpagetext',
'editprotected',
'edit' ],
717 [
'protectedpagetext',
'protect',
'edit' ] ],
718 $this->title->getUserPermissionsErrors(
'edit',
721 $this->assertEquals( [ [
'badaccess-group0' ],
722 [
'protectedpagetext',
'bogus',
'bogus' ],
723 [
'protectedpagetext',
'editprotected',
'bogus' ],
724 [
'protectedpagetext',
'protect',
'bogus' ] ],
725 $this->title->getUserPermissionsErrors(
'bogus',
727 $this->assertEquals( [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ],
728 [
'protectedpagetext',
'bogus',
'edit' ],
729 [
'protectedpagetext',
'editprotected',
'edit' ],
730 [
'protectedpagetext',
'protect',
'edit' ] ],
731 $this->title->getUserPermissionsErrors(
'edit',
734 $this->assertEquals( [ [
'badaccess-group0' ],
735 [
'protectedpagetext',
'bogus',
'bogus' ],
736 [
'protectedpagetext',
'protect',
'bogus' ] ],
737 $this->title->getUserPermissionsErrors(
'bogus',
739 $this->assertEquals( [
740 [
'protectedpagetext',
'bogus',
'edit' ],
741 [
'protectedpagetext',
'protect',
'edit' ] ],
742 $this->title->getUserPermissionsErrors(
'edit',
745 $this->title->mCascadeRestriction =
true;
747 $this->assertEquals(
false,
748 $this->title->quickUserCan(
'bogus', $this->user ) );
749 $this->assertEquals(
false,
750 $this->title->quickUserCan(
'edit', $this->user ) );
751 $this->assertEquals( [ [
'badaccess-group0' ],
752 [
'protectedpagetext',
'bogus',
'bogus' ],
753 [
'protectedpagetext',
'editprotected',
'bogus' ],
754 [
'protectedpagetext',
'protect',
'bogus' ] ],
755 $this->title->getUserPermissionsErrors(
'bogus',
757 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
758 [
'protectedpagetext',
'editprotected',
'edit' ],
759 [
'protectedpagetext',
'protect',
'edit' ] ],
760 $this->title->getUserPermissionsErrors(
'edit',
764 $this->assertEquals(
false,
765 $this->title->quickUserCan(
'bogus', $this->user ) );
766 $this->assertEquals(
false,
767 $this->title->quickUserCan(
'edit', $this->user ) );
768 $this->assertEquals( [ [
'badaccess-group0' ],
769 [
'protectedpagetext',
'bogus',
'bogus' ],
770 [
'protectedpagetext',
'protect',
'bogus' ],
771 [
'protectedpagetext',
'protect',
'bogus' ] ],
772 $this->title->getUserPermissionsErrors(
'bogus',
774 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
775 [
'protectedpagetext',
'protect',
'edit' ],
776 [
'protectedpagetext',
'protect',
'edit' ] ],
777 $this->title->getUserPermissionsErrors(
'edit',
818 $this->title->mTitleProtection[
'permission'] =
'';
819 $this->title->mTitleProtection[
'user'] = $this->user->getId();
820 $this->title->mTitleProtection[
'expiry'] =
'infinity';
821 $this->title->mTitleProtection[
'reason'] =
'test';
822 $this->title->mCascadeRestriction =
false;
824 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
825 $this->title->getUserPermissionsErrors(
'create', $this->user ) );
826 $this->assertEquals(
false,
827 $this->title->userCan(
'create', $this->user ) );
829 $this->title->mTitleProtection[
'permission'] =
'editprotected';
831 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
832 $this->title->getUserPermissionsErrors(
'create', $this->user ) );
833 $this->assertEquals(
false,
834 $this->title->userCan(
'create', $this->user ) );
836 $this->
setUserPerm( [
'createpage',
'editprotected' ] );
837 $this->assertEquals( [],
838 $this->title->getUserPermissionsErrors(
'create', $this->user ) );
839 $this->assertEquals(
true,
840 $this->title->userCan(
'create', $this->user ) );
843 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
844 $this->title->getUserPermissionsErrors(
'create', $this->user ) );
845 $this->assertEquals(
false,
846 $this->title->userCan(
'create', $this->user ) );
850 $this->assertEquals(
false,
851 $this->title->userCan(
'move', $this->user ) );
852 $this->assertEquals( [ [
'immobile-source-namespace',
'Media' ] ],
853 $this->title->getUserPermissionsErrors(
'move', $this->user ) );
856 $this->assertEquals( [],
857 $this->title->getUserPermissionsErrors(
'move', $this->user ) );
858 $this->assertEquals(
true,
859 $this->title->userCan(
'move', $this->user ) );
861 $this->title->mInterwiki =
"no";
862 $this->assertEquals( [ [
'immobile-source-page' ] ],
863 $this->title->getUserPermissionsErrors(
'move', $this->user ) );
864 $this->assertEquals(
false,
865 $this->title->userCan(
'move', $this->user ) );
868 $this->assertEquals(
false,
869 $this->title->userCan(
'move-target', $this->user ) );
870 $this->assertEquals( [ [
'immobile-target-namespace',
'Media' ] ],
871 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
874 $this->assertEquals( [],
875 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
876 $this->assertEquals(
true,
877 $this->title->userCan(
'move-target', $this->user ) );
879 $this->title->mInterwiki =
"no";
880 $this->assertEquals( [ [
'immobile-target-page' ] ],
881 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
882 $this->assertEquals(
false,
883 $this->title->userCan(
'move-target', $this->user ) );
891 'wgEmailConfirmToEdit' =>
true,
892 'wgEmailAuthentication' =>
true,
898 # $wgEmailConfirmToEdit only applies to 'edit' action
899 $this->assertEquals( [],
900 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
901 $this->assertContains( [
'confirmedittext' ],
902 $this->title->getUserPermissionsErrors(
'edit', $this->user ) );
905 $this->assertNotContains( [
'confirmedittext' ],
906 $this->title->getUserPermissionsErrors(
'edit', $this->user ) );
908 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
909 $this->assertEquals( [],
910 $this->title->getUserPermissionsErrors(
'move-target',
916 $this->user->mBlockedby = $this->user->getId();
917 $this->user->mBlock =
new Block( [
918 'address' =>
'127.0.8.1',
919 'by' => $this->user->getId(),
920 'reason' =>
'no reason given',
921 'timestamp' => $prev + 3600,
925 $this->user->mBlock->mTimestamp = 0;
926 $this->assertEquals( [ [
'autoblockedtext',
927 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
928 'Useruser',
null,
'infinite',
'127.0.8.1',
930 $this->title->getUserPermissionsErrors(
'move-target',
933 $this->assertEquals(
false, $this->title->userCan(
'move-target', $this->user ) );
935 $this->assertEquals(
true, $this->title->quickUserCan(
'move-target', $this->user ) );
939 $this->user->mBlockedby = $this->user->getName();
940 $this->user->mBlock =
new Block( [
941 'address' =>
'127.0.8.1',
942 'by' => $this->user->getId(),
943 'reason' =>
'no reason given',
948 $this->assertEquals( [ [
'blockedtext',
949 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
950 'Useruser',
null,
'23:00, 31 December 1969',
'127.0.8.1',
952 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
953 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
954 # $user->blockedFor() == ''
955 # $user->mBlock->mExpiry == 'infinity'
957 $this->user->mBlockedby = $this->user->getName();
958 $this->user->mBlock =
new Block( [
959 'address' =>
'127.0.8.1',
960 'by' => $this->user->getId(),
961 'reason' =>
'no reason given',
965 'systemBlock' =>
'test',
967 $this->assertEquals( [ [
'systemblockedtext',
968 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
969 'Useruser',
'test',
'23:00, 31 December 1969',
'127.0.8.1',
971 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );