Hide Blocked Wiki Users

From WinWolf3D/WDC

If you're blocking spam bot users, you're going to get a bunch of blocked users, so it might be good to hide them on user list. Of course, we'll leave a way to bring them back, too.

There are two methods given here. The first alters the SQL to flag blocked users when they are to be shown and remove them when they are not. This also affects the user count displayed on user list. The second method alters the SQL to flag block users. They are later block when the page is built. Blocked users are skipped when the page is built and they are not to be shown. This means that the user count will include blocked users whether they are shown or not.

For example, say your wiki has 10 users, 2 of which are block. Method 1 will display the message "Showing below up to 8 results starting with #1" and method 2 will display "Showing below up to 10 results starting with #1". Choose whichever method you want.


For MediaWiki 1.5.2

includes/SpecialListusers.php

  • Find:
var $requestedUser = '';
  • Add AFTER:
var $hideBlocked = true;
  • Find:
$out .= '<input type="submit" /></form>';
  • Add AFTER:
$showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
global $wgUser, $wgLang, $wgContLang;
$sk = $wgUser->getSkin();
$out .= $sk->makeKnownLink( $wgContLang->specialPage( 'Listusers' ),
	$showhide[1-$this->hideBlocked], 
	wfArrayToCGI( array( 'hideblocked' => 1-$this->hideBlocked), 
		array('hideblocked' => $this->hideBlocked) ) );
$out .= ' blocked users';
  • Find:
$user_groups = $dbr->tableName( 'user_groups' );
  • Add AFTER:
$ipblocks = $dbr->tableName( 'ipblocks' );
  • Find:
"user_name as value, user_id, COUNT(ug_group) as numgroups " .
  • Add AFTER:
", case when ipb_user > 0 then 1 else 0 end as isblocked " .
  • Find:
function linkParameters() {
  • Find in linkParameters:
return $conds;
  • Add BEFORE:
if( !$this->hideBlocked ) {
	$conds['hideblocked'] = $this->hideBlocked ;
}
  • Find:
$name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
  • Add AFTER:
if ($result->isblocked) {
	$name .= ' (blocked)';
}
  • Find:
$slu->requestedUser = $wgRequest->getVal('username');
  • Add AFTER:
$slu->hideBlocked = $wgRequest->getBool( 'hideblocked', true);

Method 1

  • Find from top:
"LEFT JOIN $user_groups ON user_id=ug_user " .
  • Add AFTER:
	"LEFT JOIN $ipblocks ON user_id=ipb_user ";
$whereclause =
  • Find:
$this->userQueryWhere( $dbr ) .
  • Add AFTER:
	"";
if ($this->hideBlocked) {
	$sql .= ($whereclause == "" ? " WHERE " : "") .
		" ipb_user is null";
}
	$sql .=

Method 2

  • Find from top:
"LEFT JOIN $user_groups ON user_id=ug_user " .
  • Add AFTER:
"LEFT JOIN $ipblocks ON user_id=ipb_user " .
  • Find:
$userPage = Title::makeTitle( $result->namespace, $result->title );
  • Add BEFORE:
if ($this->hideBlocked) {
	if ($result->isblocked) {
		return "";
	}
}