2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2018-12-06 20:35:40 +00:00
|
|
|
use MediaWiki\Block\Restriction\PageRestriction;
|
Separate Block into AbstractBlock, Block and SystemBlock
This commit splits the existing Block class into AbstractBlock, Block
and SystemBlock.
Before this patch, the Block class represents several types of
blocks, which can be separated into blocks stored in the database,
and temporary blocks created by the system. These are now
represented by Block and SystemBlock, which inherit from
AbstractBlock.
This lays the foundations for:
* enforcing block parameters from multiple blocks that apply to a
user/IP address
* improvements to the Block API, including the addition of services
Breaking changes: functions expecting a Block object should still
expect a Block object if it came from the database, but other
functions may now need to expect an AbstractBlock or SystemBlock
object. (Note that an alternative naming scheme, in which the
abstract class is called Block and the subclasses are DatabaseBlock
and SystemBlock, avoids this breakage. However, it introduces more
breakages to calls to static Block methods and new Block
instantiations.)
Changes to tests: system blocks don't set the $blockCreateAccount or
$mExipry block properties, so remove/change any tests that assume
they do.
Bug: T222737
Change-Id: I83bceb5e5049e254c90ace060f8f8fad44696c67
2019-03-18 22:09:49 +00:00
|
|
|
use MediaWiki\Block\SystemBlock;
|
2018-07-29 12:24:54 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-12-06 20:39:40 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2018-07-29 12:24:54 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
2013-10-24 20:30:43 +00:00
|
|
|
*
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::getPermissionErrors
|
|
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::getPermissionErrorsInternal
|
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
|
|
|
|
2019-10-20 18:11:08 +00:00
|
|
|
protected function setUp() : void {
|
2012-10-08 10:56:20 +00:00
|
|
|
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
|
|
|
}
|
2019-05-30 13:51:37 +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
|
2018-10-09 01:21:00 +00:00
|
|
|
*
|
|
|
|
|
* This test is failing per T201776.
|
|
|
|
|
*
|
|
|
|
|
* @group Broken
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkQuickPermissions
|
2013-10-21 21:09:13 +00:00
|
|
|
*/
|
|
|
|
|
public function testQuickPermissions() {
|
2020-02-22 01:24:17 +00:00
|
|
|
$this->hideDeprecated( 'Title::userCan' );
|
|
|
|
|
$this->hideDeprecated( 'Title::quickUserCan' );
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2020-02-22 01:24:17 +00:00
|
|
|
|
2018-07-29 12:24:54 +00:00
|
|
|
$prefix = MediaWikiServices::getInstance()->getContentLanguage()->
|
|
|
|
|
getFormattedNsText( NS_PROJECT );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setTitle( NS_TALK );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "" );
|
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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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 . '' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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 . '' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 . '' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "" );
|
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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "" );
|
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 . '' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "" );
|
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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "move" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runGroupPermissions( 'move', [] );
|
2012-10-12 11:09:08 +00:00
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'move' );
|
2012-10-12 11:09:08 +00:00
|
|
|
$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
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
2012-10-12 11:09:08 +00:00
|
|
|
$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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "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
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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' );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "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" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "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
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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 ) {
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$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],
|
2019-12-06 20:39:40 +00:00
|
|
|
$this->title->getUserPermissionsErrors(
|
|
|
|
|
$action, $this->user, PermissionManager::RIGOR_FULL ) );
|
2015-01-15 00:18:02 +00:00
|
|
|
$this->assertEquals( $check[$action][0],
|
2019-12-06 20:39:40 +00:00
|
|
|
$this->title->getUserPermissionsErrors(
|
|
|
|
|
$action, $this->user, PermissionManager::RIGOR_SECURE ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
global $wgGroupPermissions;
|
|
|
|
|
$old = $wgGroupPermissions;
|
2019-08-26 09:13:49 +00:00
|
|
|
$this->setMwGlobals( 'wgGroupPermissions', [] );
|
2019-04-09 06:58:04 +00:00
|
|
|
|
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],
|
2019-12-06 20:39:40 +00:00
|
|
|
$this->title->getUserPermissionsErrors(
|
|
|
|
|
$action, $this->user, PermissionManager::RIGOR_FULL ) );
|
2015-01-15 00:18:02 +00:00
|
|
|
$this->assertEquals( $check[$action][1],
|
2019-12-06 20:39:40 +00:00
|
|
|
$this->title->getUserPermissionsErrors(
|
|
|
|
|
$action, $this->user, PermissionManager::RIGOR_SECURE ) );
|
2019-04-09 06:58:04 +00:00
|
|
|
|
2019-08-26 09:13:49 +00:00
|
|
|
$this->setMwGlobals( 'wgGroupPermissions', $old );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, $action );
|
2010-12-14 16:26:35 +00:00
|
|
|
$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],
|
2019-12-06 20:39:40 +00:00
|
|
|
$this->title->getUserPermissionsErrors(
|
|
|
|
|
$action, $this->user, PermissionManager::RIGOR_FULL ) );
|
2015-01-15 00:18:02 +00:00
|
|
|
$this->assertEquals( $check[$action][2],
|
2019-12-06 20:39:40 +00:00
|
|
|
$this->title->getUserPermissionsErrors(
|
|
|
|
|
$action, $this->user, PermissionManager::RIGOR_SECURE ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, $action );
|
2010-12-14 16:26:35 +00:00
|
|
|
$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 ) {
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2013-02-14 11:36:35 +00:00
|
|
|
if ( $result2 === null ) {
|
|
|
|
|
$result2 = $result;
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
// XXX: there could be a better way to handle this, but since we need to
|
|
|
|
|
// override PermissionManager service each time globals are changed
|
|
|
|
|
// and in the same time we need to keep user permissions overrides from the outside
|
|
|
|
|
// the best we can do inside this method is to save & restore faked user perms
|
|
|
|
|
|
|
|
|
|
$userPermsOverrides = MediaWikiServices::getInstance()->getPermissionManager()
|
|
|
|
|
->getUserPermissions( $this->user );
|
|
|
|
|
|
2019-08-26 09:13:49 +00:00
|
|
|
$this->setGroupPermissions( 'autoconfirmed', 'move', false );
|
|
|
|
|
$this->setGroupPermissions( 'user', 'move', false );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, $userPermsOverrides );
|
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 );
|
|
|
|
|
|
2019-08-26 09:13:49 +00:00
|
|
|
$this->setGroupPermissions( 'autoconfirmed', 'move', true );
|
|
|
|
|
$this->setGroupPermissions( 'user', 'move', false );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, $userPermsOverrides );
|
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 );
|
|
|
|
|
|
2019-08-26 09:13:49 +00:00
|
|
|
$this->setGroupPermissions( 'autoconfirmed', 'move', true );
|
|
|
|
|
$this->setGroupPermissions( 'user', 'move', true );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, $userPermsOverrides );
|
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 );
|
|
|
|
|
|
2019-08-26 09:13:49 +00:00
|
|
|
$this->setGroupPermissions( 'autoconfirmed', 'move', false );
|
|
|
|
|
$this->setGroupPermissions( 'user', 'move', true );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, $userPermsOverrides );
|
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
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkSpecialsAndNSPermissions
|
2013-10-21 21:09:13 +00:00
|
|
|
*/
|
|
|
|
|
public function testSpecialsAndNSPermissions() {
|
2020-02-22 01:24:17 +00:00
|
|
|
$this->hideDeprecated( 'Title::userCan' );
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2020-02-22 01:24:17 +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_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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, '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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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
|
|
|
|
2019-08-23 15:33:21 +00:00
|
|
|
$this->mergeMwGlobalArrayValue( 'wgNamespaceProtection', [
|
|
|
|
|
NS_USER => [ 'bogus' ]
|
|
|
|
|
] );
|
|
|
|
|
$this->resetServices();
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_USER );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, '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 );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, '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
|
|
|
|
2019-08-23 15:33:21 +00:00
|
|
|
$this->setMwGlobals( 'wgNamespaceProtection', null );
|
|
|
|
|
$this->resetServices();
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, '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 ) );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $this->title->userCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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 ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2013-10-21 21:09:13 +00:00
|
|
|
*/
|
2018-02-13 00:15:30 +00:00
|
|
|
public function testJsConfigEditPermissions() {
|
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' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$this->runConfigEditPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2018-02-13 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-02-13 00:20:05 +00:00
|
|
|
*/
|
|
|
|
|
public function testJsonConfigEditPermissions() {
|
2018-10-03 16:47:14 +00:00
|
|
|
$prefix = MediaWikiServices::getInstance()->getContentLanguage()->
|
|
|
|
|
getFormattedNsText( NS_PROJECT );
|
2018-02-13 00:20:05 +00:00
|
|
|
$this->setUser( $this->userName );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER, $this->userName . '/test.json' );
|
|
|
|
|
$this->runConfigEditPermissions(
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
|
|
|
|
|
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
|
|
|
|
|
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2018-02-13 00:20:05 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:15:30 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-02-13 00:15:30 +00:00
|
|
|
*/
|
|
|
|
|
public function testCssConfigEditPermissions() {
|
|
|
|
|
$this->setUser( $this->userName );
|
2013-06-10 17:33:48 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER, $this->userName . '/test.css' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$this->runConfigEditPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2018-02-13 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-02-13 00:15:30 +00:00
|
|
|
*/
|
|
|
|
|
public function testOtherJsConfigEditPermissions() {
|
|
|
|
|
$this->setUser( $this->userName );
|
2013-06-10 17:33:48 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$this->runConfigEditPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2018-02-13 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-02-13 00:20:05 +00:00
|
|
|
*/
|
|
|
|
|
public function testOtherJsonConfigEditPermissions() {
|
|
|
|
|
$this->setUser( $this->userName );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.json' );
|
|
|
|
|
$this->runConfigEditPermissions(
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
|
|
|
|
|
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
|
|
|
|
|
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2018-02-13 00:20:05 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:15:30 +00:00
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-02-13 00:15:30 +00:00
|
|
|
*/
|
|
|
|
|
public function testOtherCssConfigEditPermissions() {
|
|
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.css' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$this->runConfigEditPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2018-02-13 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo This test method should be split up into separate test methods and
|
|
|
|
|
* data providers
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-02-13 00:15:30 +00:00
|
|
|
*/
|
|
|
|
|
public function testOtherNonConfigEditPermissions() {
|
|
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/tempo' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$this->runConfigEditPermissions(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-02-13 00:15:30 +00:00
|
|
|
|
2018-02-13 00:20:05 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-03 16:47:14 +00:00
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2018-10-03 16:47:14 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo This should use data providers like the other methods here.
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
|
2018-10-03 16:47:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testPatrolActionConfigEditPermissions() {
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setTitle( NS_USER, 'ToPatrolOrNotToPatrol' );
|
|
|
|
|
$this->runConfigEditPermissions(
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
|
|
|
|
[ [ 'badaccess-group0' ] ],
|
2018-10-04 13:52:41 +00:00
|
|
|
[ [ 'badaccess-groups' ] ]
|
2013-06-10 17:33:48 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:15:30 +00:00
|
|
|
protected function runConfigEditPermissions(
|
|
|
|
|
$resultNone,
|
|
|
|
|
$resultMyCss,
|
2018-02-13 00:20:05 +00:00
|
|
|
$resultMyJson,
|
2018-02-13 00:15:30 +00:00
|
|
|
$resultMyJs,
|
|
|
|
|
$resultUserCss,
|
2018-02-13 00:20:05 +00:00
|
|
|
$resultUserJson,
|
2018-10-03 16:47:14 +00:00
|
|
|
$resultUserJs,
|
|
|
|
|
$resultPatrol
|
2018-02-13 00:15:30 +00:00
|
|
|
) {
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
|
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
2018-02-13 00:15:30 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultNone, $result );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'editmyusercss' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultMyCss, $result );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'editmyuserjson' );
|
2018-02-13 00:20:05 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultMyJson, $result );
|
|
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'editmyuserjs' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultMyJs, $result );
|
2013-06-10 17:33:48 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'editusercss' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultUserCss, $result );
|
2013-06-10 17:33:48 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'edituserjson' );
|
2018-02-13 00:20:05 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultUserJson, $result );
|
|
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, 'edituserjs' );
|
2018-02-13 00:15:30 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( $resultUserJs, $result );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
2018-10-03 20:42:55 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'patrol', $this->user );
|
2018-10-04 13:52:41 +00:00
|
|
|
$this->assertEquals( reset( $resultPatrol[0] ), reset( $result[0] ) );
|
2018-10-03 20:42:55 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ 'edituserjs', 'edituserjson', 'editusercss' ] );
|
2018-02-13 00:15:30 +00:00
|
|
|
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
|
|
|
|
|
$this->assertEquals( [ [ 'badaccess-group0' ] ], $result );
|
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
|
2018-10-09 01:21:00 +00:00
|
|
|
*
|
|
|
|
|
* This test is failing per T201776.
|
|
|
|
|
*
|
|
|
|
|
* @group Broken
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkPageRestrictions
|
2013-10-21 21:09:13 +00:00
|
|
|
*/
|
|
|
|
|
public function testPageRestrictions() {
|
2020-02-22 01:24:17 +00:00
|
|
|
$this->hideDeprecated( 'Title::quickUserCan' );
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2020-02-22 01:24:17 +00:00
|
|
|
|
2018-07-29 12:24:54 +00:00
|
|
|
$prefix = MediaWikiServices::getInstance()->getContentLanguage()->
|
|
|
|
|
getFormattedNsText( NS_PROJECT );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mRestrictionsLoaded = true;
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "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
|
|
|
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $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 ) );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user );
|
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 ) );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$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;
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, "edit" );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->title->quickUserCan( 'bogus', $this->user ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
2013-06-28 17:20:00 +00:00
|
|
|
$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 ) );
|
|
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->quickUserCan( 'bogus', $this->user ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:15:30 +00:00
|
|
|
/**
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkCascadingSourcesRestrictions
|
2018-02-13 00:15:30 +00:00
|
|
|
*/
|
2013-10-21 21:09:13 +00:00
|
|
|
public function testCascadingSourcesRestrictions() {
|
2020-02-22 01:24:17 +00:00
|
|
|
$this->hideDeprecated( 'Title::userCan' );
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2020-02-22 01:24:17 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "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
|
|
|
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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
|
|
|
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $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
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkActionPermissions
|
2013-10-21 21:09:13 +00:00
|
|
|
*/
|
|
|
|
|
public function testActionPermissions() {
|
2020-02-22 01:24:17 +00:00
|
|
|
$this->hideDeprecated( 'Title::userCan' );
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2020-02-22 01:24:17 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "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 ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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';
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ 'createpage', 'protect' ] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
2013-06-28 17:20:00 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
|
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ 'createpage', 'editprotected' ] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ 'createpage' ] );
|
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 ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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" );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $this->user, [ "move" ] );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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 ) );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $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 ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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" );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
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 ) );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $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 ) );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse(
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 00:15:30 +00:00
|
|
|
/**
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserBlock
|
2018-02-13 00:15:30 +00:00
|
|
|
*/
|
2013-10-21 21:09:13 +00:00
|
|
|
public function testUserBlock() {
|
2020-02-22 01:24:17 +00:00
|
|
|
$this->hideDeprecated( 'Title::userCan' );
|
|
|
|
|
$this->hideDeprecated( 'Title::quickUserCan' );
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
2020-02-22 01:24:17 +00:00
|
|
|
|
2016-08-26 01:29:58 +00:00
|
|
|
$this->setMwGlobals( [
|
|
|
|
|
'wgEmailConfirmToEdit' => true,
|
|
|
|
|
'wgEmailAuthentication' => true,
|
2019-04-14 13:28:06 +00:00
|
|
|
'wgBlockDisablesLogin' => false,
|
2016-08-26 01:29:58 +00:00
|
|
|
] );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions(
|
|
|
|
|
$this->user,
|
|
|
|
|
[ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ]
|
|
|
|
|
);
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2016-08-26 01:29:58 +00:00
|
|
|
# $wgEmailConfirmToEdit only applies to 'edit' action
|
|
|
|
|
$this->assertEquals( [],
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2016-08-26 01:29:58 +00:00
|
|
|
$this->assertContains( [ 'confirmedittext' ],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgEmailConfirmToEdit', false );
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions(
|
|
|
|
|
$this->user,
|
|
|
|
|
[ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ]
|
|
|
|
|
);
|
2019-03-07 20:02:07 +00:00
|
|
|
|
2016-08-26 01:29:58 +00:00
|
|
|
$this->assertNotContains( [ 'confirmedittext' ],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $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();
|
2019-05-13 14:18:07 +00:00
|
|
|
$this->user->mBlock = new DatabaseBlock( [
|
2014-05-22 14:45:46 +00:00
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'by' => $this->user->getId(),
|
|
|
|
|
'reason' => 'no reason given',
|
2019-08-25 15:04:19 +00:00
|
|
|
'timestamp' => $prev,
|
2014-05-22 14:45:46 +00:00
|
|
|
'auto' => true,
|
|
|
|
|
'expiry' => 0
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
|
|
|
|
$this->assertEquals( [ [ 'autoblockedtext',
|
2019-06-27 18:24:52 +00:00
|
|
|
"[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
|
|
|
|
|
"\u{202A}Useruser\u{202C}", 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
|
|
|
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse( $this->title->userCan( 'move-target', $this->user ) );
|
2011-05-04 11:51:38 +00:00
|
|
|
// quickUserCan should ignore user blocks
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $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();
|
2019-05-13 14:18:07 +00:00
|
|
|
$this->user->mBlock = new DatabaseBlock( [
|
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',
|
2019-06-27 18:24:52 +00:00
|
|
|
"[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
|
|
|
|
|
"\u{202A}Useruser\u{202C}", 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();
|
Separate Block into AbstractBlock, Block and SystemBlock
This commit splits the existing Block class into AbstractBlock, Block
and SystemBlock.
Before this patch, the Block class represents several types of
blocks, which can be separated into blocks stored in the database,
and temporary blocks created by the system. These are now
represented by Block and SystemBlock, which inherit from
AbstractBlock.
This lays the foundations for:
* enforcing block parameters from multiple blocks that apply to a
user/IP address
* improvements to the Block API, including the addition of services
Breaking changes: functions expecting a Block object should still
expect a Block object if it came from the database, but other
functions may now need to expect an AbstractBlock or SystemBlock
object. (Note that an alternative naming scheme, in which the
abstract class is called Block and the subclasses are DatabaseBlock
and SystemBlock, avoids this breakage. However, it introduces more
breakages to calls to static Block methods and new Block
instantiations.)
Changes to tests: system blocks don't set the $blockCreateAccount or
$mExipry block properties, so remove/change any tests that assume
they do.
Bug: T222737
Change-Id: I83bceb5e5049e254c90ace060f8f8fad44696c67
2019-03-18 22:09:49 +00:00
|
|
|
$this->user->mBlock = new SystemBlock( [
|
2016-12-01 16:51:03 +00:00
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'reason' => 'no reason given',
|
|
|
|
|
'timestamp' => $now,
|
|
|
|
|
'systemBlock' => 'test',
|
|
|
|
|
] );
|
2018-12-06 20:35:40 +00:00
|
|
|
|
|
|
|
|
$errors = [ [ 'systemblockedtext',
|
2019-09-05 21:25:33 +00:00
|
|
|
"", 'no reason given', '127.0.0.1',
|
|
|
|
|
"", 'test', 'infinite', '127.0.8.1',
|
2018-12-06 20:35:40 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
|
|
|
|
$this->assertEquals( $errors,
|
2016-12-01 16:51:03 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2018-12-06 20:35:40 +00:00
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
|
|
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
|
|
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'upload', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'purge', $this->user ) );
|
2018-08-27 01:45:18 +00:00
|
|
|
|
|
|
|
|
// partial block message test
|
|
|
|
|
$this->user->mBlockedby = $this->user->getName();
|
2019-05-13 14:18:07 +00:00
|
|
|
$this->user->mBlock = new DatabaseBlock( [
|
2018-08-27 01:45:18 +00:00
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'by' => $this->user->getId(),
|
|
|
|
|
'reason' => 'no reason given',
|
|
|
|
|
'timestamp' => $now,
|
|
|
|
|
'sitewide' => false,
|
|
|
|
|
'expiry' => 10,
|
|
|
|
|
] );
|
|
|
|
|
|
2018-12-06 20:35:40 +00:00
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'upload', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'purge', $this->user ) );
|
|
|
|
|
|
|
|
|
|
$this->user->mBlock->setRestrictions( [
|
|
|
|
|
( new PageRestriction( 0, $this->title->getArticleID() ) )->setTitle( $this->title ),
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$errors = [ [ 'blockedtext-partial',
|
2019-06-27 18:24:52 +00:00
|
|
|
"[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
|
|
|
|
|
"\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1',
|
2018-12-06 20:35:40 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
|
|
|
|
$this->assertEquals( $errors,
|
2018-08-27 01:45:18 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2018-12-06 20:35:40 +00:00
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
|
|
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'upload', $this->user ) );
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'purge', $this->user ) );
|
2019-02-16 06:08:10 +00:00
|
|
|
|
|
|
|
|
// Test no block.
|
|
|
|
|
$this->user->mBlockedby = null;
|
|
|
|
|
$this->user->mBlock = null;
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( [],
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2019-02-20 03:18:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-03-07 20:02:07 +00:00
|
|
|
* @covers \MediaWiki\Permissions\PermissionManager::checkUserBlock
|
2019-02-20 03:18:14 +00:00
|
|
|
*
|
|
|
|
|
* Tests to determine that the passed in permission does not get mixed up with
|
|
|
|
|
* an action of the same name.
|
|
|
|
|
*/
|
|
|
|
|
public function testUserBlockAction() {
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->hideDeprecated( 'Title::getUserPermissionsErrors' );
|
|
|
|
|
|
2019-02-20 03:18:14 +00:00
|
|
|
global $wgLang;
|
|
|
|
|
|
|
|
|
|
$tester = $this->getMockBuilder( Action::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$tester->method( 'getName' )
|
|
|
|
|
->willReturn( 'tester' );
|
|
|
|
|
$tester->method( 'getRestriction' )
|
|
|
|
|
->willReturn( 'test' );
|
|
|
|
|
$tester->method( 'requiresUnblock' )
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
|
'wgActions' => [
|
|
|
|
|
'tester' => $tester,
|
|
|
|
|
],
|
|
|
|
|
'wgGroupPermissions' => [
|
|
|
|
|
'*' => [
|
|
|
|
|
'tester' => true,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
|
$this->user->mBlockedby = $this->user->getName();
|
2019-05-13 14:18:07 +00:00
|
|
|
$this->user->mBlock = new DatabaseBlock( [
|
2019-02-20 03:18:14 +00:00
|
|
|
'address' => '127.0.8.1',
|
|
|
|
|
'by' => $this->user->getId(),
|
|
|
|
|
'reason' => 'no reason given',
|
|
|
|
|
'timestamp' => $now,
|
|
|
|
|
'auto' => false,
|
|
|
|
|
'expiry' => 'infinity',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$errors = [ [ 'blockedtext',
|
2019-06-27 18:24:52 +00:00
|
|
|
"[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
|
|
|
|
|
"\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1',
|
2019-02-20 03:18:14 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $errors,
|
|
|
|
|
$this->title->getUserPermissionsErrors( 'tester', $this->user ) );
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|