ac15ebef820a6acc56fa2bff5b3582c7a47ec515
[lhc/web/wiklou.git] / maintenance / removeUnusedAccounts.inc
1 <?php
2
3 /**
4 * Support functions for the removeUnusedAccounts maintenance script
5 *
6 *
7 * @package MediaWiki
8 * @subpackage Maintenance
9 * @author Rob Church <robchur@gmail.com>
10 */
11
12 /**
13 * Could the specified user account be deemed inactive?
14 * (No edits, no deleted edits, no log entries, no current/old uploads)
15 *
16 * @param $id User's ID
17 * @param $master Perform checking on the master
18 * @return bool
19 */
20 function isInactiveAccount( $id, $master = false ) {
21 $dbo =& wfGetDB( $master ? DB_MASTER : DB_SLAVE );
22 $fname = 'isInactiveAccount';
23 $checks = array( 'revision' => 'rev', 'archive' => 'ar', 'logging' => 'log',
24 'image' => 'img', 'oldimage' => 'oi' );
25 $count = 0;
26
27 $dbo->immediateBegin();
28 foreach( $checks as $table => $fprefix ) {
29 $conds = array( $fprefix . '_user' => $id );
30 $count += (int)$dbo->selectField( $table, 'COUNT(*)', $conds, $fname );
31 }
32 $dbo->immediateCommit();
33
34 return $count == 0;
35 }
36
37 /**
38 * Show help for the maintenance script
39 */
40 function showHelp() {
41 echo( "Delete unused user accounts from the database.\n\n" );
42 echo( "USAGE: php removeUnusedAccounts.php [--delete]\n\n" );
43 echo( " --delete : Delete accounts which are discovered to be inactive\n" );
44 echo( "\n" );
45 }
46
47 ?>