Merge "actions: Update deprecated code in Actions::checkCanExecute()"

This commit is contained in:
jenkins-bot 2021-10-29 11:15:41 +00:00 committed by Gerrit Code Review
commit 5b27523cee
2 changed files with 10 additions and 8 deletions

View file

@ -328,9 +328,9 @@ abstract class Action implements MessageLocalizer {
*/
protected function checkCanExecute( User $user ) {
$right = $this->getRestriction();
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( $right !== null ) {
$errors = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $right, $user, $this->getTitle() );
$errors = $permissionManager->getPermissionErrors( $right, $user, $this->getTitle() );
if ( count( $errors ) ) {
throw new PermissionsError( $right, $errors );
}
@ -340,7 +340,7 @@ abstract class Action implements MessageLocalizer {
$checkReplica = !$this->getRequest()->wasPosted();
if (
$this->requiresUnblock() &&
$user->isBlockedFrom( $this->getTitle(), $checkReplica )
$permissionManager->isBlockedFrom( $user, $this->getTitle(), $checkReplica )
) {
$block = $user->getBlock();
if ( $block ) {
@ -358,7 +358,8 @@ abstract class Action implements MessageLocalizer {
// This should be checked at the end so that the user won't think the
// error is only temporary when he also don't have the rights to execute
// this action
if ( $this->requiresWrite() && wfReadOnly() ) {
$readOnlyMode = MediaWikiServices::getInstance()->getReadOnlyMode();
if ( $this->requiresWrite() && $readOnlyMode->isReadOnly() ) {
throw new ReadOnlyError();
}
}

View file

@ -1,6 +1,7 @@
<?php
use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Permissions\PermissionManager;
/**
* @covers Action
@ -286,14 +287,14 @@ class ActionTest extends MediaWikiIntegrationTestCase {
'sitewide' => false,
] );
$user->expects( $this->once() )
->method( 'isBlockedFrom' )
->with( $page->getTitle() )
->willReturn( true );
$user->expects( $this->once() )
->method( 'getBlock' )
->willReturn( $block );
$permissionManager = $this->createMock( PermissionManager::class );
$permissionManager->method( 'isBlockedFrom' )->willReturn( true );
$this->setService( 'PermissionManager', $permissionManager );
$this->expectException( UserBlockedError::class );
$action->canExecute( $user );
}