MediaWiki  master
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  'wgBlockDisablesLogin' => false,
895  ] );
896  $this->overrideMwServices();
897 
898  $this->setUserPerm( [ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ] );
899  $this->setTitle( NS_HELP, "test page" );
900 
901  # $wgEmailConfirmToEdit only applies to 'edit' action
902  $this->assertEquals( [],
903  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
904  $this->assertContains( [ 'confirmedittext' ],
905  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
906 
907  $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
908  $this->overrideMwServices();
909 
910  $this->assertNotContains( [ 'confirmedittext' ],
911  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
912 
913  # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
914  $this->assertEquals( [],
915  $this->title->getUserPermissionsErrors( 'move-target',
916  $this->user ) );
917 
918  global $wgLang;
919  $prev = time();
920  $now = time() + 120;
921  $this->user->mBlockedby = $this->user->getId();
922  $this->user->mBlock = new Block( [
923  'address' => '127.0.8.1',
924  'by' => $this->user->getId(),
925  'reason' => 'no reason given',
926  'timestamp' => $prev + 3600,
927  'auto' => true,
928  'expiry' => 0
929  ] );
930  $this->user->mBlock->setTimestamp( 0 );
931  $this->assertEquals( [ [ 'autoblockedtext',
932  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
933  'Useruser', null, 'infinite', '127.0.8.1',
934  $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ],
935  $this->title->getUserPermissionsErrors( 'move-target',
936  $this->user ) );
937 
938  $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
939  // quickUserCan should ignore user blocks
940  $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
941 
942  global $wgLocalTZoffset;
943  $wgLocalTZoffset = -60;
944  $this->user->mBlockedby = $this->user->getName();
945  $this->user->mBlock = new Block( [
946  'address' => '127.0.8.1',
947  'by' => $this->user->getId(),
948  'reason' => 'no reason given',
949  'timestamp' => $now,
950  'auto' => false,
951  'expiry' => 10,
952  ] );
953  $this->assertEquals( [ [ 'blockedtext',
954  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
955  'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
956  $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ],
957  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
958  # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
959  # $user->blockedFor() == ''
960  # $user->mBlock->mExpiry == 'infinity'
961 
962  $this->user->mBlockedby = $this->user->getName();
963  $this->user->mBlock = new Block( [
964  'address' => '127.0.8.1',
965  'by' => $this->user->getId(),
966  'reason' => 'no reason given',
967  'timestamp' => $now,
968  'auto' => false,
969  'expiry' => 10,
970  'systemBlock' => 'test',
971  ] );
972 
973  $errors = [ [ 'systemblockedtext',
974  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
975  'Useruser', 'test', '23:00, 31 December 1969', '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 Block( [
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 Block( [
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:64
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:53
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
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:48
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:68
runConfigEditPermissions( $resultNone, $resultMyCss, $resultMyJson, $resultMyJs, $resultUserCss, $resultUserJson, $resultUserJs, $resultPatrol)
$wgLang
Definition: Setup.php:876
setUser( $userName=null)
const NS_MEDIA
Definition: Defines.php:52
testUserBlock()
\MediaWiki\Permissions\PermissionManager::checkUserBlock
$res
Definition: database.txt:21
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:70
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:72
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:611
const NS_HELP
Definition: Defines.php:76
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:65
testUserBlockAction()
\MediaWiki\Permissions\PermissionManager::checkUserBlock
static createNew( $name, $params=[])
Add a user to the database, return the user object.
Definition: User.php:4291
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:587
Definition: Block.php:31
isWikitextNS( $ns)
Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.