Page MenuHomePhabricator

Aborting a block using BlockIp hook shows <hookaborted> on the block form
Closed, ResolvedPublic

Description

Author: Nx.devnull

Description:
Screenshot

The following simple extension will cancel the block, and the message "Block aborted" will be displayed at the top of the block form. However a large red <hookaborted> message will also be displayed, below blockiptext. The latter shouldn't be shown if the extension already returns an error message of its own, and should be something more user-friendly otherwise.

<?php

if ( !defined( 'MEDIAWIKI' ) ) {
exit;
}

$wgHooks['BlockIp'][] = 'BlockIpTest';

function BlockIpTest( &$ban, &$user ) {

return 'Block aborted';

}


Version: 1.15.x
Severity: enhancement

Attached:

Screenshot-hookaborted.png (578×1 px, 54 KB)

Details

Reference
bz22922

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:00 PM
bzimport set Reference to bz22922.
bzimport added a subscriber: Unknown Object (MLST).

happy.melon.wiki wrote:

Can you confirm whether this still occurs in trunk? The blocking system has been completely rewritten since 1.15.

Nx.devnull wrote:

It's slightly better in that it displays the message "The modification you tried to make was aborted by an extension hook." instead of <hookabort>, but it still doesn't allow the extension to customize that message, instead the extension's error message is outputted at the top and the title of the page changes to "internal error".

Nx.devnull wrote:

Quick and dirty hack

Here's a patch to show you a rough idea of what I'd like. Instead of returning a string, the extension can set the third parameter of the blockip hook and return false. The problem with this patch though is that it requires error to be a message key.

Attached:

Nx.devnull wrote:

And the extension to test this:

<?php

if ( !defined( 'MEDIAWIKI' ) ) {

exit;

}

$wgHooks['BlockIp'][] = 'BlockIpTest';

$wgExtensionMessagesFiles['PageList'] = dirname( FILE ) . '/blocktest.i18n.php';

function BlockIpTest( &$ban, &$user, &$error ) {

$error = 'test-abort';
return false;

}

and blocktest.i18n.php is:

<?php

$messages = array();

$messages['en'] = array(
'test-abort' => 'Testing block abort',
);

TTO subscribed.

This appears to have been done exactly as the previous commenter suggested. From SpecialBlock.php:

		$reason = [ 'hookaborted' ];
		if ( !Hooks::run( 'BlockIp', [ &$block, &$performer, &$reason ] ) ) {
			return $reason;
		}