summaryrefslogtreecommitdiff
path: root/maintenance/removeUnusedAccounts.inc
blob: ac15ebef820a6acc56fa2bff5b3582c7a47ec515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

/**
 * Support functions for the removeUnusedAccounts maintenance script
 *
 *
 * @package MediaWiki
 * @subpackage Maintenance
 * @author Rob Church <robchur@gmail.com>
 */

/**
 * Could the specified user account be deemed inactive?
 * (No edits, no deleted edits, no log entries, no current/old uploads)
 *
 * @param $id User's ID
 * @param $master Perform checking on the master
 * @return bool
 */
function isInactiveAccount( $id, $master = false ) {
	$dbo =& wfGetDB( $master ? DB_MASTER : DB_SLAVE );
	$fname = 'isInactiveAccount';
	$checks = array( 'revision' => 'rev', 'archive' => 'ar', 'logging' => 'log',
					 'image' => 'img', 'oldimage' => 'oi' );
	$count = 0;

	$dbo->immediateBegin();
	foreach( $checks as $table => $fprefix ) {
		$conds = array( $fprefix . '_user' => $id );
		$count += (int)$dbo->selectField( $table, 'COUNT(*)', $conds, $fname );
	}
	$dbo->immediateCommit();

	return $count == 0;
}

/**
 * Show help for the maintenance script
 */
function showHelp() {
	echo( "Delete unused user accounts from the database.\n\n" );
	echo( "USAGE: php removeUnusedAccounts.php [--delete]\n\n" );
	echo( "  --delete : Delete accounts which are discovered to be inactive\n" );
	echo( "\n" );
}

?>