MediaWiki  1.33.0
TitlePermissionTest.php
Go to the documentation of this file.
1 <?php
2 
5 
13 
17  protected $userName, $altUserName;
18 
22  protected $title;
23 
28 
29  protected function setUp() {
30  parent::setUp();
31 
32  $localZone = 'UTC';
33  $localOffset = date( 'Z' ) / 60;
34 
35  $this->setMwGlobals( [
36  'wgLocaltimezone' => $localZone,
37  'wgLocalTZoffset' => $localOffset,
38  'wgNamespaceProtection' => [
39  NS_MEDIAWIKI => 'editinterface',
40  ],
41  ] );
42  // Without this testUserBlock will use a non-English context on non-English MediaWiki
43  // installations (because of how Title::checkUserBlock is implemented) and fail.
45 
46  $this->userName = 'Useruser';
47  $this->altUserName = 'Altuseruser';
48  date_default_timezone_set( $localZone );
49 
50  $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
51  if ( !isset( $this->userUser ) || !( $this->userUser instanceof User ) ) {
52  $this->userUser = User::newFromName( $this->userName );
53 
54  if ( !$this->userUser->getId() ) {
55  $this->userUser = User::createNew( $this->userName, [
56  "email" => "test@example.com",
57  "real_name" => "Test User" ] );
58  $this->userUser->load();
59  }
60 
61  $this->altUser = User::newFromName( $this->altUserName );
62  if ( !$this->altUser->getId() ) {
63  $this->altUser = User::createNew( $this->altUserName, [
64  "email" => "alttest@example.com",
65  "real_name" => "Test User Alt" ] );
66  $this->altUser->load();
67  }
68 
69  $this->anonUser = User::newFromId( 0 );
70 
71  $this->user = $this->userUser;
72  }
73  $this->overrideMwServices();
74  }
75 
76  protected function setUserPerm( $perm ) {
77  // Setting member variables is evil!!!
78 
79  if ( is_array( $perm ) ) {
80  $this->user->mRights = $perm;
81  } else {
82  $this->user->mRights = [ $perm ];
83  }
84  }
85 
86  protected function setTitle( $ns, $title = "Main_Page" ) {
87  $this->title = Title::makeTitle( $ns, $title );
88  }
89 
90  protected function setUser( $userName = null ) {
91  if ( $userName === 'anon' ) {
92  $this->user = $this->anonUser;
93  } elseif ( $userName === null || $userName === $this->userName ) {
94  $this->user = $this->userUser;
95  } else {
96  $this->user = $this->altUser;
97  }
98  }
99 
109  public function testQuickPermissions() {
110  $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
111  getFormattedNsText( NS_PROJECT );
112 
113  $this->setUser( 'anon' );
114  $this->setTitle( NS_TALK );
115  $this->setUserPerm( "createtalk" );
116  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
117  $this->assertEquals( [], $res );
118 
119  $this->setTitle( NS_TALK );
120  $this->setUserPerm( "createpage" );
121  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
122  $this->assertEquals( [ [ "nocreatetext" ] ], $res );
123 
124  $this->setTitle( NS_TALK );
125  $this->setUserPerm( "" );
126  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
127  $this->assertEquals( [ [ 'nocreatetext' ] ], $res );
128 
129  $this->setTitle( NS_MAIN );
130  $this->setUserPerm( "createpage" );
131  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
132  $this->assertEquals( [], $res );
133 
134  $this->setTitle( NS_MAIN );
135  $this->setUserPerm( "createtalk" );
136  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
137  $this->assertEquals( [ [ 'nocreatetext' ] ], $res );
138 
139  $this->setUser( $this->userName );
140  $this->setTitle( NS_TALK );
141  $this->setUserPerm( "createtalk" );
142  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
143  $this->assertEquals( [], $res );
144 
145  $this->setTitle( NS_TALK );
146  $this->setUserPerm( "createpage" );
147  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
148  $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
149 
150  $this->setTitle( NS_TALK );
151  $this->setUserPerm( "" );
152  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
153  $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
154 
155  $this->setTitle( NS_MAIN );
156  $this->setUserPerm( "createpage" );
157  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
158  $this->assertEquals( [], $res );
159 
160  $this->setTitle( NS_MAIN );
161  $this->setUserPerm( "createtalk" );
162  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
163  $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
164 
165  $this->setTitle( NS_MAIN );
166  $this->setUserPerm( "" );
167  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
168  $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
169 
170  $this->setUser( 'anon' );
171  $this->setTitle( NS_USER, $this->userName . '' );
172  $this->setUserPerm( "" );
173  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
174  $this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
175 
176  $this->setTitle( NS_USER, $this->userName . '/subpage' );
177  $this->setUserPerm( "" );
178  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
179  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
180 
181  $this->setTitle( NS_USER, $this->userName . '' );
182  $this->setUserPerm( "move-rootuserpages" );
183  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
184  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
185 
186  $this->setTitle( NS_USER, $this->userName . '/subpage' );
187  $this->setUserPerm( "move-rootuserpages" );
188  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
189  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
190 
191  $this->setTitle( NS_USER, $this->userName . '' );
192  $this->setUserPerm( "" );
193  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
194  $this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
195 
196  $this->setTitle( NS_USER, $this->userName . '/subpage' );
197  $this->setUserPerm( "" );
198  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
199  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
200 
201  $this->setTitle( NS_USER, $this->userName . '' );
202  $this->setUserPerm( "move-rootuserpages" );
203  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
204  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
205 
206  $this->setTitle( NS_USER, $this->userName . '/subpage' );
207  $this->setUserPerm( "move-rootuserpages" );
208  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
209  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
210 
211  $this->setUser( $this->userName );
212  $this->setTitle( NS_FILE, "img.png" );
213  $this->setUserPerm( "" );
214  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
215  $this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ], $res );
216 
217  $this->setTitle( NS_FILE, "img.png" );
218  $this->setUserPerm( "movefile" );
219  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
220  $this->assertEquals( [ [ 'movenotallowed' ] ], $res );
221 
222  $this->setUser( 'anon' );
223  $this->setTitle( NS_FILE, "img.png" );
224  $this->setUserPerm( "" );
225  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
226  $this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenologintext' ] ], $res );
227 
228  $this->setTitle( NS_FILE, "img.png" );
229  $this->setUserPerm( "movefile" );
230  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
231  $this->assertEquals( [ [ 'movenologintext' ] ], $res );
232 
233  $this->setUser( $this->userName );
234  $this->setUserPerm( "move" );
235  $this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
236 
237  $this->setUserPerm( "" );
238  $this->runGroupPermissions(
239  'move',
240  [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ]
241  );
242 
243  $this->setUser( 'anon' );
244  $this->setUserPerm( "move" );
245  $this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
246 
247  $this->setUserPerm( "" );
248  $this->runGroupPermissions(
249  'move',
250  [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ],
251  [ [ 'movenotallowedfile' ], [ 'movenologintext' ] ]
252  );
253 
254  if ( $this->isWikitextNS( NS_MAIN ) ) {
255  // NOTE: some content models don't allow moving
256  // @todo find a Wikitext namespace for testing
257 
258  $this->setTitle( NS_MAIN );
259  $this->setUser( 'anon' );
260  $this->setUserPerm( "move" );
261  $this->runGroupPermissions( 'move', [] );
262 
263  $this->setUserPerm( "" );
264  $this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ],
265  [ [ 'movenologintext' ] ] );
266 
267  $this->setUser( $this->userName );
268  $this->setUserPerm( "" );
269  $this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ] );
270 
271  $this->setUserPerm( "move" );
272  $this->runGroupPermissions( 'move', [] );
273 
274  $this->setUser( 'anon' );
275  $this->setUserPerm( 'move' );
276  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
277  $this->assertEquals( [], $res );
278 
279  $this->setUserPerm( '' );
280  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
281  $this->assertEquals( [ [ 'movenotallowed' ] ], $res );
282  }
283 
284  $this->setTitle( NS_USER );
285  $this->setUser( $this->userName );
286  $this->setUserPerm( [ "move", "move-rootuserpages" ] );
287  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
288  $this->assertEquals( [], $res );
289 
290  $this->setUserPerm( "move" );
291  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
292  $this->assertEquals( [ [ 'cant-move-to-user-page' ] ], $res );
293 
294  $this->setUser( 'anon' );
295  $this->setUserPerm( [ "move", "move-rootuserpages" ] );
296  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
297  $this->assertEquals( [], $res );
298 
299  $this->setTitle( NS_USER, "User/subpage" );
300  $this->setUserPerm( [ "move", "move-rootuserpages" ] );
301  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
302  $this->assertEquals( [], $res );
303 
304  $this->setUserPerm( "move" );
305  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
306  $this->assertEquals( [], $res );
307 
308  $this->setUser( 'anon' );
309  $check = [
310  'edit' => [
311  [ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ] ],
312  [ [ 'badaccess-group0' ] ],
313  [],
314  true
315  ],
316  'protect' => [
317  [ [
318  'badaccess-groups',
319  "[[$prefix:Administrators|Administrators]]", 1 ],
320  [ 'protect-cantedit'
321  ] ],
322  [ [ 'badaccess-group0' ], [ 'protect-cantedit' ] ],
323  [ [ 'protect-cantedit' ] ],
324  false
325  ],
326  '' => [ [], [], [], true ]
327  ];
328 
329  foreach ( [ "edit", "protect", "" ] as $action ) {
330  $this->setUserPerm( null );
331  $this->assertEquals( $check[$action][0],
332  $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
333  $this->assertEquals( $check[$action][0],
334  $this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
335  $this->assertEquals( $check[$action][0],
336  $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
337 
338  global $wgGroupPermissions;
339  $old = $wgGroupPermissions;
340  $wgGroupPermissions = [];
341 
342  $this->assertEquals( $check[$action][1],
343  $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
344  $this->assertEquals( $check[$action][1],
345  $this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
346  $this->assertEquals( $check[$action][1],
347  $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
348  $wgGroupPermissions = $old;
349 
350  $this->setUserPerm( $action );
351  $this->assertEquals( $check[$action][2],
352  $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
353  $this->assertEquals( $check[$action][2],
354  $this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
355  $this->assertEquals( $check[$action][2],
356  $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
357 
358  $this->setUserPerm( $action );
359  $this->assertEquals( $check[$action][3],
360  $this->title->userCan( $action, $this->user, true ) );
361  $this->assertEquals( $check[$action][3],
362  $this->title->quickUserCan( $action, $this->user ) );
363  # count( User::getGroupsWithPermissions( $action ) ) < 1
364  }
365  }
366 
367  protected function runGroupPermissions( $action, $result, $result2 = null ) {
368  global $wgGroupPermissions;
369 
370  if ( $result2 === null ) {
371  $result2 = $result;
372  }
373 
374  $wgGroupPermissions['autoconfirmed']['move'] = false;
375  $wgGroupPermissions['user']['move'] = false;
376  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
377  $this->assertEquals( $result, $res );
378 
379  $wgGroupPermissions['autoconfirmed']['move'] = true;
380  $wgGroupPermissions['user']['move'] = false;
381  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
382  $this->assertEquals( $result2, $res );
383 
384  $wgGroupPermissions['autoconfirmed']['move'] = true;
385  $wgGroupPermissions['user']['move'] = true;
386  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
387  $this->assertEquals( $result2, $res );
388 
389  $wgGroupPermissions['autoconfirmed']['move'] = false;
390  $wgGroupPermissions['user']['move'] = true;
391  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
392  $this->assertEquals( $result2, $res );
393  }
394 
400  public function testSpecialsAndNSPermissions() {
401  global $wgNamespaceProtection;
402  $this->setUser( $this->userName );
403 
404  $this->setTitle( NS_SPECIAL );
405 
406  $this->assertEquals( [ [ 'badaccess-group0' ], [ 'ns-specialprotected' ] ],
407  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
408 
409  $this->setTitle( NS_MAIN );
410  $this->setUserPerm( 'bogus' );
411  $this->assertEquals( [],
412  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
413 
414  $this->setTitle( NS_MAIN );
415  $this->setUserPerm( '' );
416  $this->assertEquals( [ [ 'badaccess-group0' ] ],
417  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
418 
419  $wgNamespaceProtection[NS_USER] = [ 'bogus' ];
420 
421  $this->setTitle( NS_USER );
422  $this->setUserPerm( '' );
423  $this->assertEquals( [ [ 'badaccess-group0' ],
424  [ 'namespaceprotected', 'User', 'bogus' ] ],
425  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
426 
427  $this->setTitle( NS_MEDIAWIKI );
428  $this->setUserPerm( 'bogus' );
429  $this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
430  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
431 
432  $this->setTitle( NS_MEDIAWIKI );
433  $this->setUserPerm( 'bogus' );
434  $this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
435  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
436 
437  $wgNamespaceProtection = null;
438 
439  $this->setUserPerm( 'bogus' );
440  $this->assertEquals( [],
441  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
442  $this->assertEquals( true,
443  $this->title->userCan( 'bogus', $this->user ) );
444 
445  $this->setUserPerm( '' );
446  $this->assertEquals( [ [ 'badaccess-group0' ] ],
447  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
448  $this->assertEquals( false,
449  $this->title->userCan( 'bogus', $this->user ) );
450  }
451 
457  public function testJsConfigEditPermissions() {
458  $this->setUser( $this->userName );
459 
460  $this->setTitle( NS_USER, $this->userName . '/test.js' );
462  [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
463 
464  [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
465  [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
466  [ [ 'badaccess-group0' ] ],
467 
468  [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
469  [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
470  [ [ 'badaccess-group0' ] ],
471  [ [ 'badaccess-groups' ] ]
472  );
473  }
474 
480  public function testJsonConfigEditPermissions() {
481  $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
482  getFormattedNsText( NS_PROJECT );
483  $this->setUser( $this->userName );
484 
485  $this->setTitle( NS_USER, $this->userName . '/test.json' );
487  [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
488 
489  [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
490  [ [ 'badaccess-group0' ] ],
491  [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
492 
493  [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
494  [ [ 'badaccess-group0' ] ],
495  [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
496  [ [ 'badaccess-groups' ] ]
497  );
498  }
499 
505  public function testCssConfigEditPermissions() {
506  $this->setUser( $this->userName );
507 
508  $this->setTitle( NS_USER, $this->userName . '/test.css' );
510  [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
511 
512  [ [ 'badaccess-group0' ] ],
513  [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
514  [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
515 
516  [ [ 'badaccess-group0' ] ],
517  [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
518  [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
519  [ [ 'badaccess-groups' ] ]
520  );
521  }
522 
529  $this->setUser( $this->userName );
530 
531  $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
533  [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
534 
535  [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
536  [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
537  [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
538 
539  [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
540  [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
541  [ [ 'badaccess-group0' ] ],
542  [ [ 'badaccess-groups' ] ]
543  );
544  }
545 
552  $this->setUser( $this->userName );
553 
554  $this->setTitle( NS_USER, $this->altUserName . '/test.json' );
556  [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
557 
558  [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
559  [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
560  [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
561 
562  [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
563  [ [ 'badaccess-group0' ] ],
564  [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
565  [ [ 'badaccess-groups' ] ]
566  );
567  }
568 
575  $this->setUser( $this->userName );
576 
577  $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
579  [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
580 
581  [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
582  [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
583  [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
584 
585  [ [ 'badaccess-group0' ] ],
586  [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
587  [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
588  [ [ 'badaccess-groups' ] ]
589  );
590  }
591 
598  $this->setUser( $this->userName );
599 
600  $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
602  [ [ 'badaccess-group0' ] ],
603 
604  [ [ 'badaccess-group0' ] ],
605  [ [ 'badaccess-group0' ] ],
606  [ [ 'badaccess-group0' ] ],
607 
608  [ [ 'badaccess-group0' ] ],
609  [ [ 'badaccess-group0' ] ],
610  [ [ 'badaccess-group0' ] ],
611  [ [ 'badaccess-groups' ] ]
612  );
613  }
614 
620  $this->setUser( 'anon' );
621  $this->setTitle( NS_USER, 'ToPatrolOrNotToPatrol' );
623  [ [ 'badaccess-group0' ] ],
624 
625  [ [ 'badaccess-group0' ] ],
626  [ [ 'badaccess-group0' ] ],
627  [ [ 'badaccess-group0' ] ],
628 
629  [ [ 'badaccess-group0' ] ],
630  [ [ 'badaccess-group0' ] ],
631  [ [ 'badaccess-group0' ] ],
632  [ [ 'badaccess-groups' ] ]
633  );
634  }
635 
636  protected function runConfigEditPermissions(
637  $resultNone,
638  $resultMyCss,
639  $resultMyJson,
640  $resultMyJs,
641  $resultUserCss,
642  $resultUserJson,
643  $resultUserJs,
644  $resultPatrol
645  ) {
646  $this->setUserPerm( '' );
647  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
648  $this->assertEquals( $resultNone, $result );
649 
650  $this->setUserPerm( 'editmyusercss' );
651  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
652  $this->assertEquals( $resultMyCss, $result );
653 
654  $this->setUserPerm( 'editmyuserjson' );
655  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
656  $this->assertEquals( $resultMyJson, $result );
657 
658  $this->setUserPerm( 'editmyuserjs' );
659  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
660  $this->assertEquals( $resultMyJs, $result );
661 
662  $this->setUserPerm( 'editusercss' );
663  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
664  $this->assertEquals( $resultUserCss, $result );
665 
666  $this->setUserPerm( 'edituserjson' );
667  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
668  $this->assertEquals( $resultUserJson, $result );
669 
670  $this->setUserPerm( 'edituserjs' );
671  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
672  $this->assertEquals( $resultUserJs, $result );
673 
674  $this->setUserPerm( '' );
675  $result = $this->title->getUserPermissionsErrors( 'patrol', $this->user );
676  $this->assertEquals( reset( $resultPatrol[0] ), reset( $result[0] ) );
677 
678  $this->setUserPerm( [ 'edituserjs', 'edituserjson', 'editusercss' ] );
679  $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
680  $this->assertEquals( [ [ 'badaccess-group0' ] ], $result );
681  }
682 
692  public function testPageRestrictions() {
693  $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
694  getFormattedNsText( NS_PROJECT );
695 
696  $this->setTitle( NS_MAIN );
697  $this->title->mRestrictionsLoaded = true;
698  $this->setUserPerm( "edit" );
699  $this->title->mRestrictions = [ "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
700 
701  $this->assertEquals( [],
702  $this->title->getUserPermissionsErrors( 'edit',
703  $this->user ) );
704 
705  $this->assertEquals( true,
706  $this->title->quickUserCan( 'edit', $this->user ) );
707  $this->title->mRestrictions = [ "edit" => [ 'bogus', "sysop", "protect", "" ],
708  "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
709 
710  $this->assertEquals( [ [ 'badaccess-group0' ],
711  [ 'protectedpagetext', 'bogus', 'bogus' ],
712  [ 'protectedpagetext', 'editprotected', 'bogus' ],
713  [ 'protectedpagetext', 'protect', 'bogus' ] ],
714  $this->title->getUserPermissionsErrors( 'bogus',
715  $this->user ) );
716  $this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
717  [ 'protectedpagetext', 'editprotected', 'edit' ],
718  [ 'protectedpagetext', 'protect', 'edit' ] ],
719  $this->title->getUserPermissionsErrors( 'edit',
720  $this->user ) );
721  $this->setUserPerm( "" );
722  $this->assertEquals( [ [ 'badaccess-group0' ],
723  [ 'protectedpagetext', 'bogus', 'bogus' ],
724  [ 'protectedpagetext', 'editprotected', 'bogus' ],
725  [ 'protectedpagetext', 'protect', 'bogus' ] ],
726  $this->title->getUserPermissionsErrors( 'bogus',
727  $this->user ) );
728  $this->assertEquals( [ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ],
729  [ 'protectedpagetext', 'bogus', 'edit' ],
730  [ 'protectedpagetext', 'editprotected', 'edit' ],
731  [ 'protectedpagetext', 'protect', 'edit' ] ],
732  $this->title->getUserPermissionsErrors( 'edit',
733  $this->user ) );
734  $this->setUserPerm( [ "edit", "editprotected" ] );
735  $this->assertEquals( [ [ 'badaccess-group0' ],
736  [ 'protectedpagetext', 'bogus', 'bogus' ],
737  [ 'protectedpagetext', 'protect', 'bogus' ] ],
738  $this->title->getUserPermissionsErrors( 'bogus',
739  $this->user ) );
740  $this->assertEquals( [
741  [ 'protectedpagetext', 'bogus', 'edit' ],
742  [ 'protectedpagetext', 'protect', 'edit' ] ],
743  $this->title->getUserPermissionsErrors( 'edit',
744  $this->user ) );
745 
746  $this->title->mCascadeRestriction = true;
747  $this->setUserPerm( "edit" );
748  $this->assertEquals( false,
749  $this->title->quickUserCan( 'bogus', $this->user ) );
750  $this->assertEquals( false,
751  $this->title->quickUserCan( 'edit', $this->user ) );
752  $this->assertEquals( [ [ 'badaccess-group0' ],
753  [ 'protectedpagetext', 'bogus', 'bogus' ],
754  [ 'protectedpagetext', 'editprotected', 'bogus' ],
755  [ 'protectedpagetext', 'protect', 'bogus' ] ],
756  $this->title->getUserPermissionsErrors( 'bogus',
757  $this->user ) );
758  $this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
759  [ 'protectedpagetext', 'editprotected', 'edit' ],
760  [ 'protectedpagetext', 'protect', 'edit' ] ],
761  $this->title->getUserPermissionsErrors( 'edit',
762  $this->user ) );
763 
764  $this->setUserPerm( [ "edit", "editprotected" ] );
765  $this->assertEquals( false,
766  $this->title->quickUserCan( 'bogus', $this->user ) );
767  $this->assertEquals( false,
768  $this->title->quickUserCan( 'edit', $this->user ) );
769  $this->assertEquals( [ [ 'badaccess-group0' ],
770  [ 'protectedpagetext', 'bogus', 'bogus' ],
771  [ 'protectedpagetext', 'protect', 'bogus' ],
772  [ 'protectedpagetext', 'protect', 'bogus' ] ],
773  $this->title->getUserPermissionsErrors( 'bogus',
774  $this->user ) );
775  $this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
776  [ 'protectedpagetext', 'protect', 'edit' ],
777  [ 'protectedpagetext', 'protect', 'edit' ] ],
778  $this->title->getUserPermissionsErrors( 'edit',
779  $this->user ) );
780  }
781 
786  $this->setTitle( NS_MAIN, "test page" );
787  $this->setUserPerm( [ "edit", "bogus" ] );
788 
789  $this->title->mCascadeSources = [
790  Title::makeTitle( NS_MAIN, "Bogus" ),
791  Title::makeTitle( NS_MAIN, "UnBogus" )
792  ];
793  $this->title->mCascadingRestrictions = [
794  "bogus" => [ 'bogus', "sysop", "protect", "" ]
795  ];
796 
797  $this->assertEquals( false,
798  $this->title->userCan( 'bogus', $this->user ) );
799  $this->assertEquals( [
800  [ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
801  [ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
802  [ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ] ],
803  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
804 
805  $this->assertEquals( true,
806  $this->title->userCan( 'edit', $this->user ) );
807  $this->assertEquals( [],
808  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
809  }
810 
816  public function testActionPermissions() {
817  $this->setUserPerm( [ "createpage" ] );
818  $this->setTitle( NS_MAIN, "test page" );
819  $this->title->mTitleProtection['permission'] = '';
820  $this->title->mTitleProtection['user'] = $this->user->getId();
821  $this->title->mTitleProtection['expiry'] = 'infinity';
822  $this->title->mTitleProtection['reason'] = 'test';
823  $this->title->mCascadeRestriction = false;
824 
825  $this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
826  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
827  $this->assertEquals( false,
828  $this->title->userCan( 'create', $this->user ) );
829 
830  $this->title->mTitleProtection['permission'] = 'editprotected';
831  $this->setUserPerm( [ 'createpage', 'protect' ] );
832  $this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
833  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
834  $this->assertEquals( false,
835  $this->title->userCan( 'create', $this->user ) );
836 
837  $this->setUserPerm( [ 'createpage', 'editprotected' ] );
838  $this->assertEquals( [],
839  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
840  $this->assertEquals( true,
841  $this->title->userCan( 'create', $this->user ) );
842 
843  $this->setUserPerm( [ 'createpage' ] );
844  $this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
845  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
846  $this->assertEquals( false,
847  $this->title->userCan( 'create', $this->user ) );
848 
849  $this->setTitle( NS_MEDIA, "test page" );
850  $this->setUserPerm( [ "move" ] );
851  $this->assertEquals( false,
852  $this->title->userCan( 'move', $this->user ) );
853  $this->assertEquals( [ [ 'immobile-source-namespace', 'Media' ] ],
854  $this->title->getUserPermissionsErrors( 'move', $this->user ) );
855 
856  $this->setTitle( NS_HELP, "test page" );
857  $this->assertEquals( [],
858  $this->title->getUserPermissionsErrors( 'move', $this->user ) );
859  $this->assertEquals( true,
860  $this->title->userCan( 'move', $this->user ) );
861 
862  $this->title->mInterwiki = "no";
863  $this->assertEquals( [ [ 'immobile-source-page' ] ],
864  $this->title->getUserPermissionsErrors( 'move', $this->user ) );
865  $this->assertEquals( false,
866  $this->title->userCan( 'move', $this->user ) );
867 
868  $this->setTitle( NS_MEDIA, "test page" );
869  $this->assertEquals( false,
870  $this->title->userCan( 'move-target', $this->user ) );
871  $this->assertEquals( [ [ 'immobile-target-namespace', 'Media' ] ],
872  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
873 
874  $this->setTitle( NS_HELP, "test page" );
875  $this->assertEquals( [],
876  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
877  $this->assertEquals( true,
878  $this->title->userCan( 'move-target', $this->user ) );
879 
880  $this->title->mInterwiki = "no";
881  $this->assertEquals( [ [ 'immobile-target-page' ] ],
882  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
883  $this->assertEquals( false,
884  $this->title->userCan( 'move-target', $this->user ) );
885  }
886 
890  public function testUserBlock() {
891  $this->setMwGlobals( [
892  'wgEmailConfirmToEdit' => true,
893  'wgEmailAuthentication' => true,
894  ] );
895  $this->overrideMwServices();
896 
897  $this->setUserPerm( [ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ] );
898  $this->setTitle( NS_HELP, "test page" );
899 
900  # $wgEmailConfirmToEdit only applies to 'edit' action
901  $this->assertEquals( [],
902  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
903  $this->assertContains( [ 'confirmedittext' ],
904  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
905 
906  $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
907  $this->overrideMwServices();
908 
909  $this->assertNotContains( [ 'confirmedittext' ],
910  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
911 
912  # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
913  $this->assertEquals( [],
914  $this->title->getUserPermissionsErrors( 'move-target',
915  $this->user ) );
916 
917  global $wgLang;
918  $prev = time();
919  $now = time() + 120;
920  $this->user->mBlockedby = $this->user->getId();
921  $this->user->mBlock = new Block( [
922  'address' => '127.0.8.1',
923  'by' => $this->user->getId(),
924  'reason' => 'no reason given',
925  'timestamp' => $prev + 3600,
926  'auto' => true,
927  'expiry' => 0
928  ] );
929  $this->user->mBlock->setTimestamp( 0 );
930  $this->assertEquals( [ [ 'autoblockedtext',
931  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
932  'Useruser', null, 'infinite', '127.0.8.1',
933  $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ],
934  $this->title->getUserPermissionsErrors( 'move-target',
935  $this->user ) );
936 
937  $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
938  // quickUserCan should ignore user blocks
939  $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
940 
941  global $wgLocalTZoffset;
942  $wgLocalTZoffset = -60;
943  $this->user->mBlockedby = $this->user->getName();
944  $this->user->mBlock = new Block( [
945  'address' => '127.0.8.1',
946  'by' => $this->user->getId(),
947  'reason' => 'no reason given',
948  'timestamp' => $now,
949  'auto' => false,
950  'expiry' => 10,
951  ] );
952  $this->assertEquals( [ [ 'blockedtext',
953  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
954  'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
955  $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ],
956  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
957  # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
958  # $user->blockedFor() == ''
959  # $user->mBlock->mExpiry == 'infinity'
960 
961  $this->user->mBlockedby = $this->user->getName();
962  $this->user->mBlock = new Block( [
963  'address' => '127.0.8.1',
964  'by' => $this->user->getId(),
965  'reason' => 'no reason given',
966  'timestamp' => $now,
967  'auto' => false,
968  'expiry' => 10,
969  'systemBlock' => 'test',
970  ] );
971 
972  $errors = [ [ 'systemblockedtext',
973  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
974  'Useruser', 'test', '23:00, 31 December 1969', '127.0.8.1',
975  $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
976 
977  $this->assertEquals( $errors,
978  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
979  $this->assertEquals( $errors,
980  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
981  $this->assertEquals( $errors,
982  $this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
983  $this->assertEquals( $errors,
984  $this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
985  $this->assertEquals( $errors,
986  $this->title->getUserPermissionsErrors( 'upload', $this->user ) );
987  $this->assertEquals( [],
988  $this->title->getUserPermissionsErrors( 'purge', $this->user ) );
989 
990  // partial block message test
991  $this->user->mBlockedby = $this->user->getName();
992  $this->user->mBlock = new Block( [
993  'address' => '127.0.8.1',
994  'by' => $this->user->getId(),
995  'reason' => 'no reason given',
996  'timestamp' => $now,
997  'sitewide' => false,
998  'expiry' => 10,
999  ] );
1000 
1001  $this->assertEquals( [],
1002  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
1003  $this->assertEquals( [],
1004  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
1005  $this->assertEquals( [],
1006  $this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
1007  $this->assertEquals( [],
1008  $this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
1009  $this->assertEquals( [],
1010  $this->title->getUserPermissionsErrors( 'upload', $this->user ) );
1011  $this->assertEquals( [],
1012  $this->title->getUserPermissionsErrors( 'purge', $this->user ) );
1013 
1014  $this->user->mBlock->setRestrictions( [
1015  ( new PageRestriction( 0, $this->title->getArticleID() ) )->setTitle( $this->title ),
1016  ] );
1017 
1018  $errors = [ [ 'blockedtext-partial',
1019  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
1020  'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
1021  $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
1022 
1023  $this->assertEquals( $errors,
1024  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
1025  $this->assertEquals( $errors,
1026  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
1027  $this->assertEquals( $errors,
1028  $this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
1029  $this->assertEquals( $errors,
1030  $this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
1031  $this->assertEquals( [],
1032  $this->title->getUserPermissionsErrors( 'upload', $this->user ) );
1033  $this->assertEquals( [],
1034  $this->title->getUserPermissionsErrors( 'purge', $this->user ) );
1035 
1036  // Test no block.
1037  $this->user->mBlockedby = null;
1038  $this->user->mBlock = null;
1039 
1040  $this->assertEquals( [],
1041  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
1042  }
1043 
1050  public function testUserBlockAction() {
1051  global $wgLang;
1052 
1053  $tester = $this->getMockBuilder( Action::class )
1054  ->disableOriginalConstructor()
1055  ->getMock();
1056  $tester->method( 'getName' )
1057  ->willReturn( 'tester' );
1058  $tester->method( 'getRestriction' )
1059  ->willReturn( 'test' );
1060  $tester->method( 'requiresUnblock' )
1061  ->willReturn( false );
1062 
1063  $this->setMwGlobals( [
1064  'wgActions' => [
1065  'tester' => $tester,
1066  ],
1067  'wgGroupPermissions' => [
1068  '*' => [
1069  'tester' => true,
1070  ],
1071  ],
1072  ] );
1073 
1074  $now = time();
1075  $this->user->mBlockedby = $this->user->getName();
1076  $this->user->mBlock = new Block( [
1077  'address' => '127.0.8.1',
1078  'by' => $this->user->getId(),
1079  'reason' => 'no reason given',
1080  'timestamp' => $now,
1081  'auto' => false,
1082  'expiry' => 'infinity',
1083  ] );
1084 
1085  $errors = [ [ 'blockedtext',
1086  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
1087  'Useruser', null, 'infinite', '127.0.8.1',
1088  $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
1089 
1090  $this->assertEquals( $errors,
1091  $this->title->getUserPermissionsErrors( 'tester', $this->user ) );
1092  }
1093 }
TitlePermissionTest\setUser
setUser( $userName=null)
Definition: TitlePermissionTest.php:90
TitlePermissionTest\testOtherCssConfigEditPermissions
testOtherCssConfigEditPermissions()
Definition: TitlePermissionTest.php:574
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:609
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
NS_HELP
const NS_HELP
Definition: Defines.php:76
TitlePermissionTest\testUserBlockAction
testUserBlockAction()
\MediaWiki\Permissions\PermissionManager::checkUserBlock
Definition: TitlePermissionTest.php:1050
TitlePermissionTest\setTitle
setTitle( $ns, $title="Main_Page")
Definition: TitlePermissionTest.php:86
TitlePermissionTest\$anonUser
User $anonUser
Definition: TitlePermissionTest.php:27
MediaWikiTestCase\isWikitextNS
isWikitextNS( $ns)
Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
Definition: MediaWikiTestCase.php:2194
TitlePermissionTest\testOtherJsonConfigEditPermissions
testOtherJsonConfigEditPermissions()
Definition: TitlePermissionTest.php:551
$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 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name '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. '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 '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 since 1.28! 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:1983
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
TitlePermissionTest\runConfigEditPermissions
runConfigEditPermissions( $resultNone, $resultMyCss, $resultMyJson, $resultMyJs, $resultUserCss, $resultUserJson, $resultUserJs, $resultPatrol)
Definition: TitlePermissionTest.php:636
TitlePermissionTest\testCascadingSourcesRestrictions
testCascadingSourcesRestrictions()
\MediaWiki\Permissions\PermissionManager::checkCascadingSourcesRestrictions
Definition: TitlePermissionTest.php:785
NS_FILE
const NS_FILE
Definition: Defines.php:70
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
$res
$res
Definition: database.txt:21
TitlePermissionTest\testJsonConfigEditPermissions
testJsonConfigEditPermissions()
Definition: TitlePermissionTest.php:480
TitlePermissionTest\testSpecialsAndNSPermissions
testSpecialsAndNSPermissions()
Definition: TitlePermissionTest.php:400
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\createNew
static createNew( $name, $params=[])
Add a user to the database, return the user object.
Definition: User.php:4303
MediaWikiTestCase\overrideMwServices
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
Definition: MediaWikiTestCase.php:937
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
TitlePermissionTest\testOtherJsConfigEditPermissions
testOtherJsConfigEditPermissions()
Definition: TitlePermissionTest.php:528
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:68
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
TitlePermissionTest\runGroupPermissions
runGroupPermissions( $action, $result, $result2=null)
Definition: TitlePermissionTest.php:367
TitlePermissionTest\$title
Title $title
Definition: TitlePermissionTest.php:22
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
$wgLang
$wgLang
Definition: Setup.php:875
TitlePermissionTest\testJsConfigEditPermissions
testJsConfigEditPermissions()
Definition: TitlePermissionTest.php:457
TitlePermissionTest\setUserPerm
setUserPerm( $perm)
Definition: TitlePermissionTest.php:76
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
TitlePermissionTest\testUserBlock
testUserBlock()
\MediaWiki\Permissions\PermissionManager::checkUserBlock
Definition: TitlePermissionTest.php:890
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
TitlePermissionTest\testPageRestrictions
testPageRestrictions()
Definition: TitlePermissionTest.php:692
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:5334
TitlePermissionTest
Database.
Definition: TitlePermissionTest.php:12
TitlePermissionTest\testOtherNonConfigEditPermissions
testOtherNonConfigEditPermissions()
Definition: TitlePermissionTest.php:597
RequestContext\resetMain
static resetMain()
Resets singleton returned by getMain().
Definition: RequestContext.php:456
$wgLocalTZoffset
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
Definition: DefaultSettings.php:3195
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
title
title
Definition: parserTests.txt:245
TitlePermissionTest\$altUser
User $altUser
Definition: TitlePermissionTest.php:27
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
TitlePermissionTest\testActionPermissions
testActionPermissions()
Definition: TitlePermissionTest.php:816
TitlePermissionTest\testPatrolActionConfigEditPermissions
testPatrolActionConfigEditPermissions()
Definition: TitlePermissionTest.php:619
TitlePermissionTest\setUp
setUp()
Definition: TitlePermissionTest.php:29
Title
Represents a title within MediaWiki.
Definition: Title.php:40
TitlePermissionTest\testQuickPermissions
testQuickPermissions()
Definition: TitlePermissionTest.php:109
MediaWiki\Block\Restriction\PageRestriction
Definition: PageRestriction.php:25
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:31
NS_USER
const NS_USER
Definition: Defines.php:66
TitlePermissionTest\$userName
string $userName
Definition: TitlePermissionTest.php:17
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1985
NS_TALK
const NS_TALK
Definition: Defines.php:65
TitlePermissionTest\testCssConfigEditPermissions
testCssConfigEditPermissions()
Definition: TitlePermissionTest.php:505
TitlePermissionTest\$user
User $user
Definition: TitlePermissionTest.php:27
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
$wgGroupPermissions
$wgGroupPermissions['sysop']['replacetext']
Definition: ReplaceText.php:56
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
TitlePermissionTest\$altUserName
string $altUserName
Definition: TitlePermissionTest.php:17
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
TitlePermissionTest\$userUser
User $userUser
Definition: TitlePermissionTest.php:27