2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Database
|
2013-10-24 20:30:43 +00:00
|
|
|
*
|
|
|
|
|
* @covers Title::getUserPermissionsErrors
|
|
|
|
|
* @covers Title::getUserPermissionsErrorsInternal
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
2011-06-22 21:02:07 +00:00
|
|
|
class TitlePermissionTest extends MediaWikiLangTestCase {
|
2011-10-14 21:18:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @var string
|
2011-10-14 21:18:38 +00:00
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
protected $userName, $altUserName;
|
2011-10-14 21:18:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @var Title
|
2011-10-14 21:18:38 +00:00
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
protected $title;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
|
|
|
|
protected $user, $anonUser, $userUser, $altUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$localZone = 'UTC';
|
|
|
|
|
$localOffset = date( 'Z' ) / 60;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2012-10-08 10:56:20 +00:00
|
|
|
'wgLocaltimezone' => $localZone,
|
|
|
|
|
'wgLocalTZoffset' => $localOffset,
|
2016-02-17 09:09:32 +00:00
|
|
|
'wgNamespaceProtection' => [
|
2012-10-08 10:56:20 +00:00
|
|
|
NS_MEDIAWIKI => 'editinterface',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
] );
|
2014-07-09 15:40:35 +00:00
|
|
|
// Without this testUserBlock will use a non-English context on non-English MediaWiki
|
|
|
|
|
// installations (because of how Title::checkUserBlock is implemented) and fail.
|
|
|
|
|
RequestContext::resetMain();
|
2012-10-08 10:56:20 +00:00
|
|
|
|
|
|
|
|
$this->userName = 'Useruser';
|
|
|
|
|
$this->altUserName = 'Altuseruser';
|
|
|
|
|
date_default_timezone_set( $localZone );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title = Title::makeTitle( NS_MAIN, "Main Page" );
|
2013-11-23 14:56:42 +00:00
|
|
|
if ( !isset( $this->userUser ) || !( $this->userUser instanceof User ) ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->userUser = User::newFromName( $this->userName );
|
2011-04-23 19:28:35 +00:00
|
|
|
|
2016-03-18 13:55:54 +00:00
|
|
|
if ( !$this->userUser->getId() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->userUser = User::createNew( $this->userName, [
|
2010-12-14 16:26:35 +00:00
|
|
|
"email" => "test@example.com",
|
2016-02-17 09:09:32 +00:00
|
|
|
"real_name" => "Test User" ] );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->userUser->load();
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2011-04-23 19:28:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->altUser = User::newFromName( $this->altUserName );
|
2016-03-18 13:55:54 +00:00
|
|
|
if ( !$this->altUser->getId() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->altUser = User::createNew( $this->altUserName, [
|
2010-12-14 16:26:35 +00:00
|
|
|
"email" => "alttest@example.com",
|
2016-02-17 09:09:32 +00:00
|
|
|
"real_name" => "Test User Alt" ] );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->altUser->load();
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->anonUser = User::newFromId( 0 );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->userUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2011-06-22 21:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function setUserPerm( $perm ) {
|
2011-07-16 16:09:00 +00:00
|
|
|
// Setting member variables is evil!!!
|
|
|
|
|
|
2011-12-12 06:03:01 +00:00
|
|
|
if ( is_array( $perm ) ) {
|
|
|
|
|
$this->user->mRights = $perm;
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->user->mRights = [ $perm ];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function setTitle( $ns, $title = "Main_Page" ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title = Title::makeTitle( $ns, $title );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function setUser( $userName = null ) {
|
2010-12-14 16:26:35 +00:00
|
|
|
if ( $userName === 'anon' ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->anonUser;
|
2011-06-17 16:05:35 +00:00
|
|
|
} elseif ( $userName === null || $userName === $this->userName ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->userUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
} else {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->altUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
|
|
|
|
*/
|
|
|
|
|
public function testQuickPermissions() {
|
2010-12-14 16:26:35 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ "nocreatetext" ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'nocreatetext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'nocreatetext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "movefile" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenotallowed' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "movefile" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( "" );
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->runGroupPermissions(
|
|
|
|
|
'move',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ]
|
2014-04-24 12:50:36 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( "" );
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->runGroupPermissions(
|
|
|
|
|
'move',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ],
|
|
|
|
|
[ [ 'movenotallowedfile' ], [ 'movenologintext' ] ]
|
2014-04-24 12:50:36 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-12 11:09:08 +00:00
|
|
|
if ( $this->isWikitextNS( NS_MAIN ) ) {
|
2015-09-11 13:44:59 +00:00
|
|
|
// NOTE: some content models don't allow moving
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo find a Wikitext namespace for testing
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( "" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ],
|
|
|
|
|
[ [ 'movenologintext' ] ] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setUser( $this->userName );
|
|
|
|
|
$this->setUserPerm( "" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( 'move' );
|
|
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'movenotallowed' ] ], $res );
|
2012-10-12 11:09:08 +00:00
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "move", "move-rootuserpages" ] );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'cant-move-to-user-page' ] ], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "move", "move-rootuserpages" ] );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER, "User/subpage" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "move", "move-rootuserpages" ] );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [], $res );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$check = [
|
|
|
|
|
'edit' => [
|
|
|
|
|
[ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[],
|
2014-04-24 12:50:36 +00:00
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'protect' => [
|
|
|
|
|
[ [
|
2014-04-24 12:50:36 +00:00
|
|
|
'badaccess-groups',
|
2016-02-17 09:09:32 +00:00
|
|
|
"[[$prefix:Administrators|Administrators]]", 1 ],
|
|
|
|
|
[ 'protect-cantedit'
|
|
|
|
|
] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'protect-cantedit' ] ],
|
|
|
|
|
[ [ 'protect-cantedit' ] ],
|
2014-04-24 12:50:36 +00:00
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'' => [ [], [], [], true ]
|
|
|
|
|
];
|
2012-10-10 17:18:12 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
foreach ( [ "edit", "protect", "" ] as $action ) {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( null );
|
|
|
|
|
$this->assertEquals( $check[$action][0],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, true ) );
|
2015-01-15 00:18:02 +00:00
|
|
|
$this->assertEquals( $check[$action][0],
|
|
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
|
|
|
|
|
$this->assertEquals( $check[$action][0],
|
|
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
global $wgGroupPermissions;
|
|
|
|
|
$old = $wgGroupPermissions;
|
2016-02-17 09:09:32 +00:00
|
|
|
$wgGroupPermissions = [];
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $check[$action][1],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, true ) );
|
2015-01-15 00:18:02 +00:00
|
|
|
$this->assertEquals( $check[$action][1],
|
|
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
|
|
|
|
|
$this->assertEquals( $check[$action][1],
|
|
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgGroupPermissions = $old;
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( $action );
|
|
|
|
|
$this->assertEquals( $check[$action][2],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, true ) );
|
2015-01-15 00:18:02 +00:00
|
|
|
$this->assertEquals( $check[$action][2],
|
|
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
|
|
|
|
|
$this->assertEquals( $check[$action][2],
|
|
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( $action );
|
|
|
|
|
$this->assertEquals( $check[$action][3],
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( $action, $this->user, true ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $check[$action][3],
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->quickUserCan( $action, $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
# count( User::getGroupsWithPermissions( $action ) ) < 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function runGroupPermissions( $action, $result, $result2 = null ) {
|
2010-12-14 16:26:35 +00:00
|
|
|
global $wgGroupPermissions;
|
|
|
|
|
|
2013-02-14 11:36:35 +00:00
|
|
|
if ( $result2 === null ) {
|
|
|
|
|
$result2 = $result;
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = false;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = false;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result, $res );
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = true;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = false;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2, $res );
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = true;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = true;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2, $res );
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = false;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = true;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2, $res );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
|
|
|
|
*/
|
|
|
|
|
public function testSpecialsAndNSPermissions() {
|
2012-10-08 10:56:20 +00:00
|
|
|
global $wgNamespaceProtection;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_SPECIAL );
|
2011-04-23 19:28:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ], [ 'ns-specialprotected' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( 'bogus' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( '' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$wgNamespaceProtection[NS_USER] = [ 'bogus' ];
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_USER );
|
|
|
|
|
$this->setUserPerm( '' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ],
|
|
|
|
|
[ 'namespaceprotected', 'User', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIAWIKI );
|
|
|
|
|
$this->setUserPerm( 'bogus' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIAWIKI );
|
|
|
|
|
$this->setUserPerm( 'bogus' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$wgNamespaceProtection = null;
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( 'bogus' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( '' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
|
|
|
|
*/
|
|
|
|
|
public function testCssAndJavascriptPermissions() {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2013-06-10 17:33:48 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/test.js' );
|
|
|
|
|
$this->runCSSandJSPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER, $this->userName . '/test.css' );
|
|
|
|
|
$this->runCSSandJSPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->runCSSandJSPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.css' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->runCSSandJSPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/tempo' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->runCSSandJSPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$this->assertEquals( $result0,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2013-06-10 17:33:48 +00:00
|
|
|
$this->setUserPerm( 'editmyusercss' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result1,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2013-06-10 17:33:48 +00:00
|
|
|
$this->setUserPerm( 'editmyuserjs' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2013-06-10 17:33:48 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( 'editusercss' );
|
|
|
|
|
$this->assertEquals( $result3,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( 'edituserjs' );
|
|
|
|
|
$this->assertEquals( $result4,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ 'edituserjs', 'editusercss' ] );
|
|
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
|
|
|
|
*/
|
|
|
|
|
public function testPageRestrictions() {
|
2012-10-10 17:18:12 +00:00
|
|
|
global $wgContLang;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mRestrictionsLoaded = true;
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "edit" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->title->mRestrictions = [ "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( true,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->quickUserCan( 'edit', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->title->mRestrictions = [ "edit" => [ 'bogus', "sysop", "protect", "" ],
|
|
|
|
|
"bogus" => [ 'bogus', "sysop", "protect", "" ] ];
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ],
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'editprotected', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'editprotected', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'edit' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ],
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'editprotected', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ],
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'editprotected', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'edit' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "edit", "editprotected" ] );
|
|
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ],
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'edit' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2013-06-28 17:20:00 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mCascadeRestriction = true;
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->setUserPerm( "edit" );
|
|
|
|
|
$this->assertEquals( false,
|
|
|
|
|
$this->title->quickUserCan( 'bogus', $this->user ) );
|
|
|
|
|
$this->assertEquals( false,
|
|
|
|
|
$this->title->quickUserCan( 'edit', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ],
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'editprotected', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'bogus' ] ],
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'editprotected', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'edit' ] ],
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "edit", "editprotected" ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->quickUserCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->quickUserCan( 'edit', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ],
|
|
|
|
|
[ 'protectedpagetext', 'bogus', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'bogus' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'edit' ],
|
|
|
|
|
[ 'protectedpagetext', 'protect', 'edit' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
public function testCascadingSourcesRestrictions() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "edit", "bogus" ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->title->mCascadeSources = [
|
2014-04-24 12:50:36 +00:00
|
|
|
Title::makeTitle( NS_MAIN, "Bogus" ),
|
|
|
|
|
Title::makeTitle( NS_MAIN, "UnBogus" )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
|
|
|
|
$this->title->mCascadingRestrictions = [
|
2016-05-12 21:43:06 +00:00
|
|
|
"bogus" => [ 'bogus', "sysop", "protect", "" ]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'bogus', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [
|
|
|
|
|
[ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
|
|
|
|
|
[ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
|
|
|
|
|
[ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( true,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'edit', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
|
|
|
|
*/
|
|
|
|
|
public function testActionPermissions() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "createpage" ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
2014-10-11 05:43:02 +00:00
|
|
|
$this->title->mTitleProtection['permission'] = '';
|
2016-03-19 00:08:06 +00:00
|
|
|
$this->title->mTitleProtection['user'] = $this->user->getId();
|
Clean up handling of 'infinity'
There's a bunch of stuff that probably only works because the database
representation of infinity is actually 'infinity' on all databases
besides Oracle, and Oracle in general isn't maintained.
Generally, we should probably use 'infinity' everywhere except where
directly dealing with the database.
* Many extension callers of Language::formatExpiry() with $format !==
true are assuming it'll return 'infinity', none are checking for
$db->getInfinity().
* And Language::formatExpiry() would choke if passed 'infinity', despite
callers doing this.
* And Language::formatExpiry() could be more useful for the API if we
can override the string returned for infinity.
* As for core, Title is using Language::formatExpiry() with TS_MW which
is going to be changing anyway. Extension callers mostly don't exist.
* Block already normalizes its mExpiry field (and ->getExpiry()),
but some stuff is comparing it with $db->getInfinity() anyway. A few
external users set mExpiry to $db->getInfinity(), but this is mostly
because SpecialBlock::parseExpiryInput() returns $db->getInfinity()
while most callers (including all extensions) are assuming 'infinity'.
* And for that matter, Block should use $db->decodeExpiry() instead of
manually doing it, once we make that safe to call with 'infinity' for
all the extensions passing $db->getInfinity() to Block's contructor.
* WikiPage::doUpdateRestrictions() and some of its callers are using
$db->getInfinity(), when all the inserts using that value are using
$db->encodeExpiry() which will convert 'infinity'.
This also cleans up a slave-lag issue I noticed in ApiBlock while
testing.
Bug: T92550
Change-Id: I5eb68c1fb6029da8289276ecf7c81330575029ef
2015-03-12 16:37:04 +00:00
|
|
|
$this->title->mTitleProtection['expiry'] = 'infinity';
|
2014-10-11 05:43:02 +00:00
|
|
|
$this->title->mTitleProtection['reason'] = 'test';
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mCascadeRestriction = false;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2014-10-11 05:43:02 +00:00
|
|
|
$this->title->mTitleProtection['permission'] = 'editprotected';
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ 'createpage', 'protect' ] );
|
|
|
|
|
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
|
|
|
|
$this->assertEquals( false,
|
|
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ 'createpage', 'editprotected' ] );
|
|
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ 'createpage' ] );
|
|
|
|
|
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIA, "test page" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "move" ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'immobile-source-namespace', 'Media' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mInterwiki = "no";
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'immobile-source-page' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIA, "test page" );
|
|
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'immobile-target-namespace', 'Media' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mInterwiki = "no";
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'immobile-target-page' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
public function testUserBlock() {
|
2012-10-10 17:18:12 +00:00
|
|
|
global $wgEmailConfirmToEdit, $wgEmailAuthentication;
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgEmailConfirmToEdit = true;
|
|
|
|
|
$wgEmailAuthentication = true;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setUserPerm( [ "createpage", "move" ] );
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
# $short
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'confirmedittext' ] ],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgEmailConfirmToEdit = false;
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
# $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
global $wgLang;
|
|
|
|
|
$prev = time();
|
|
|
|
|
$now = time() + 120;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlockedby = $this->user->getId();
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->user->mBlock = new Block( [
|
2014-05-22 14:45:46 +00:00
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'by' => $this->user->getId(),
|
|
|
|
|
'reason' => 'no reason given',
|
|
|
|
|
'timestamp' => $prev + 3600,
|
|
|
|
|
'auto' => true,
|
|
|
|
|
'expiry' => 0
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlock->mTimestamp = 0;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'autoblockedtext',
|
2013-02-14 11:36:35 +00:00
|
|
|
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
|
|
|
|
|
'Useruser', null, 'infinite', '127.0.8.1',
|
2016-02-17 09:09:32 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target',
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
|
2011-05-04 11:51:38 +00:00
|
|
|
// quickUserCan should ignore user blocks
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-07-02 11:11:01 +00:00
|
|
|
global $wgLocalTZoffset;
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgLocalTZoffset = -60;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlockedby = $this->user->getName();
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->user->mBlock = new Block( [
|
2014-05-22 14:45:46 +00:00
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'by' => $this->user->getId(),
|
|
|
|
|
'reason' => 'no reason given',
|
|
|
|
|
'timestamp' => $now,
|
|
|
|
|
'auto' => false,
|
|
|
|
|
'expiry' => 10,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
|
|
|
|
$this->assertEquals( [ [ 'blockedtext',
|
2013-02-14 11:36:35 +00:00
|
|
|
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
|
|
|
|
|
'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
|
2016-02-17 09:09:32 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
# $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
|
|
|
|
|
# $user->blockedFor() == ''
|
|
|
|
|
# $user->mBlock->mExpiry == 'infinity'
|
2016-12-01 16:51:03 +00:00
|
|
|
|
|
|
|
|
$this->user->mBlockedby = $this->user->getName();
|
|
|
|
|
$this->user->mBlock = new Block( [
|
|
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'by' => $this->user->getId(),
|
|
|
|
|
'reason' => 'no reason given',
|
|
|
|
|
'timestamp' => $now,
|
|
|
|
|
'auto' => false,
|
|
|
|
|
'expiry' => 10,
|
|
|
|
|
'systemBlock' => 'test',
|
|
|
|
|
] );
|
|
|
|
|
$this->assertEquals( [ [ 'systemblockedtext',
|
|
|
|
|
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
|
|
|
|
|
'Useruser', 'test', '23:00, 31 December 1969', '127.0.8.1',
|
|
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|