Index: trunk/phase3/maintenance/removeUnusedAccounts.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | require_once( 'commandLine.inc' ); |
17 | 17 | require_once( 'userFunctions.inc' ); |
18 | 18 | |
19 | | -echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" ); |
| 19 | +echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits and uploaded no files.\n\n" ); |
20 | 20 | |
21 | 21 | # Check parameters |
22 | 22 | if( @$options['help'] ) { |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | echo( "Locating inactive users..." ); |
36 | 36 | foreach( $users as $user ) { |
37 | 37 | if( $user != 1 ) { # Don't *touch* the first user account, ever |
38 | | - if( CountEdits( $user, false ) == 0 ) { |
39 | | - # User has no edits, mark them for deletion |
| 38 | + if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 ) { |
| 39 | + # User has no edits or images, mark them for deletion |
40 | 40 | $del[] = $user; |
41 | 41 | $count++; |
42 | 42 | } |
Index: trunk/phase3/maintenance/userFunctions.inc |
— | — | @@ -30,6 +30,27 @@ |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
| 34 | + * Count the number of images the specified user has uploaded |
| 35 | + * |
| 36 | + * @param integer $user User ID |
| 37 | + * @param bool $slave Whether or not a slave can be used |
| 38 | + * @return integer |
| 39 | + */ |
| 40 | +function CountImages( $user, $slave = true ) { |
| 41 | + $dbw =& wfGetDB( $slave ? DB_SLAVE: DB_MASTER ); |
| 42 | + # Count current images |
| 43 | + $res = $dbw->select( 'image', 'COUNT(rev_id) AS count', array( 'img_user' => $user ) ); |
| 44 | + $row = $dbw->fetchObject( $res ); |
| 45 | + $count = $row->count; |
| 46 | + # Count deleted edits |
| 47 | + $res = $dbw->select( 'oldimage', 'COUNT(*) AS count', array( 'oi_user' => $user ) ); |
| 48 | + $row = $dbw->fetchObject( $res ); |
| 49 | + $count += $row->count; |
| 50 | + # Done |
| 51 | + return( $count ); |
| 52 | +} |
| 53 | + |
| 54 | +/** |
34 | 55 | * Retrieve all valid user IDs |
35 | 56 | * |
36 | 57 | * @return array |