* Added wfDie() wrapper, and some manual die(-1), to force the return code
[lhc/web/wiklou.git] / maintenance / removeUnusedAccounts.php
1 <?php
2
3 /**
4 * Remove unused user accounts from the database
5 * An unused account is one which has made no edits
6 *
7 * @package MediaWiki
8 * @subpackage Maintenance
9 * @author Rob Church <robchur@gmail.com>
10 */
11
12 $options = array( 'delete','help' );
13 require_once( 'commandLine.inc' );
14 require_once( 'removeUnusedAccounts.inc' );
15
16 echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" );
17
18 # Check parameters
19 if( @$options['help'] ) {
20 echo( "USAGE: removeUnusedAccounts.php [--help|--delete]\n\nThe first (default) account is ignored.\n\n" );
21 wfDie();
22 } else {
23 $delete = @$options['delete'] ? true : false ;
24 }
25
26 $count = 0;
27 $del = array();
28
29 # Right, who needs deleting?
30 $users = GetUsers();
31 echo( "Found " . count( $users ) . " accounts.\n\n" );
32 echo( "Locating inactive users..." );
33 foreach( $users as $user ) {
34 if( $user != 1 ) { # Don't *touch* the first user account, ever
35 if( CountEdits( $user ) == 0 ) {
36 # User has no edits, mark them for deletion
37 $del[] = $user;
38 $count++;
39 }
40 }
41 }
42 echo( "done.\n" );
43
44 # Purge the inactive accounts we found
45 echo( $count . " inactive accounts found.\n" );
46 if( ( $delete ) and ( $count > 0 ) ) {
47 echo( " Deleting..." );
48 DeleteUsers( $del );
49 echo( "done.\n" );
50 } else {
51 echo "Run the script with the --delete option to remove them from the database.\n";
52 }
53 echo( "\n" );
54
55 ?>