Page MenuHomePhabricator

Special:InvestigateBlock: RuntimeException: Can't reblock a user with multiple blocks already present.
Closed, ResolvedPublic2 Estimated Story PointsBUG REPORT

Description

What is the problem?

When using Special:InvestigateBlock to block a user or IP that already has more than one block against them, this exception is thrown:

[11d9e8a17daed5a3db7a0ee6] /wiki/Special:InvestigateBlock RuntimeException: Can\'t reblock a user with multiple blocks already present. Update calling code for multiblocks, providing a specific block to update.

Backtrace:

from /var/www/html/w/includes/block/BlockUser.php(628)
#0 /var/www/html/w/includes/block/BlockUser.php(566): MediaWiki\Block\BlockUser->placeBlockInternal()
#1 /var/www/html/w/includes/block/BlockUser.php(491): MediaWiki\Block\BlockUser->placeBlockUnsafe()
#2 /var/www/html/w/extensions/CheckUser/src/Investigate/SpecialInvestigateBlock.php(342): MediaWiki\Block\BlockUser->placeBlock()
#3 /var/www/html/w/includes/htmlform/HTMLForm.php(824): MediaWiki\CheckUser\Investigate\SpecialInvestigateBlock->onSubmit()
#4 /var/www/html/w/includes/htmlform/HTMLForm.php(705): MediaWiki\HTMLForm\HTMLForm->trySubmit()
#5 /var/www/html/w/includes/htmlform/HTMLForm.php(721): MediaWiki\HTMLForm\HTMLForm->tryAuthorizedSubmit()
#6 /var/www/html/w/includes/specialpage/FormSpecialPage.php(240): MediaWiki\HTMLForm\HTMLForm->show()
#7 /var/www/html/w/includes/specialpage/SpecialPage.php(729): MediaWiki\SpecialPage\FormSpecialPage->execute()
#8 /var/www/html/w/includes/specialpage/SpecialPageFactory.php(1737): MediaWiki\SpecialPage\SpecialPage->run()
#9 /var/www/html/w/includes/actions/ActionEntryPoint.php(503): MediaWiki\SpecialPage\SpecialPageFactory->executePath()
#10 /var/www/html/w/includes/actions/ActionEntryPoint.php(145): MediaWiki\Actions\ActionEntryPoint->performRequest()
#11 /var/www/html/w/includes/MediaWikiEntryPoint.php(202): MediaWiki\Actions\ActionEntryPoint->execute()
#12 /var/www/html/w/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#13 {main}

I don't know how Special:InvestigateBlock is supposed to handle multiblocks. This might need another task.

Steps to reproduce problem
  1. On a wiki with Codex Special:Block and Multiblocks enabled ($wgUseCodexSpecialBlock = true; $wgEnableMultiBlocks = true;)
  2. Use Special:Block to create two blocks against the same user or IP
  3. Go to Special:InvestigateBlock
  4. Enter the name of the user or IP from step 2
  5. Check "Override existing blocks"
  6. Add a reason
  7. Submit

Expected behaviour: Not exactly sure what the expected behaviour here should be...
Observed behaviour: The above exception.

Environment

Wiki(s): local docker MediaWiki 1.44.0-alpha (9669d77) 08:30, 3 March 2025. CheckUser 2.5 (3b8b9e1) 07:26, 3 March 2025.

Derived Requirements

  1. Special:InvestigateBlock must properly handle users or IPs with multiple existing blocks.
    • If multiple blocks exist, the system should provide a way to specify which block to update or prevent an override without a clear selection.
    • The system should not trigger a RuntimeException.
  1. Ensure that reblocking a user/IP with multiple blocks does not cause an error.
    • If reblocking is allowed, it should either merge, replace, or clearly communicate the expected outcome of the action.
    • If reblocking is not allowed, a user-friendly error message should be displayed instead of an exception.
  1. Implement logging and error handling for reblocking scenarios.
    • Block logs should correctly reflect the attempted actions on Special:InvestigateBlock.
    • If an action fails, a user-readable message should be logged instead of throwing a system-level exception.

