Check that accounts have no uploads prior to calling them unused
authorRob Church <robchurch@users.mediawiki.org>
Tue, 4 Apr 2006 02:50:58 +0000 (02:50 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Tue, 4 Apr 2006 02:50:58 +0000 (02:50 +0000)
maintenance/removeUnusedAccounts.php
maintenance/userFunctions.inc

index 1c6213c..2c967b1 100644 (file)
@@ -15,7 +15,7 @@ $options = array( 'delete','help' );
 require_once( 'commandLine.inc' );
 require_once( 'userFunctions.inc' );
 
-echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" );
+echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits and uploaded no files.\n\n" );
 
 # Check parameters
 if( @$options['help'] ) {
@@ -34,8 +34,8 @@ 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, false ) == 0 ) {
-                       # User has no edits, mark them for deletion
+               if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 ) {
+                       # User has no edits or images, mark them for deletion
                        $del[] = $user;
                        $count++;
                }
index 42429e8..314da61 100644 (file)
@@ -29,6 +29,27 @@ function CountEdits( $user, $slave = true ) {
        return( $count );
 }
 
+/**
+ * Count the number of images the specified user has uploaded
+ *
+ * @param integer $user User ID
+ * @param bool $slave Whether or not a slave can be used
+ * @return integer
+ */
+function CountImages( $user, $slave = true ) {
+       $dbw =& wfGetDB( $slave ? DB_SLAVE: DB_MASTER );
+       # Count current images
+       $res = $dbw->select( 'image', 'COUNT(rev_id) AS count', array( 'img_user' => $user ) );
+       $row = $dbw->fetchObject( $res );
+       $count = $row->count;
+       # Count deleted edits
+       $res = $dbw->select( 'oldimage', 'COUNT(*) AS count', array( 'oi_user' => $user ) );
+       $row = $dbw->fetchObject( $res );
+       $count += $row->count;
+       # Done
+       return( $count );
+}
+
 /**
  * Retrieve all valid user IDs
  *