MediaWiki  1.23.2
TitlePermissionTest.php
Go to the documentation of this file.
1 <?php
2 
10 
14  protected $userName, $altUserName;
15 
19  protected $title;
20 
24  protected $user, $anonUser, $userUser, $altUser;
25 
26  protected function setUp() {
27  parent::setUp();
28 
29  $langObj = Language::factory( 'en' );
30  $localZone = 'UTC';
31  $localOffset = date( 'Z' ) / 60;
32 
33  $this->setMwGlobals( array(
34  'wgMemc' => new EmptyBagOStuff,
35  'wgContLang' => $langObj,
36  'wgLanguageCode' => 'en',
37  'wgLang' => $langObj,
38  'wgLocaltimezone' => $localZone,
39  'wgLocalTZoffset' => $localOffset,
40  'wgNamespaceProtection' => array(
41  NS_MEDIAWIKI => 'editinterface',
42  ),
43  ) );
44 
45  $this->userName = 'Useruser';
46  $this->altUserName = 'Altuseruser';
47  date_default_timezone_set( $localZone );
48 
49  $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
50  if ( !isset( $this->userUser ) || !( $this->userUser instanceof User ) ) {
51  $this->userUser = User::newFromName( $this->userName );
52 
53  if ( !$this->userUser->getID() ) {
54  $this->userUser = User::createNew( $this->userName, array(
55  "email" => "test@example.com",
56  "real_name" => "Test User" ) );
57  $this->userUser->load();
58  }
59 
60  $this->altUser = User::newFromName( $this->altUserName );
61  if ( !$this->altUser->getID() ) {
62  $this->altUser = User::createNew( $this->altUserName, array(
63  "email" => "alttest@example.com",
64  "real_name" => "Test User Alt" ) );
65  $this->altUser->load();
66  }
67 
68  $this->anonUser = User::newFromId( 0 );
69 
70  $this->user = $this->userUser;
71  }
72  }
73 
74  protected function setUserPerm( $perm ) {
75  // Setting member variables is evil!!!
76 
77  if ( is_array( $perm ) ) {
78  $this->user->mRights = $perm;
79  } else {
80  $this->user->mRights = array( $perm );
81  }
82  }
83 
84  protected function setTitle( $ns, $title = "Main_Page" ) {
85  $this->title = Title::makeTitle( $ns, $title );
86  }
87 
88  protected function setUser( $userName = null ) {
89  if ( $userName === 'anon' ) {
90  $this->user = $this->anonUser;
91  } elseif ( $userName === null || $userName === $this->userName ) {
92  $this->user = $this->userUser;
93  } else {
94  $this->user = $this->altUser;
95  }
96  }
97 
102  public function testQuickPermissions() {
104  $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
105 
106  $this->setUser( 'anon' );
107  $this->setTitle( NS_TALK );
108  $this->setUserPerm( "createtalk" );
109  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
110  $this->assertEquals( array(), $res );
111 
112  $this->setTitle( NS_TALK );
113  $this->setUserPerm( "createpage" );
114  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
115  $this->assertEquals( array( array( "nocreatetext" ) ), $res );
116 
117  $this->setTitle( NS_TALK );
118  $this->setUserPerm( "" );
119  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
120  $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
121 
122  $this->setTitle( NS_MAIN );
123  $this->setUserPerm( "createpage" );
124  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
125  $this->assertEquals( array(), $res );
126 
127  $this->setTitle( NS_MAIN );
128  $this->setUserPerm( "createtalk" );
129  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
130  $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
131 
132  $this->setUser( $this->userName );
133  $this->setTitle( NS_TALK );
134  $this->setUserPerm( "createtalk" );
135  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
136  $this->assertEquals( array(), $res );
137 
138  $this->setTitle( NS_TALK );
139  $this->setUserPerm( "createpage" );
140  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
141  $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
142 
143  $this->setTitle( NS_TALK );
144  $this->setUserPerm( "" );
145  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
146  $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
147 
148  $this->setTitle( NS_MAIN );
149  $this->setUserPerm( "createpage" );
150  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
151  $this->assertEquals( array(), $res );
152 
153  $this->setTitle( NS_MAIN );
154  $this->setUserPerm( "createtalk" );
155  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
156  $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
157 
158  $this->setTitle( NS_MAIN );
159  $this->setUserPerm( "" );
160  $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
161  $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
162 
163  $this->setUser( 'anon' );
164  $this->setTitle( NS_USER, $this->userName . '' );
165  $this->setUserPerm( "" );
166  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
167  $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
168 
169  $this->setTitle( NS_USER, $this->userName . '/subpage' );
170  $this->setUserPerm( "" );
171  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
172  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
173 
174  $this->setTitle( NS_USER, $this->userName . '' );
175  $this->setUserPerm( "move-rootuserpages" );
176  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
177  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
178 
179  $this->setTitle( NS_USER, $this->userName . '/subpage' );
180  $this->setUserPerm( "move-rootuserpages" );
181  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
182  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
183 
184  $this->setTitle( NS_USER, $this->userName . '' );
185  $this->setUserPerm( "" );
186  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
187  $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
188 
189  $this->setTitle( NS_USER, $this->userName . '/subpage' );
190  $this->setUserPerm( "" );
191  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
192  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
193 
194  $this->setTitle( NS_USER, $this->userName . '' );
195  $this->setUserPerm( "move-rootuserpages" );
196  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
197  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
198 
199  $this->setTitle( NS_USER, $this->userName . '/subpage' );
200  $this->setUserPerm( "move-rootuserpages" );
201  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
202  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
203 
204  $this->setUser( $this->userName );
205  $this->setTitle( NS_FILE, "img.png" );
206  $this->setUserPerm( "" );
207  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
208  $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
209 
210  $this->setTitle( NS_FILE, "img.png" );
211  $this->setUserPerm( "movefile" );
212  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
213  $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
214 
215  $this->setUser( 'anon' );
216  $this->setTitle( NS_FILE, "img.png" );
217  $this->setUserPerm( "" );
218  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
219  $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
220 
221  $this->setTitle( NS_FILE, "img.png" );
222  $this->setUserPerm( "movefile" );
223  $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
224  $this->assertEquals( array( array( 'movenologintext' ) ), $res );
225 
226  $this->setUser( $this->userName );
227  $this->setUserPerm( "move" );
228  $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
229 
230  $this->setUserPerm( "" );
231  $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
232 
233  $this->setUser( 'anon' );
234  $this->setUserPerm( "move" );
235  $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
236 
237  $this->setUserPerm( "" );
238  $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
239  array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
240 
241  if ( $this->isWikitextNS( NS_MAIN ) ) {
242  //NOTE: some content models don't allow moving
243  // @todo find a Wikitext namespace for testing
244 
245  $this->setTitle( NS_MAIN );
246  $this->setUser( 'anon' );
247  $this->setUserPerm( "move" );
248  $this->runGroupPermissions( 'move', array() );
249 
250  $this->setUserPerm( "" );
251  $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
252  array( array( 'movenologintext' ) ) );
253 
254  $this->setUser( $this->userName );
255  $this->setUserPerm( "" );
256  $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
257 
258  $this->setUserPerm( "move" );
259  $this->runGroupPermissions( 'move', array() );
260 
261  $this->setUser( 'anon' );
262  $this->setUserPerm( 'move' );
263  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
264  $this->assertEquals( array(), $res );
265 
266  $this->setUserPerm( '' );
267  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
268  $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
269  }
270 
271  $this->setTitle( NS_USER );
272  $this->setUser( $this->userName );
273  $this->setUserPerm( array( "move", "move-rootuserpages" ) );
274  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
275  $this->assertEquals( array(), $res );
276 
277  $this->setUserPerm( "move" );
278  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
279  $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
280 
281  $this->setUser( 'anon' );
282  $this->setUserPerm( array( "move", "move-rootuserpages" ) );
283  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
284  $this->assertEquals( array(), $res );
285 
286  $this->setTitle( NS_USER, "User/subpage" );
287  $this->setUserPerm( array( "move", "move-rootuserpages" ) );
288  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
289  $this->assertEquals( array(), $res );
290 
291  $this->setUserPerm( "move" );
292  $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
293  $this->assertEquals( array(), $res );
294 
295  $this->setUser( 'anon' );
296  $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
297  array( array( 'badaccess-group0' ) ),
298  array(), true ),
299  'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
300  array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
301  array( array( 'protect-cantedit' ) ), false ),
302  '' => array( array(), array(), array(), true ) );
303 
304  foreach ( array( "edit", "protect", "" ) as $action ) {
305  $this->setUserPerm( null );
306  $this->assertEquals( $check[$action][0],
307  $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
308 
309  global $wgGroupPermissions;
310  $old = $wgGroupPermissions;
311  $wgGroupPermissions = array();
312 
313  $this->assertEquals( $check[$action][1],
314  $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
315  $wgGroupPermissions = $old;
316 
317  $this->setUserPerm( $action );
318  $this->assertEquals( $check[$action][2],
319  $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
320 
321  $this->setUserPerm( $action );
322  $this->assertEquals( $check[$action][3],
323  $this->title->userCan( $action, $this->user, true ) );
324  $this->assertEquals( $check[$action][3],
325  $this->title->quickUserCan( $action, $this->user ) );
326  # count( User::getGroupsWithPermissions( $action ) ) < 1
327  }
328  }
329 
330  protected function runGroupPermissions( $action, $result, $result2 = null ) {
331  global $wgGroupPermissions;
332 
333  if ( $result2 === null ) {
334  $result2 = $result;
335  }
336 
337  $wgGroupPermissions['autoconfirmed']['move'] = false;
338  $wgGroupPermissions['user']['move'] = false;
339  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
340  $this->assertEquals( $result, $res );
341 
342  $wgGroupPermissions['autoconfirmed']['move'] = true;
343  $wgGroupPermissions['user']['move'] = false;
344  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
345  $this->assertEquals( $result2, $res );
346 
347  $wgGroupPermissions['autoconfirmed']['move'] = true;
348  $wgGroupPermissions['user']['move'] = true;
349  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
350  $this->assertEquals( $result2, $res );
351 
352  $wgGroupPermissions['autoconfirmed']['move'] = false;
353  $wgGroupPermissions['user']['move'] = true;
354  $res = $this->title->getUserPermissionsErrors( $action, $this->user );
355  $this->assertEquals( $result2, $res );
356  }
357 
362  public function testSpecialsAndNSPermissions() {
364  $this->setUser( $this->userName );
365 
366  $this->setTitle( NS_SPECIAL );
367 
368  $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
369  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
370 
371  $this->setTitle( NS_MAIN );
372  $this->setUserPerm( 'bogus' );
373  $this->assertEquals( array(),
374  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
375 
376  $this->setTitle( NS_MAIN );
377  $this->setUserPerm( '' );
378  $this->assertEquals( array( array( 'badaccess-group0' ) ),
379  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
380 
381  $wgNamespaceProtection[NS_USER] = array( 'bogus' );
382 
383  $this->setTitle( NS_USER );
384  $this->setUserPerm( '' );
385  $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
386  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
387 
388  $this->setTitle( NS_MEDIAWIKI );
389  $this->setUserPerm( 'bogus' );
390  $this->assertEquals( array( array( 'protectedinterface' ) ),
391  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
392 
393  $this->setTitle( NS_MEDIAWIKI );
394  $this->setUserPerm( 'bogus' );
395  $this->assertEquals( array( array( 'protectedinterface' ) ),
396  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
397 
398  $wgNamespaceProtection = null;
399 
400  $this->setUserPerm( 'bogus' );
401  $this->assertEquals( array(),
402  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
403  $this->assertEquals( true,
404  $this->title->userCan( 'bogus', $this->user ) );
405 
406  $this->setUserPerm( '' );
407  $this->assertEquals( array( array( 'badaccess-group0' ) ),
408  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
409  $this->assertEquals( false,
410  $this->title->userCan( 'bogus', $this->user ) );
411  }
412 
417  public function testCssAndJavascriptPermissions() {
418  $this->setUser( $this->userName );
419 
420  $this->setTitle( NS_USER, $this->userName . '/test.js' );
421  $this->runCSSandJSPermissions(
422  array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
423  array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
424  array( array( 'badaccess-group0' ) ),
425  array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
426  array( array( 'badaccess-group0' ) )
427  );
428 
429  $this->setTitle( NS_USER, $this->userName . '/test.css' );
430  $this->runCSSandJSPermissions(
431  array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
432  array( array( 'badaccess-group0' ) ),
433  array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
434  array( array( 'badaccess-group0' ) ),
435  array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) )
436  );
437 
438  $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
439  $this->runCSSandJSPermissions(
440  array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
441  array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
442  array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
443  array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
444  array( array( 'badaccess-group0' ) )
445  );
446 
447  $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
448  $this->runCSSandJSPermissions(
449  array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
450  array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
451  array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
452  array( array( 'badaccess-group0' ) ),
453  array( array( 'badaccess-group0' ), array( 'customcssprotected' ) )
454  );
455 
456  $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
457  $this->runCSSandJSPermissions(
458  array( array( 'badaccess-group0' ) ),
459  array( array( 'badaccess-group0' ) ),
460  array( array( 'badaccess-group0' ) ),
461  array( array( 'badaccess-group0' ) ),
462  array( array( 'badaccess-group0' ) )
463  );
464  }
465 
466  protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
467  $this->setUserPerm( '' );
468  $this->assertEquals( $result0,
469  $this->title->getUserPermissionsErrors( 'bogus',
470  $this->user ) );
471 
472  $this->setUserPerm( 'editmyusercss' );
473  $this->assertEquals( $result1,
474  $this->title->getUserPermissionsErrors( 'bogus',
475  $this->user ) );
476 
477  $this->setUserPerm( 'editmyuserjs' );
478  $this->assertEquals( $result2,
479  $this->title->getUserPermissionsErrors( 'bogus',
480  $this->user ) );
481 
482  $this->setUserPerm( 'editusercss' );
483  $this->assertEquals( $result3,
484  $this->title->getUserPermissionsErrors( 'bogus',
485  $this->user ) );
486 
487  $this->setUserPerm( 'edituserjs' );
488  $this->assertEquals( $result4,
489  $this->title->getUserPermissionsErrors( 'bogus',
490  $this->user ) );
491 
492  $this->setUserPerm( 'editusercssjs' );
493  $this->assertEquals( array( array( 'badaccess-group0' ) ),
494  $this->title->getUserPermissionsErrors( 'bogus',
495  $this->user ) );
496 
497  $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
498  $this->assertEquals( array( array( 'badaccess-group0' ) ),
499  $this->title->getUserPermissionsErrors( 'bogus',
500  $this->user ) );
501  }
502 
507  public function testPageRestrictions() {
509 
510  $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
511 
512  $this->setTitle( NS_MAIN );
513  $this->title->mRestrictionsLoaded = true;
514  $this->setUserPerm( "edit" );
515  $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
516 
517  $this->assertEquals( array(),
518  $this->title->getUserPermissionsErrors( 'edit',
519  $this->user ) );
520 
521  $this->assertEquals( true,
522  $this->title->quickUserCan( 'edit', $this->user ) );
523  $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
524  "bogus" => array( 'bogus', "sysop", "protect", "" ) );
525 
526  $this->assertEquals( array( array( 'badaccess-group0' ),
527  array( 'protectedpagetext', 'bogus' ),
528  array( 'protectedpagetext', 'editprotected' ),
529  array( 'protectedpagetext', 'protect' ) ),
530  $this->title->getUserPermissionsErrors( 'bogus',
531  $this->user ) );
532  $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
533  array( 'protectedpagetext', 'editprotected' ),
534  array( 'protectedpagetext', 'protect' ) ),
535  $this->title->getUserPermissionsErrors( 'edit',
536  $this->user ) );
537  $this->setUserPerm( "" );
538  $this->assertEquals( array( array( 'badaccess-group0' ),
539  array( 'protectedpagetext', 'bogus' ),
540  array( 'protectedpagetext', 'editprotected' ),
541  array( 'protectedpagetext', 'protect' ) ),
542  $this->title->getUserPermissionsErrors( 'bogus',
543  $this->user ) );
544  $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
545  array( 'protectedpagetext', 'bogus' ),
546  array( 'protectedpagetext', 'editprotected' ),
547  array( 'protectedpagetext', 'protect' ) ),
548  $this->title->getUserPermissionsErrors( 'edit',
549  $this->user ) );
550  $this->setUserPerm( array( "edit", "editprotected" ) );
551  $this->assertEquals( array( array( 'badaccess-group0' ),
552  array( 'protectedpagetext', 'bogus' ),
553  array( 'protectedpagetext', 'protect' ) ),
554  $this->title->getUserPermissionsErrors( 'bogus',
555  $this->user ) );
556  $this->assertEquals( array(
557  array( 'protectedpagetext', 'bogus' ),
558  array( 'protectedpagetext', 'protect' ) ),
559  $this->title->getUserPermissionsErrors( 'edit',
560  $this->user ) );
561 
562  $this->title->mCascadeRestriction = true;
563  $this->setUserPerm( "edit" );
564  $this->assertEquals( false,
565  $this->title->quickUserCan( 'bogus', $this->user ) );
566  $this->assertEquals( false,
567  $this->title->quickUserCan( 'edit', $this->user ) );
568  $this->assertEquals( array( array( 'badaccess-group0' ),
569  array( 'protectedpagetext', 'bogus' ),
570  array( 'protectedpagetext', 'editprotected' ),
571  array( 'protectedpagetext', 'protect' ) ),
572  $this->title->getUserPermissionsErrors( 'bogus',
573  $this->user ) );
574  $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
575  array( 'protectedpagetext', 'editprotected' ),
576  array( 'protectedpagetext', 'protect' ) ),
577  $this->title->getUserPermissionsErrors( 'edit',
578  $this->user ) );
579 
580  $this->setUserPerm( array( "edit", "editprotected" ) );
581  $this->assertEquals( false,
582  $this->title->quickUserCan( 'bogus', $this->user ) );
583  $this->assertEquals( false,
584  $this->title->quickUserCan( 'edit', $this->user ) );
585  $this->assertEquals( array( array( 'badaccess-group0' ),
586  array( 'protectedpagetext', 'bogus' ),
587  array( 'protectedpagetext', 'protect' ),
588  array( 'protectedpagetext', 'protect' ) ),
589  $this->title->getUserPermissionsErrors( 'bogus',
590  $this->user ) );
591  $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
592  array( 'protectedpagetext', 'protect' ),
593  array( 'protectedpagetext', 'protect' ) ),
594  $this->title->getUserPermissionsErrors( 'edit',
595  $this->user ) );
596  }
597 
598  public function testCascadingSourcesRestrictions() {
599  $this->setTitle( NS_MAIN, "test page" );
600  $this->setUserPerm( array( "edit", "bogus" ) );
601 
602  $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
603  $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
604 
605  $this->assertEquals( false,
606  $this->title->userCan( 'bogus', $this->user ) );
607  $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
608  array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
609  array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
610  $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
611 
612  $this->assertEquals( true,
613  $this->title->userCan( 'edit', $this->user ) );
614  $this->assertEquals( array(),
615  $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
616  }
617 
622  public function testActionPermissions() {
623  $this->setUserPerm( array( "createpage" ) );
624  $this->setTitle( NS_MAIN, "test page" );
625  $this->title->mTitleProtection['pt_create_perm'] = '';
626  $this->title->mTitleProtection['pt_user'] = $this->user->getID();
627  $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
628  $this->title->mTitleProtection['pt_reason'] = 'test';
629  $this->title->mCascadeRestriction = false;
630 
631  $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
632  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
633  $this->assertEquals( false,
634  $this->title->userCan( 'create', $this->user ) );
635 
636  $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
637  $this->setUserPerm( array( 'createpage', 'protect' ) );
638  $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
639  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
640  $this->assertEquals( false,
641  $this->title->userCan( 'create', $this->user ) );
642 
643  $this->setUserPerm( array( 'createpage', 'editprotected' ) );
644  $this->assertEquals( array(),
645  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
646  $this->assertEquals( true,
647  $this->title->userCan( 'create', $this->user ) );
648 
649  $this->setUserPerm( array( 'createpage' ) );
650  $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
651  $this->title->getUserPermissionsErrors( 'create', $this->user ) );
652  $this->assertEquals( false,
653  $this->title->userCan( 'create', $this->user ) );
654 
655  $this->setTitle( NS_MEDIA, "test page" );
656  $this->setUserPerm( array( "move" ) );
657  $this->assertEquals( false,
658  $this->title->userCan( 'move', $this->user ) );
659  $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
660  $this->title->getUserPermissionsErrors( 'move', $this->user ) );
661 
662  $this->setTitle( NS_HELP, "test page" );
663  $this->assertEquals( array(),
664  $this->title->getUserPermissionsErrors( 'move', $this->user ) );
665  $this->assertEquals( true,
666  $this->title->userCan( 'move', $this->user ) );
667 
668  $this->title->mInterwiki = "no";
669  $this->assertEquals( array( array( 'immobile-source-page' ) ),
670  $this->title->getUserPermissionsErrors( 'move', $this->user ) );
671  $this->assertEquals( false,
672  $this->title->userCan( 'move', $this->user ) );
673 
674  $this->setTitle( NS_MEDIA, "test page" );
675  $this->assertEquals( false,
676  $this->title->userCan( 'move-target', $this->user ) );
677  $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
678  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
679 
680  $this->setTitle( NS_HELP, "test page" );
681  $this->assertEquals( array(),
682  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
683  $this->assertEquals( true,
684  $this->title->userCan( 'move-target', $this->user ) );
685 
686  $this->title->mInterwiki = "no";
687  $this->assertEquals( array( array( 'immobile-target-page' ) ),
688  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
689  $this->assertEquals( false,
690  $this->title->userCan( 'move-target', $this->user ) );
691  }
692 
693  public function testUserBlock() {
694  global $wgEmailConfirmToEdit, $wgEmailAuthentication;
695  $wgEmailConfirmToEdit = true;
696  $wgEmailAuthentication = true;
697 
698  $this->setUserPerm( array( "createpage", "move" ) );
699  $this->setTitle( NS_HELP, "test page" );
700 
701  # $short
702  $this->assertEquals( array( array( 'confirmedittext' ) ),
703  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
704  $wgEmailConfirmToEdit = false;
705  $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
706 
707  # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
708  $this->assertEquals( array(),
709  $this->title->getUserPermissionsErrors( 'move-target',
710  $this->user ) );
711 
712  global $wgLang;
713  $prev = time();
714  $now = time() + 120;
715  $this->user->mBlockedby = $this->user->getId();
716  $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
717  'no reason given', $prev + 3600, 1, 0 );
718  $this->user->mBlock->mTimestamp = 0;
719  $this->assertEquals( array( array( 'autoblockedtext',
720  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
721  'Useruser', null, 'infinite', '127.0.8.1',
722  $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
723  $this->title->getUserPermissionsErrors( 'move-target',
724  $this->user ) );
725 
726  $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
727  // quickUserCan should ignore user blocks
728  $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
729 
730  global $wgLocalTZoffset;
731  $wgLocalTZoffset = -60;
732  $this->user->mBlockedby = $this->user->getName();
733  $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
734  'no reason given', $now, 0, 10 );
735  $this->assertEquals( array( array( 'blockedtext',
736  '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
737  'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
738  $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
739  $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
740  # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
741  # $user->blockedFor() == ''
742  # $user->mBlock->mExpiry == 'infinity'
743  }
744 }
TitlePermissionTest\setUser
setUser( $userName=null)
Definition: TitlePermissionTest.php:85
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag '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 '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. '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 '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 '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 wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() '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 User::isValidEmailAddr(), 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 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) '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:Associative array mapping language codes to prefixed links of the form "language:title". & $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. 'LinkBegin':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:1528
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:411
NS_HELP
const NS_HELP
Definition: Defines.php:91
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
EmptyBagOStuff
A BagOStuff object with no objects in it.
Definition: EmptyBagOStuff.php:29
TitlePermissionTest\setTitle
setTitle( $ns, $title="Main_Page")
Definition: TitlePermissionTest.php:81
TitlePermissionTest\$anonUser
User $anonUser
Definition: TitlePermissionTest.php:21
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
TitlePermissionTest\testCssAndJavascriptPermissions
testCssAndJavascriptPermissions()
Definition: TitlePermissionTest.php:414
MediaWikiTestCase\isWikitextNS
isWikitextNS( $ns)
Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
Definition: MediaWikiTestCase.php:886
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
TitlePermissionTest\testCascadingSourcesRestrictions
testCascadingSourcesRestrictions()
Definition: TitlePermissionTest.php:595
NS_FILE
const NS_FILE
Definition: Defines.php:85
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
TitlePermissionTest\testSpecialsAndNSPermissions
testSpecialsAndNSPermissions()
Definition: TitlePermissionTest.php:359
TitlePermissionTest\runCSSandJSPermissions
runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4)
Definition: TitlePermissionTest.php:463
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:68
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:83
TitlePermissionTest\runGroupPermissions
runGroupPermissions( $action, $result, $result2=null)
Definition: TitlePermissionTest.php:327
TitlePermissionTest\$title
Title $title
Definition: TitlePermissionTest.php:17
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
TitlePermissionTest\setUserPerm
setUserPerm( $perm)
Definition: TitlePermissionTest.php:71
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
TitlePermissionTest\testUserBlock
testUserBlock()
Definition: TitlePermissionTest.php:690
TitlePermissionTest\testPageRestrictions
testPageRestrictions()
Definition: TitlePermissionTest.php:504
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
User\createNew
static createNew( $name, $params=array())
Add a user to the database, return the user object.
Definition: User.php:3458
TitlePermissionTest
@group Database
Definition: TitlePermissionTest.php:9
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2431
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:67
TitlePermissionTest\$altUser
User $altUser
Definition: TitlePermissionTest.php:21
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
TitlePermissionTest\testActionPermissions
testActionPermissions()
Definition: TitlePermissionTest.php:619
TitlePermissionTest\setUp
setUp()
Definition: TitlePermissionTest.php:23
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:35
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
TitlePermissionTest\testQuickPermissions
testQuickPermissions()
Definition: TitlePermissionTest.php:99
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Block
Definition: Block.php:22
NS_USER
const NS_USER
Definition: Defines.php:81
TitlePermissionTest\$userName
string $userName
Definition: TitlePermissionTest.php:13
$wgNamespaceProtection
if(!isset( $wgVersion)) if( $wgScript===false) if( $wgLoadScript===false) if( $wgArticlePath===false) if(!empty( $wgActionPaths) &&!isset( $wgActionPaths['view'])) if( $wgStylePath===false) if( $wgLocalStylePath===false) if( $wgStyleDirectory===false) if( $wgExtensionAssetsPath===false) if( $wgLogo===false) if( $wgUploadPath===false) if( $wgUploadDirectory===false) if( $wgReadOnlyFile===false) if( $wgFileCacheDirectory===false) if( $wgDeletedDirectory===false) if(isset( $wgFileStore['deleted']['directory'])) if(isset( $wgFooterIcons['copyright']) &&isset( $wgFooterIcons['copyright']['copyright']) && $wgFooterIcons['copyright']['copyright']===array()) if(isset( $wgFooterIcons['poweredby']) &&isset( $wgFooterIcons['poweredby']['mediawiki']) && $wgFooterIcons['poweredby']['mediawiki']['src']===null) $wgNamespaceProtection[NS_MEDIAWIKI]
Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a sysadmin to set $wgName...
Definition: Setup.php:135
NS_TALK
const NS_TALK
Definition: Defines.php:80
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
TitlePermissionTest\$user
User $user
Definition: TitlePermissionTest.php:21
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:87
TitlePermissionTest\$altUserName
string $altUserName
Definition: TitlePermissionTest.php:13
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
$res
$res
Definition: database.txt:21
TitlePermissionTest\$userUser
User $userUser
Definition: TitlePermissionTest.php:21