Test Steps

    1. Test Case 1: Attempt to reblock a user/IP with multiple existing blocks
  1. Ensure that $wgUseCodexSpecialBlock = true; and $wgEnableMultiBlocks = true; are enabled.
  2. Navigate to Special:Block and create two separate blocks against the same user/IP.
  3. Navigate to Special:InvestigateBlock.
  4. Enter the username/IP from Step 2.
  5. Check "Override existing blocks" and enter a reason.
  6. Click Submit.
  7. AC1: Confirm that the system handles the request gracefully (e.g., prevents reblocking, allows specifying a block to update, or provides a clear error message)
    1. Test Case 2: Ensure reblocking a user/IP with a single block works correctly
  1. Navigate to Special:Block and create one block against a user/IP.
  2. Go to Special:InvestigateBlock and attempt to reblock the user/IP.
  3. AC2: Confirm that the reblock operation is successful and updates the block details correctly.

QA Results - Local

ACStatusDetails
1T387723#10671659
2T387723#10671659

Details

Related Changes in Gerrit:

Event Timeline

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

The form has a checkbox "override existing blocks". Do we really want to remove any number of existing blocks for each user when that is checked?

I think in multiblocks mode ($wgEnableMultiBlocks=true) we want the checkbox to say "add a new block even if the user is already blocked" or "add to existing blocks". Then we can pass CONFLICT_NEW and everything will work just fine. The user will be blocked with the specified message and expiry, and unlike pre-multiblocks, the admin doesn't have to worry about what blocks might exist already.

Additional context which may be useful in deciding an approach:

This override blocks checkbox is useful on WMF wikis because the block reason needed to be changed in cases where a CheckUser is marking the block as based on private evidence.

For example, on the English Wikipedia {{checkuserblock}} is used to indicate that administrators are not allowed to remove the block without consulting a CheckUser. This is often added to the reason for a pre-existing block without changing anything else about the block if the block is already sitewide.

I guess with multiblocks there won't be a "remove all blocks without seeing each block parameters" feature, so the administrator would still see the reason for the block they are removing and be able to check they are allowed to remove the block.

Change #1124904 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/extensions/CheckUser@master] Updates for multiblocks

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

Change #1124904 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Updates for multiblocks

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

GMikesell-WMF updated Other Assignee, added: GMikesell-WMF.
GMikesell-WMF updated the task description. (Show Details)

@tstarling Confirmed that the system handles the request gracefully (e.g., prevents reblocking, allows specifying a block to update, or provides a clear error message) as seen from the gifs below. I will mark this as Resolved. Thanks for all your work!

Test Result - Local

Status: ✅ PASS
Environment: Local MediaWiki:1.44.0-alpha (debaa0b) 14:39, 24 March 2025
OS: macOS Sequoia 15.4
Browser: Chrome 134
Device: MBA
Emulated Device: NA

Test Steps

    1. Test Case 1: Attempt to reblock a user/IP with multiple existing blocks
  1. Ensure that $wgUseCodexSpecialBlock = true; and $wgEnableMultiBlocks = true; are enabled.
  2. Navigate to Special:Block and create two separate blocks against the same user/IP.
  3. Navigate to Special:InvestigateBlock.
  4. Enter the username/IP from Step 2.
  5. Check "Override existing blocks" and enter a reason.
  6. Click Submit.
  7. AC1: Confirm that the system handles the request gracefully (e.g., prevents reblocking, allows specifying a block to update, or provides a clear error message)

2025-03-24_15-03-18.mp4.gif (952×1 px, 2 MB)

    1. Test Case 2: Ensure reblocking a user/IP with a single block works correctly
  1. Navigate to Special:Block and create one block against a user/IP.
  2. Go to Special:InvestigateBlock and attempt to reblock the user/IP.
  3. AC2: Confirm that the reblock operation is successful and updates the block details correctly.

2025-03-24_12-41-31.mp4.gif (850×1 px, 2 MB)

GMikesell-WMF updated the task description. (Show Details)
GMikesell-WMF updated Other Assignee, removed: GMikesell-WMF.