MediaWiki
REL1_22
|
00001 <?php 00002 00007 class TitlePermissionTest extends MediaWikiLangTestCase { 00008 00012 protected $userName, $altUserName; 00013 00017 protected $title; 00018 00022 protected $user, $anonUser, $userUser, $altUser; 00023 00024 protected function setUp() { 00025 parent::setUp(); 00026 00027 $langObj = Language::factory( 'en' ); 00028 $localZone = 'UTC'; 00029 $localOffset = date( 'Z' ) / 60; 00030 00031 $this->setMwGlobals( array( 00032 'wgMemc' => new EmptyBagOStuff, 00033 'wgContLang' => $langObj, 00034 'wgLanguageCode' => 'en', 00035 'wgLang' => $langObj, 00036 'wgLocaltimezone' => $localZone, 00037 'wgLocalTZoffset' => $localOffset, 00038 'wgNamespaceProtection' => array( 00039 NS_MEDIAWIKI => 'editinterface', 00040 ), 00041 ) ); 00042 00043 $this->userName = 'Useruser'; 00044 $this->altUserName = 'Altuseruser'; 00045 date_default_timezone_set( $localZone ); 00046 00047 $this->title = Title::makeTitle( NS_MAIN, "Main Page" ); 00048 if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) { 00049 $this->userUser = User::newFromName( $this->userName ); 00050 00051 if ( !$this->userUser->getID() ) { 00052 $this->userUser = User::createNew( $this->userName, array( 00053 "email" => "[email protected]", 00054 "real_name" => "Test User" ) ); 00055 $this->userUser->load(); 00056 } 00057 00058 $this->altUser = User::newFromName( $this->altUserName ); 00059 if ( !$this->altUser->getID() ) { 00060 $this->altUser = User::createNew( $this->altUserName, array( 00061 "email" => "[email protected]", 00062 "real_name" => "Test User Alt" ) ); 00063 $this->altUser->load(); 00064 } 00065 00066 $this->anonUser = User::newFromId( 0 ); 00067 00068 $this->user = $this->userUser; 00069 } 00070 } 00071 00072 protected function setUserPerm( $perm ) { 00073 // Setting member variables is evil!!! 00074 00075 if ( is_array( $perm ) ) { 00076 $this->user->mRights = $perm; 00077 } else { 00078 $this->user->mRights = array( $perm ); 00079 } 00080 } 00081 00082 protected function setTitle( $ns, $title = "Main_Page" ) { 00083 $this->title = Title::makeTitle( $ns, $title ); 00084 } 00085 00086 protected function setUser( $userName = null ) { 00087 if ( $userName === 'anon' ) { 00088 $this->user = $this->anonUser; 00089 } elseif ( $userName === null || $userName === $this->userName ) { 00090 $this->user = $this->userUser; 00091 } else { 00092 $this->user = $this->altUser; 00093 } 00094 } 00095 00100 public function testQuickPermissions() { 00101 global $wgContLang; 00102 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT ); 00103 00104 $this->setUser( 'anon' ); 00105 $this->setTitle( NS_TALK ); 00106 $this->setUserPerm( "createtalk" ); 00107 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00108 $this->assertEquals( array(), $res ); 00109 00110 $this->setTitle( NS_TALK ); 00111 $this->setUserPerm( "createpage" ); 00112 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00113 $this->assertEquals( array( array( "nocreatetext" ) ), $res ); 00114 00115 $this->setTitle( NS_TALK ); 00116 $this->setUserPerm( "" ); 00117 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00118 $this->assertEquals( array( array( 'nocreatetext' ) ), $res ); 00119 00120 $this->setTitle( NS_MAIN ); 00121 $this->setUserPerm( "createpage" ); 00122 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00123 $this->assertEquals( array(), $res ); 00124 00125 $this->setTitle( NS_MAIN ); 00126 $this->setUserPerm( "createtalk" ); 00127 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00128 $this->assertEquals( array( array( 'nocreatetext' ) ), $res ); 00129 00130 $this->setUser( $this->userName ); 00131 $this->setTitle( NS_TALK ); 00132 $this->setUserPerm( "createtalk" ); 00133 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00134 $this->assertEquals( array(), $res ); 00135 00136 $this->setTitle( NS_TALK ); 00137 $this->setUserPerm( "createpage" ); 00138 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00139 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res ); 00140 00141 $this->setTitle( NS_TALK ); 00142 $this->setUserPerm( "" ); 00143 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00144 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res ); 00145 00146 $this->setTitle( NS_MAIN ); 00147 $this->setUserPerm( "createpage" ); 00148 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00149 $this->assertEquals( array(), $res ); 00150 00151 $this->setTitle( NS_MAIN ); 00152 $this->setUserPerm( "createtalk" ); 00153 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00154 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res ); 00155 00156 $this->setTitle( NS_MAIN ); 00157 $this->setUserPerm( "" ); 00158 $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); 00159 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res ); 00160 00161 $this->setUser( 'anon' ); 00162 $this->setTitle( NS_USER, $this->userName . '' ); 00163 $this->setUserPerm( "" ); 00164 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00165 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res ); 00166 00167 $this->setTitle( NS_USER, $this->userName . '/subpage' ); 00168 $this->setUserPerm( "" ); 00169 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00170 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00171 00172 $this->setTitle( NS_USER, $this->userName . '' ); 00173 $this->setUserPerm( "move-rootuserpages" ); 00174 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00175 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00176 00177 $this->setTitle( NS_USER, $this->userName . '/subpage' ); 00178 $this->setUserPerm( "move-rootuserpages" ); 00179 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00180 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00181 00182 $this->setTitle( NS_USER, $this->userName . '' ); 00183 $this->setUserPerm( "" ); 00184 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00185 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res ); 00186 00187 $this->setTitle( NS_USER, $this->userName . '/subpage' ); 00188 $this->setUserPerm( "" ); 00189 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00190 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00191 00192 $this->setTitle( NS_USER, $this->userName . '' ); 00193 $this->setUserPerm( "move-rootuserpages" ); 00194 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00195 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00196 00197 $this->setTitle( NS_USER, $this->userName . '/subpage' ); 00198 $this->setUserPerm( "move-rootuserpages" ); 00199 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00200 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00201 00202 $this->setUser( $this->userName ); 00203 $this->setTitle( NS_FILE, "img.png" ); 00204 $this->setUserPerm( "" ); 00205 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00206 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res ); 00207 00208 $this->setTitle( NS_FILE, "img.png" ); 00209 $this->setUserPerm( "movefile" ); 00210 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00211 $this->assertEquals( array( array( 'movenotallowed' ) ), $res ); 00212 00213 $this->setUser( 'anon' ); 00214 $this->setTitle( NS_FILE, "img.png" ); 00215 $this->setUserPerm( "" ); 00216 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00217 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res ); 00218 00219 $this->setTitle( NS_FILE, "img.png" ); 00220 $this->setUserPerm( "movefile" ); 00221 $res = $this->title->getUserPermissionsErrors( 'move', $this->user ); 00222 $this->assertEquals( array( array( 'movenologintext' ) ), $res ); 00223 00224 $this->setUser( $this->userName ); 00225 $this->setUserPerm( "move" ); 00226 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) ); 00227 00228 $this->setUserPerm( "" ); 00229 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) ); 00230 00231 $this->setUser( 'anon' ); 00232 $this->setUserPerm( "move" ); 00233 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) ); 00234 00235 $this->setUserPerm( "" ); 00236 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), 00237 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) ); 00238 00239 if ( $this->isWikitextNS( NS_MAIN ) ) { 00240 //NOTE: some content models don't allow moving 00241 // @todo find a Wikitext namespace for testing 00242 00243 $this->setTitle( NS_MAIN ); 00244 $this->setUser( 'anon' ); 00245 $this->setUserPerm( "move" ); 00246 $this->runGroupPermissions( 'move', array() ); 00247 00248 $this->setUserPerm( "" ); 00249 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ), 00250 array( array( 'movenologintext' ) ) ); 00251 00252 $this->setUser( $this->userName ); 00253 $this->setUserPerm( "" ); 00254 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) ); 00255 00256 $this->setUserPerm( "move" ); 00257 $this->runGroupPermissions( 'move', array() ); 00258 00259 $this->setUser( 'anon' ); 00260 $this->setUserPerm( 'move' ); 00261 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00262 $this->assertEquals( array(), $res ); 00263 00264 $this->setUserPerm( '' ); 00265 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00266 $this->assertEquals( array( array( 'movenotallowed' ) ), $res ); 00267 } 00268 00269 $this->setTitle( NS_USER ); 00270 $this->setUser( $this->userName ); 00271 $this->setUserPerm( array( "move", "move-rootuserpages" ) ); 00272 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00273 $this->assertEquals( array(), $res ); 00274 00275 $this->setUserPerm( "move" ); 00276 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00277 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res ); 00278 00279 $this->setUser( 'anon' ); 00280 $this->setUserPerm( array( "move", "move-rootuserpages" ) ); 00281 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00282 $this->assertEquals( array(), $res ); 00283 00284 $this->setTitle( NS_USER, "User/subpage" ); 00285 $this->setUserPerm( array( "move", "move-rootuserpages" ) ); 00286 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00287 $this->assertEquals( array(), $res ); 00288 00289 $this->setUserPerm( "move" ); 00290 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); 00291 $this->assertEquals( array(), $res ); 00292 00293 $this->setUser( 'anon' ); 00294 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ), 00295 array( array( 'badaccess-group0' ) ), 00296 array(), true ), 00297 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ), 00298 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ), 00299 array( array( 'protect-cantedit' ) ), false ), 00300 '' => array( array(), array(), array(), true ) ); 00301 00302 foreach ( array( "edit", "protect", "" ) as $action ) { 00303 $this->setUserPerm( null ); 00304 $this->assertEquals( $check[$action][0], 00305 $this->title->getUserPermissionsErrors( $action, $this->user, true ) ); 00306 00307 global $wgGroupPermissions; 00308 $old = $wgGroupPermissions; 00309 $wgGroupPermissions = array(); 00310 00311 $this->assertEquals( $check[$action][1], 00312 $this->title->getUserPermissionsErrors( $action, $this->user, true ) ); 00313 $wgGroupPermissions = $old; 00314 00315 $this->setUserPerm( $action ); 00316 $this->assertEquals( $check[$action][2], 00317 $this->title->getUserPermissionsErrors( $action, $this->user, true ) ); 00318 00319 $this->setUserPerm( $action ); 00320 $this->assertEquals( $check[$action][3], 00321 $this->title->userCan( $action, $this->user, true ) ); 00322 $this->assertEquals( $check[$action][3], 00323 $this->title->quickUserCan( $action, $this->user ) ); 00324 # count( User::getGroupsWithPermissions( $action ) ) < 1 00325 } 00326 } 00327 00328 protected function runGroupPermissions( $action, $result, $result2 = null ) { 00329 global $wgGroupPermissions; 00330 00331 if ( $result2 === null ) { 00332 $result2 = $result; 00333 } 00334 00335 $wgGroupPermissions['autoconfirmed']['move'] = false; 00336 $wgGroupPermissions['user']['move'] = false; 00337 $res = $this->title->getUserPermissionsErrors( $action, $this->user ); 00338 $this->assertEquals( $result, $res ); 00339 00340 $wgGroupPermissions['autoconfirmed']['move'] = true; 00341 $wgGroupPermissions['user']['move'] = false; 00342 $res = $this->title->getUserPermissionsErrors( $action, $this->user ); 00343 $this->assertEquals( $result2, $res ); 00344 00345 $wgGroupPermissions['autoconfirmed']['move'] = true; 00346 $wgGroupPermissions['user']['move'] = true; 00347 $res = $this->title->getUserPermissionsErrors( $action, $this->user ); 00348 $this->assertEquals( $result2, $res ); 00349 00350 $wgGroupPermissions['autoconfirmed']['move'] = false; 00351 $wgGroupPermissions['user']['move'] = true; 00352 $res = $this->title->getUserPermissionsErrors( $action, $this->user ); 00353 $this->assertEquals( $result2, $res ); 00354 } 00355 00360 public function testSpecialsAndNSPermissions() { 00361 global $wgNamespaceProtection; 00362 $this->setUser( $this->userName ); 00363 00364 $this->setTitle( NS_SPECIAL ); 00365 00366 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ), 00367 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00368 00369 $this->setTitle( NS_MAIN ); 00370 $this->setUserPerm( 'bogus' ); 00371 $this->assertEquals( array(), 00372 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00373 00374 $this->setTitle( NS_MAIN ); 00375 $this->setUserPerm( '' ); 00376 $this->assertEquals( array( array( 'badaccess-group0' ) ), 00377 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00378 00379 $wgNamespaceProtection[NS_USER] = array( 'bogus' ); 00380 00381 $this->setTitle( NS_USER ); 00382 $this->setUserPerm( '' ); 00383 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ), 00384 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00385 00386 $this->setTitle( NS_MEDIAWIKI ); 00387 $this->setUserPerm( 'bogus' ); 00388 $this->assertEquals( array( array( 'protectedinterface' ) ), 00389 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00390 00391 $this->setTitle( NS_MEDIAWIKI ); 00392 $this->setUserPerm( 'bogus' ); 00393 $this->assertEquals( array( array( 'protectedinterface' ) ), 00394 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00395 00396 $wgNamespaceProtection = null; 00397 00398 $this->setUserPerm( 'bogus' ); 00399 $this->assertEquals( array(), 00400 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00401 $this->assertEquals( true, 00402 $this->title->userCan( 'bogus', $this->user ) ); 00403 00404 $this->setUserPerm( '' ); 00405 $this->assertEquals( array( array( 'badaccess-group0' ) ), 00406 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00407 $this->assertEquals( false, 00408 $this->title->userCan( 'bogus', $this->user ) ); 00409 } 00410 00415 public function testCssAndJavascriptPermissions() { 00416 $this->setUser( $this->userName ); 00417 00418 $this->setTitle( NS_USER, $this->userName . '/test.js' ); 00419 $this->runCSSandJSPermissions( 00420 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ), 00421 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ), 00422 array( array( 'badaccess-group0' ) ), 00423 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ), 00424 array( array( 'badaccess-group0' ) ) 00425 ); 00426 00427 $this->setTitle( NS_USER, $this->userName . '/test.css' ); 00428 $this->runCSSandJSPermissions( 00429 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ), 00430 array( array( 'badaccess-group0' ) ), 00431 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ), 00432 array( array( 'badaccess-group0' ) ), 00433 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ) 00434 ); 00435 00436 $this->setTitle( NS_USER, $this->altUserName . '/test.js' ); 00437 $this->runCSSandJSPermissions( 00438 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ), 00439 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ), 00440 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ), 00441 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ), 00442 array( array( 'badaccess-group0' ) ) 00443 ); 00444 00445 $this->setTitle( NS_USER, $this->altUserName . '/test.css' ); 00446 $this->runCSSandJSPermissions( 00447 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ), 00448 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ), 00449 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ), 00450 array( array( 'badaccess-group0' ) ), 00451 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) 00452 ); 00453 00454 $this->setTitle( NS_USER, $this->altUserName . '/tempo' ); 00455 $this->runCSSandJSPermissions( 00456 array( array( 'badaccess-group0' ) ), 00457 array( array( 'badaccess-group0' ) ), 00458 array( array( 'badaccess-group0' ) ), 00459 array( array( 'badaccess-group0' ) ), 00460 array( array( 'badaccess-group0' ) ) 00461 ); 00462 } 00463 00464 protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) { 00465 $this->setUserPerm( '' ); 00466 $this->assertEquals( $result0, 00467 $this->title->getUserPermissionsErrors( 'bogus', 00468 $this->user ) ); 00469 00470 $this->setUserPerm( 'editmyusercss' ); 00471 $this->assertEquals( $result1, 00472 $this->title->getUserPermissionsErrors( 'bogus', 00473 $this->user ) ); 00474 00475 $this->setUserPerm( 'editmyuserjs' ); 00476 $this->assertEquals( $result2, 00477 $this->title->getUserPermissionsErrors( 'bogus', 00478 $this->user ) ); 00479 00480 $this->setUserPerm( 'editusercss' ); 00481 $this->assertEquals( $result3, 00482 $this->title->getUserPermissionsErrors( 'bogus', 00483 $this->user ) ); 00484 00485 $this->setUserPerm( 'edituserjs' ); 00486 $this->assertEquals( $result4, 00487 $this->title->getUserPermissionsErrors( 'bogus', 00488 $this->user ) ); 00489 00490 $this->setUserPerm( 'editusercssjs' ); 00491 $this->assertEquals( array( array( 'badaccess-group0' ) ), 00492 $this->title->getUserPermissionsErrors( 'bogus', 00493 $this->user ) ); 00494 00495 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) ); 00496 $this->assertEquals( array( array( 'badaccess-group0' ) ), 00497 $this->title->getUserPermissionsErrors( 'bogus', 00498 $this->user ) ); 00499 } 00500 00505 public function testPageRestrictions() { 00506 global $wgContLang; 00507 00508 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT ); 00509 00510 $this->setTitle( NS_MAIN ); 00511 $this->title->mRestrictionsLoaded = true; 00512 $this->setUserPerm( "edit" ); 00513 $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) ); 00514 00515 $this->assertEquals( array(), 00516 $this->title->getUserPermissionsErrors( 'edit', 00517 $this->user ) ); 00518 00519 $this->assertEquals( true, 00520 $this->title->quickUserCan( 'edit', $this->user ) ); 00521 $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ), 00522 "bogus" => array( 'bogus', "sysop", "protect", "" ) ); 00523 00524 $this->assertEquals( array( array( 'badaccess-group0' ), 00525 array( 'protectedpagetext', 'bogus' ), 00526 array( 'protectedpagetext', 'editprotected' ), 00527 array( 'protectedpagetext', 'protect' ) ), 00528 $this->title->getUserPermissionsErrors( 'bogus', 00529 $this->user ) ); 00530 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), 00531 array( 'protectedpagetext', 'editprotected' ), 00532 array( 'protectedpagetext', 'protect' ) ), 00533 $this->title->getUserPermissionsErrors( 'edit', 00534 $this->user ) ); 00535 $this->setUserPerm( "" ); 00536 $this->assertEquals( array( array( 'badaccess-group0' ), 00537 array( 'protectedpagetext', 'bogus' ), 00538 array( 'protectedpagetext', 'editprotected' ), 00539 array( 'protectedpagetext', 'protect' ) ), 00540 $this->title->getUserPermissionsErrors( 'bogus', 00541 $this->user ) ); 00542 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ), 00543 array( 'protectedpagetext', 'bogus' ), 00544 array( 'protectedpagetext', 'editprotected' ), 00545 array( 'protectedpagetext', 'protect' ) ), 00546 $this->title->getUserPermissionsErrors( 'edit', 00547 $this->user ) ); 00548 $this->setUserPerm( array( "edit", "editprotected" ) ); 00549 $this->assertEquals( array( array( 'badaccess-group0' ), 00550 array( 'protectedpagetext', 'bogus' ), 00551 array( 'protectedpagetext', 'protect' ) ), 00552 $this->title->getUserPermissionsErrors( 'bogus', 00553 $this->user ) ); 00554 $this->assertEquals( array( 00555 array( 'protectedpagetext', 'bogus' ), 00556 array( 'protectedpagetext', 'protect' ) ), 00557 $this->title->getUserPermissionsErrors( 'edit', 00558 $this->user ) ); 00559 00560 $this->title->mCascadeRestriction = true; 00561 $this->setUserPerm( "edit" ); 00562 $this->assertEquals( false, 00563 $this->title->quickUserCan( 'bogus', $this->user ) ); 00564 $this->assertEquals( false, 00565 $this->title->quickUserCan( 'edit', $this->user ) ); 00566 $this->assertEquals( array( array( 'badaccess-group0' ), 00567 array( 'protectedpagetext', 'bogus' ), 00568 array( 'protectedpagetext', 'editprotected' ), 00569 array( 'protectedpagetext', 'protect' ) ), 00570 $this->title->getUserPermissionsErrors( 'bogus', 00571 $this->user ) ); 00572 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), 00573 array( 'protectedpagetext', 'editprotected' ), 00574 array( 'protectedpagetext', 'protect' ) ), 00575 $this->title->getUserPermissionsErrors( 'edit', 00576 $this->user ) ); 00577 00578 $this->setUserPerm( array( "edit", "editprotected" ) ); 00579 $this->assertEquals( false, 00580 $this->title->quickUserCan( 'bogus', $this->user ) ); 00581 $this->assertEquals( false, 00582 $this->title->quickUserCan( 'edit', $this->user ) ); 00583 $this->assertEquals( array( array( 'badaccess-group0' ), 00584 array( 'protectedpagetext', 'bogus' ), 00585 array( 'protectedpagetext', 'protect' ), 00586 array( 'protectedpagetext', 'protect' ) ), 00587 $this->title->getUserPermissionsErrors( 'bogus', 00588 $this->user ) ); 00589 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), 00590 array( 'protectedpagetext', 'protect' ), 00591 array( 'protectedpagetext', 'protect' ) ), 00592 $this->title->getUserPermissionsErrors( 'edit', 00593 $this->user ) ); 00594 } 00595 00596 public function testCascadingSourcesRestrictions() { 00597 $this->setTitle( NS_MAIN, "test page" ); 00598 $this->setUserPerm( array( "edit", "bogus" ) ); 00599 00600 $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) ); 00601 $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) ); 00602 00603 $this->assertEquals( false, 00604 $this->title->userCan( 'bogus', $this->user ) ); 00605 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ), 00606 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ), 00607 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ), 00608 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); 00609 00610 $this->assertEquals( true, 00611 $this->title->userCan( 'edit', $this->user ) ); 00612 $this->assertEquals( array(), 00613 $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); 00614 } 00615 00620 public function testActionPermissions() { 00621 $this->setUserPerm( array( "createpage" ) ); 00622 $this->setTitle( NS_MAIN, "test page" ); 00623 $this->title->mTitleProtection['pt_create_perm'] = ''; 00624 $this->title->mTitleProtection['pt_user'] = $this->user->getID(); 00625 $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity(); 00626 $this->title->mTitleProtection['pt_reason'] = 'test'; 00627 $this->title->mCascadeRestriction = false; 00628 00629 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ), 00630 $this->title->getUserPermissionsErrors( 'create', $this->user ) ); 00631 $this->assertEquals( false, 00632 $this->title->userCan( 'create', $this->user ) ); 00633 00634 $this->title->mTitleProtection['pt_create_perm'] = 'sysop'; 00635 $this->setUserPerm( array( 'createpage', 'protect' ) ); 00636 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ), 00637 $this->title->getUserPermissionsErrors( 'create', $this->user ) ); 00638 $this->assertEquals( false, 00639 $this->title->userCan( 'create', $this->user ) ); 00640 00641 $this->setUserPerm( array( 'createpage', 'editprotected' ) ); 00642 $this->assertEquals( array(), 00643 $this->title->getUserPermissionsErrors( 'create', $this->user ) ); 00644 $this->assertEquals( true, 00645 $this->title->userCan( 'create', $this->user ) ); 00646 00647 $this->setUserPerm( array( 'createpage' ) ); 00648 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ), 00649 $this->title->getUserPermissionsErrors( 'create', $this->user ) ); 00650 $this->assertEquals( false, 00651 $this->title->userCan( 'create', $this->user ) ); 00652 00653 $this->setTitle( NS_MEDIA, "test page" ); 00654 $this->setUserPerm( array( "move" ) ); 00655 $this->assertEquals( false, 00656 $this->title->userCan( 'move', $this->user ) ); 00657 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ), 00658 $this->title->getUserPermissionsErrors( 'move', $this->user ) ); 00659 00660 $this->setTitle( NS_HELP, "test page" ); 00661 $this->assertEquals( array(), 00662 $this->title->getUserPermissionsErrors( 'move', $this->user ) ); 00663 $this->assertEquals( true, 00664 $this->title->userCan( 'move', $this->user ) ); 00665 00666 $this->title->mInterwiki = "no"; 00667 $this->assertEquals( array( array( 'immobile-source-page' ) ), 00668 $this->title->getUserPermissionsErrors( 'move', $this->user ) ); 00669 $this->assertEquals( false, 00670 $this->title->userCan( 'move', $this->user ) ); 00671 00672 $this->setTitle( NS_MEDIA, "test page" ); 00673 $this->assertEquals( false, 00674 $this->title->userCan( 'move-target', $this->user ) ); 00675 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ), 00676 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); 00677 00678 $this->setTitle( NS_HELP, "test page" ); 00679 $this->assertEquals( array(), 00680 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); 00681 $this->assertEquals( true, 00682 $this->title->userCan( 'move-target', $this->user ) ); 00683 00684 $this->title->mInterwiki = "no"; 00685 $this->assertEquals( array( array( 'immobile-target-page' ) ), 00686 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); 00687 $this->assertEquals( false, 00688 $this->title->userCan( 'move-target', $this->user ) ); 00689 } 00690 00691 public function testUserBlock() { 00692 global $wgEmailConfirmToEdit, $wgEmailAuthentication; 00693 $wgEmailConfirmToEdit = true; 00694 $wgEmailAuthentication = true; 00695 00696 $this->setUserPerm( array( "createpage", "move" ) ); 00697 $this->setTitle( NS_HELP, "test page" ); 00698 00699 # $short 00700 $this->assertEquals( array( array( 'confirmedittext' ) ), 00701 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); 00702 $wgEmailConfirmToEdit = false; 00703 $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) ); 00704 00705 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' 00706 $this->assertEquals( array(), 00707 $this->title->getUserPermissionsErrors( 'move-target', 00708 $this->user ) ); 00709 00710 global $wgLang; 00711 $prev = time(); 00712 $now = time() + 120; 00713 $this->user->mBlockedby = $this->user->getId(); 00714 $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(), 00715 'no reason given', $prev + 3600, 1, 0 ); 00716 $this->user->mBlock->mTimestamp = 0; 00717 $this->assertEquals( array( array( 'autoblockedtext', 00718 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', 00719 'Useruser', null, 'infinite', '127.0.8.1', 00720 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ), 00721 $this->title->getUserPermissionsErrors( 'move-target', 00722 $this->user ) ); 00723 00724 $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) ); 00725 // quickUserCan should ignore user blocks 00726 $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) ); 00727 00728 global $wgLocalTZoffset; 00729 $wgLocalTZoffset = -60; 00730 $this->user->mBlockedby = $this->user->getName(); 00731 $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(), 00732 'no reason given', $now, 0, 10 ); 00733 $this->assertEquals( array( array( 'blockedtext', 00734 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', 00735 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', 00736 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ), 00737 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); 00738 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) 00739 # $user->blockedFor() == '' 00740 # $user->mBlock->mExpiry == 'infinity' 00741 } 00742 }