Revert r37063 "KTHMLfixes no longer loaded on skins where it doesn't exist. (bug...
[mediawiki.git] / maintenance / removeUnusedAccounts.php
blob636832cbd3f7feae3465768f163faeb2132e07d7
1 <?php
2 /**
3 * Remove unused user accounts from the database
4 * An unused account is one which has made no edits
6 * @file
7 * @ingroup Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
11 /**
12 * @todo Don't delete sysops or bureaucrats
15 $options = array( 'help', 'delete' );
16 require_once( 'commandLine.inc' );
17 require_once( 'removeUnusedAccounts.inc' );
18 echo( "Remove Unused Accounts\n\n" );
19 $fname = 'removeUnusedAccounts';
21 if( isset( $options['help'] ) ) {
22 showHelp();
23 exit();
26 # Do an initial scan for inactive accounts and report the result
27 echo( "Checking for unused user accounts...\n" );
28 $del = array();
29 $dbr = wfGetDB( DB_SLAVE );
30 $res = $dbr->select( 'user', array( 'user_id', 'user_name' ), '', $fname );
31 while( $row = $dbr->fetchObject( $res ) ) {
32 # Check the account, but ignore it if it's the primary administrator
33 if( $row->user_id > 1 && isInactiveAccount( $row->user_id, true ) ) {
34 # Inactive; print out the name and flag it
35 $del[] = $row->user_id;
36 echo( $row->user_name . "\n" );
39 $count = count( $del );
40 echo( "...found {$count}.\n" );
42 # If required, go back and delete each marked account
43 if( $count > 0 && isset( $options['delete'] ) ) {
44 echo( "\nDeleting inactive accounts..." );
45 $dbw = wfGetDB( DB_MASTER );
46 $dbw->delete( 'user', array( 'user_id' => $del ), $fname );
47 echo( "done.\n" );
48 # Update the site_stats.ss_users field
49 $users = $dbw->selectField( 'user', 'COUNT(*)', array(), $fname );
50 $dbw->update( 'site_stats', array( 'ss_users' => $users ), array( 'ss_row_id' => 1 ), $fname );
51 } else {
52 if( $count > 0 )
53 echo( "\nRun the script again with --delete to remove them from the database.\n" );
55 echo( "\n" );