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