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