Page MenuHomePhabricator

Partial blocks leads to wrong error messages
Closed, ResolvedPublic2 Estimated Story Points

Description

In this case, wrong messages for attempting to undelete a page

Steps to reproduce:
1 Block an admin from editing a specific page
2 As that admin, attempt to undelete an older revision of that page (or the entire page, if deleted)

Expected result
Your username or IP address has been blocked from making changes to this page. You can still edit other pages on this wiki. (or a message like this)

Actual result
The action you have requested is limited to users in one of the groups: Administrators, Oversighters, Researchers, Check users.

This is based on SpecialUndelete.php including the following check:

protected function isAllowed( $permission, User $user = null ) {
	$user = $user ?: $this->getUser();
	$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
	if ( $this->mTargetObj !== null ) {
		return $permissionManager->userCan( $permission, $user, $this->mTargetObj );
	} else {
		return $permissionManager->userHasRight( $user, $permission );
	}
}

which doesn't differential between users who can undelete pages in general, but not the specific page in question, and those who cannot undelete at all. Splitting this so that if $user->isAllowed( $permission ); but not $permissionManager->userCan( $permission, $user, $this->mTargetObj ); it results in a different error should solve this

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Removing Wikimedia-production-error as this seems out of scope (no exception_id provided)

Removing Wikimedia-production-error as this seems out of scope (no exception_id provided)

What is the tag for a logic error in production code?

[OT] Why do you think that someone needs such a tag?

[OT] Why do you think that someone needs such a tag?

Because that is what is happening - the relevant user can undelete pages, since they are an administrator, but cannot undelete that specific page to due a partial block. The error message shouldn't say that they are unable to proceed based on their user groups, but rather based on the block

@DannyS712: My question was about the tag, not about an explanation what's happening

Oh. I thought it might help identify such errors. Sorry for the confusion

Niharika set the point value for this task to 2.

Change 548446 had a related patch set uploaded (by Tchanders; owner: Tchanders):
[mediawiki/core@master] Allow block error messages to be shown in Special:Undelete

https://gerrit.wikimedia.org/r/548446

This isn't caused by partial blocks; a sitewide blocked user trying to undelete a page will see the same message. But it would be good to fix, since it's confusing.

The problem is that by default special pages report a generic permission error via SpecialPage::displayRestrictionError. That method simply throws an PermissionsError, with the action associated with the special page in question (in this case 'deletedhistory').

Some special pages customise the permission checks to check for a block separately, or show the errors returned by the PermissionManager. We can customise Special:Undelete, but should be careful to preserve the following behaviour:

  • A user without the necessary permissions sees a permission error, whether blocked or not
  • A blocked user with the necessary permissions is still able to access Special:Undelete when no target is specified

Incidentally, FormSpecialPages have throwing a UserBlockError built in to their permission checks in FormSpecialPage::checkExecutePermissions. Perhaps all SpecialPages should have an option to do something like this rather than each implementing it their own way, though that's out of scope here.

For testing/reviewing, note also there are some complications with undeleting and partial blocks: T219305#5067588

Change 548446 merged by jenkins-bot:
[mediawiki/core@master] Allow block error messages to be shown in Special:Undelete

https://gerrit.wikimedia.org/r/548446

dom_walden subscribed.
  • A user without the necessary permissions sees a permission error, whether blocked or not

I tested with an anonymous user who was not blocked and a regular user who was sitewide blocked.

They both get permission error ("The action you have requested is limited to users in one of the groups: Administrators, oversight, researcher, Check users.") when they go to Special:Undelete and Special:Undelete/$article.

  • A blocked user with the necessary permissions is still able to access Special:Undelete when no target is specified

User with admin permissions sitewide blocked.

Can use Special:Undelete to search, and find pages they are blocked from.

Get block message on Special:Undelete/$page for any page.

This applies also to system blocks (if you remove 'ipblock-exempt' right from admins).

The exception is that if you are sitewide blocked, but not blocked from own User_talk, you cannot undelete your own User_talk. I think due to this logic here. This must be an old bug, so I will raise separately.

User with admin permissions partially blocked from article namespace.

Can use Special:Undelete to search, and find pages they are blocked from.

Gets block message on Special:Undelete/$article. Can undelete pages in User and User_talk namespace.

This applies also to composite blocks.

Testing was done on my local VM.