define( 'ACTION_REPORT', 0 );
define( 'ACTION_DELETE', 1 );
-/**
- * Count the number of edits the specified user has made
- * @param $user_id A database user id.
- * @return integer Number of edits made by the given user.
- */
+# Count the number of edits the specified user has made
function CountEdits( $user_id ) {
- # We've *got* to pull this stuff off the master. If the user *has* made
- # an edit, but it hasn't been replicated to the slaves yet, we'll end up
- # falsely marking them as inactive. This could (and usually would) lead
- # to their deletion.
+ # We've *got* to pull this stuff off the master. If the user *has* made an edit, but it hasn't
+ # been replicated to the slaves yet, we'll end up falsely marking them as inactive. This could
+ # (and usually would) lead to their deletion.
$dbw =& wfGetDB( DB_MASTER );
$sql = 'SELECT COUNT(rev_id) AS count FROM ' . $dbw->tableName( 'revision' ) . ' WHERE rev_user = ' . $user_id;
$res = $dbw->query( $sql );
return( $row->count );
}
-/**
- * Return an array containing all valid user IDs
- * @return array Array of User:: object(s).
- */
+# Return an array containing all valid user IDs
function GetUsers() {
# We're safe enough pulling this off a slave
$dbr =& wfGetDB( DB_SLAVE );
return( $users );
}
-/**
- * Delete one or more users.
- * You will probably use GetUsers() first to get a list of users :o)
- * @param array An array of User:: object(s)
- */
+# Delete one or more users
function DeleteUsers( $users ) {
# Need a master, obviously
$dbw =& wfGetDB( DB_MASTER );
$dbw->commit();
}
-?>
+?>
\ No newline at end of file
* @author Rob Church <robchur@gmail.com>
*/
-# Options available
$options = array( 'delete','help' );
-
require_once( 'commandLine.inc' );
require_once( 'removeUnusedAccounts.inc' );
-# Default action (just report):
-$action = ACTION_REPORT;
+echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" );
-# Handle parameters
-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;
+# 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;
# Purge the inactive accounts we found
echo( $count . " inactive accounts found.\n" );
-if( ( $action == ACTION_DELETE ) && ( $count > 0 ) ) {
- echo( " Deleting..." );
- DeleteUsers( $del );
- echo( "done.\n" );
-} else {
- echo "\nYou can delete them by using the '--delete' switch (see help).\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" );
?>