Skip to content

Commit

Permalink
Replace removed User::getRights (#206)
Browse files Browse the repository at this point in the history
* Replace removed User::getRights

Deprecated since 1.34

[master]

* Replace removed User::getRights

Deprecated since 1.34

[master]

* Replace removed User::getRights

Deprecated since 1.34

[master]

* Replace removed User::getRights

Deprecated since 1.34

[master]

* Replace removed User::getRights

Deprecated since 1.34

[master]
  • Loading branch information
HamishSlater authored Feb 27, 2023
1 parent 356d43f commit aafae46
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/PropertyAnnotators/PageContributorsPropertyAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SESP\PropertyAnnotators;

use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use SMW\DIProperty;
use SMW\DIWikiPage;
use SMW\SemanticData;
Expand Down Expand Up @@ -30,6 +32,7 @@ class PageContributorsPropertyAnnotator implements PropertyAnnotator {
* @var AppFactory
*/
private $appFactory;
private PermissionManager $permissionManager;

/**
* @since 2.0
Expand All @@ -38,6 +41,11 @@ class PageContributorsPropertyAnnotator implements PropertyAnnotator {
*/
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
$this->permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
}

public function setPermissionManager( PermissionManager $permissionManager ) {
$this->permissionManager = $permissionManager;
}

/**
Expand Down Expand Up @@ -87,7 +95,7 @@ public function addAnnotation( DIProperty $property, SemanticData $semanticData
}

private function isNotAnonymous( $user ) {
return !( in_array( 'bot', $user->getRights() ) && $this->appFactory->getOption( 'sespgExcludeBotEdits' ) ) && !$user->isAnon();
return !( in_array( 'bot', $this->permissionManager->getUserPermissions( $user ) ) && $this->appFactory->getOption( 'sespgExcludeBotEdits' ) ) && !$user->isAnon();
}

}
10 changes: 9 additions & 1 deletion src/PropertyAnnotators/UserRightPropertyAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SESP\PropertyAnnotators;

use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use SMW\DIProperty;
use SMW\SemanticData;
use SMWDataItem as DataItem;
Expand Down Expand Up @@ -30,6 +32,7 @@ class UserRightPropertyAnnotator implements PropertyAnnotator {
* @var AppFactory
*/
private $appFactory;
private PermissionManager $permissionManager;

/**
* @since 2.0
Expand All @@ -38,6 +41,11 @@ class UserRightPropertyAnnotator implements PropertyAnnotator {
*/
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
$this->permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
}

public function setPermissionManager( PermissionManager $permissionManager ) {
$this->permissionManager = $permissionManager;
}

/**
Expand Down Expand Up @@ -70,7 +78,7 @@ public function addAnnotation( DIProperty $property, SemanticData $semanticData
return;
}

foreach ( $user->getRights() as $right ) {
foreach ( $this->permissionManager->getUserPermissions( $user ) as $right ) {
$semanticData->addPropertyObjectValue( $property, new DIBlob( $right ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SESP\Tests\PropertyAnnotators;

use ArrayIterator;
use MediaWiki\Permissions\PermissionManager;
use SESP\AppFactory;
use SESP\PropertyAnnotators\PageContributorsPropertyAnnotator;
use SMW\DIProperty;
Expand Down Expand Up @@ -74,10 +75,6 @@ public function testAddAnnotation() {
->method( 'isAnon' )
->will( $this->returnValue( false ) );

$user->expects( $this->once() )
->method( 'getRights' )
->will( $this->returnValue( [] ) );

$wikiPage = $this->getMockBuilder( WikiPage::class )
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -109,10 +106,20 @@ public function testAddAnnotation() {
$semanticData->expects( $this->once() )
->method( 'addPropertyObjectValue' );

$permissionManager = $this->getMockBuilder( PermissionManager::class )
->disableOriginalConstructor()
->getMock();

$permissionManager->expects( $this->once() )
->method( 'getUserPermissions' )
->will( $this->returnValue( [] ) );

$instance = new PageContributorsPropertyAnnotator(
$this->appFactory
);

$instance->setPermissionManager( $permissionManager );

$instance->addAnnotation( $this->property, $semanticData );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SESP\Tests\PropertyAnnotators;

use MediaWiki\Permissions\PermissionManager;
use SESP\PropertyAnnotators\UserRightPropertyAnnotator;
use SMW\DIProperty;
use SMW\DIWikiPage;
Expand Down Expand Up @@ -58,10 +59,6 @@ public function testAddAnnotation( $rights, $expected ) {
->disableOriginalConstructor()
->getMock();

$user->expects( $this->once() )
->method( 'getRights' )
->will( $this->returnValue( $rights ) );

$this->appFactory->expects( $this->once() )
->method( 'newUserFromTitle' )
->will( $this->returnValue( $user ) );
Expand Down Expand Up @@ -93,10 +90,20 @@ public function testAddAnnotation( $rights, $expected ) {
$semanticData->expects( $expected )
->method( 'addPropertyObjectValue' );

$permissionManager = $this->getMockBuilder( PermissionManager::class )
->disableOriginalConstructor()
->getMock();

$permissionManager->expects( $this->once() )
->method( 'getUserPermissions' )
->will( $this->returnValue( $rights ) );

$instance = new UserRightPropertyAnnotator(
$this->appFactory
);

$instance->setPermissionManager( $permissionManager );

$instance->addAnnotation( $this->property, $semanticData );
}

Expand Down

0 comments on commit aafae46

Please sign in to comment.