038875f4d99a5a9c48b46250b2ff7f9d7e7d2fb3
[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 require_once( 'commandLine.inc' );
13 require_once( 'removeUnusedAccounts.inc' );
14 echo( "REMOVE UNUSED ACCOUNTS\nThis script will delete all users who have made no edits.\n\n" );
15 echo( "Syntax: removeUnusedAccounts.php [delete]\n * delete -> delete the accounts\n * The first user (usually the site owner) is left alone\n\n" );
16
17 # Handle parameters
18 if( isset( $args[0] ) ) {
19 $param = array_shift( $args );
20 if( $param == 'delete' ) {
21 $action = ACTION_DELETE;
22 } else {
23 $action = ACTION_REPORT;
24 }
25 } else {
26 $action = ACTION_REPORT;
27 }
28
29 $count = 0;
30 $del = array();
31
32 # Right, who needs deleting?
33 $users = GetUsers();
34 echo( "Found " . count( $users ) . " accounts.\n\n" );
35 echo( "Locating inactive users..." );
36 foreach( $users as $user ) {
37 if( $user != 1 ) { # Don't *touch* the first user account, ever
38 if( CountEdits( $user ) == 0 ) {
39 # User has no edits, mark them for deletion
40 $del[] = $user;
41 $count++;
42 }
43 }
44 }
45 echo( "done.\n" );
46
47 # Purge the inactive accounts we found
48 echo( $count . " inactive accounts found." );
49 if( ( $action == ACTION_DELETE ) && ( $count > 0 ) ) {
50 echo( " Deleting..." );
51 DeleteUsers( $del );
52 echo( "done.\n" );
53 }
54
55 ?>