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