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