Check that accounts have no uploads prior to calling them unused
[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 define( 'ACTION_REPORT', 0 );
13 define( 'ACTION_DELETE', 1 );
14 $options = array( 'delete','help' );
15 require_once( 'commandLine.inc' );
16 require_once( 'userFunctions.inc' );
17
18 echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits and uploaded no files.\n\n" );
19
20 # Check parameters
21 if( @$options['help'] ) {
22 echo( "USAGE: removeUnusedAccounts.php [--help|--delete]\n\nThe first (default) account is ignored.\n\n" );
23 wfDie();
24 } else {
25 $delete = @$options['delete'] ? true : false ;
26 }
27
28 $count = 0;
29 $del = array();
30
31 # Right, who needs deleting?
32 $users = GetUsers();
33 echo( "Found " . count( $users ) . " accounts.\n\n" );
34 echo( "Locating inactive users..." );
35 foreach( $users as $user ) {
36 if( $user != 1 ) { # Don't *touch* the first user account, ever
37 if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 ) {
38 # User has no edits or images, mark them for deletion
39 $del[] = $user;
40 $count++;
41 }
42 }
43 }
44 echo( "done.\n" );
45
46 # Purge the inactive accounts we found
47 echo( $count . " inactive accounts found.\n" );
48 if( $count > 0 ) {
49 if( $delete ) {
50 echo( "Deleting..." );
51 DeleteUsers( $del );
52 echo( "done.\n" );
53 } else {
54 echo "Run the script with the --delete option to remove them from the database.\n";
55 }
56 }
57
58 echo( "\n" );
59
60 ?>