* Correct a couple of major oversights in the commenting (no, they aren't arrays of User objects, that would be mad, and to what avail?)
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?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>
|
|
*/
|
|
|
|
$options = array( 'delete','help' );
|
|
require_once( 'commandLine.inc' );
|
|
require_once( 'removeUnusedAccounts.inc' );
|
|
|
|
echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" );
|
|
|
|
# Check parameters
|
|
if( $options['help'] ) {
|
|
echo( "USAGE: removeUnusedAccounts.php [--help|--delete]\n\nThe first (default) account is ignored.\n\n" );
|
|
die();
|
|
} else {
|
|
$delete = ( $options['delete'] ? true : false );
|
|
}
|
|
|
|
$count = 0;
|
|
$del = array();
|
|
|
|
# Right, who needs deleting?
|
|
$users = GetUsers();
|
|
echo( "Found " . count( $users ) . " accounts.\n\n" );
|
|
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
|
|
echo( $count . " inactive accounts found.\n" );
|
|
if( $count > 0 ) {
|
|
if( ( $delete ) || ( $count > 0 ) ) {
|
|
echo( " Deleting..." );
|
|
DeleteUsers( $del );
|
|
echo( "done.\n" );
|
|
} else {
|
|
echo "Run the script with the --delete option to remove them from the database.\n";
|
|
}
|
|
}
|
|
echo( "\n" );
|
|
|
|
?>
|