2006-01-04 12:33:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove unused user accounts from the database
|
|
|
|
|
* An unused account is one which has made no edits
|
|
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage Maintenance
|
|
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
*/
|
2006-01-05 23:16:11 +00:00
|
|
|
|
|
|
|
|
# Options available
|
|
|
|
|
$options = array( 'delete','help' );
|
2006-01-04 12:33:45 +00:00
|
|
|
|
|
|
|
|
require_once( 'commandLine.inc' );
|
|
|
|
|
require_once( 'removeUnusedAccounts.inc' );
|
2006-01-05 23:16:11 +00:00
|
|
|
|
|
|
|
|
# Default action (just report):
|
|
|
|
|
$action = ACTION_REPORT;
|
2006-01-04 13:02:04 +00:00
|
|
|
|
|
|
|
|
# Handle parameters
|
2006-01-05 23:16:11 +00:00
|
|
|
if(@$options['help']) {
|
|
|
|
|
echo <<<END
|
|
|
|
|
This script will delete all users who have made no edits.
|
|
|
|
|
|
|
|
|
|
usage:removeUnusedAccounts.php [--help|--delete]
|
|
|
|
|
--delete : delete the unused accounts
|
|
|
|
|
--help : this help message
|
|
|
|
|
|
|
|
|
|
NB: The first user (usually the site owner) is left alone
|
|
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(@$options['delete']) {
|
|
|
|
|
$action = ACTION_DELETE;
|
2006-01-04 13:02:04 +00:00
|
|
|
}
|
2006-01-04 12:33:45 +00:00
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
|
$del = array();
|
|
|
|
|
|
|
|
|
|
# Right, who needs deleting?
|
|
|
|
|
$users = GetUsers();
|
2006-01-04 13:02:04 +00:00
|
|
|
echo( "Found " . count( $users ) . " accounts.\n\n" );
|
2006-01-04 12:33:45 +00:00
|
|
|
echo( "Locating inactive users..." );
|
|
|
|
|
foreach( $users as $user ) {
|
|
|
|
|
if( $user != 1 ) { # Don't *touch* the first user account, ever
|
|
|
|
|
if( CountEdits( $user ) == 0 ) {
|
|
|
|
|
# User has no edits, mark them for deletion
|
|
|
|
|
$del[] = $user;
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
echo( "done.\n" );
|
|
|
|
|
|
|
|
|
|
# Purge the inactive accounts we found
|
2006-01-05 23:16:11 +00:00
|
|
|
echo( $count . " inactive accounts found.\n" );
|
2006-01-04 13:02:04 +00:00
|
|
|
if( ( $action == ACTION_DELETE ) && ( $count > 0 ) ) {
|
|
|
|
|
echo( " Deleting..." );
|
|
|
|
|
DeleteUsers( $del );
|
|
|
|
|
echo( "done.\n" );
|
2006-01-05 23:16:11 +00:00
|
|
|
} else {
|
|
|
|
|
echo "\nYou can delete them by using the '--delete' switch (see help).\n";
|
2006-01-04 13:02:04 +00:00
|
|
|
}
|
2006-01-04 12:33:45 +00:00
|
|
|
|
2006-01-05 23:16:11 +00:00
|
|
|
?>
|