r13449 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13448‎ | r13449 | r13450 >
Date:02:50, 4 April 2006
Author:robchurch
Status:old
Tags:
Comment:
Check that accounts have no uploads prior to calling them unused
Modified paths:
  • /trunk/phase3/maintenance/removeUnusedAccounts.php (modified) (history)
  • /trunk/phase3/maintenance/userFunctions.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/removeUnusedAccounts.php
@@ -15,7 +15,7 @@
1616 require_once( 'commandLine.inc' );
1717 require_once( 'userFunctions.inc' );
1818
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" );
2020
2121 # Check parameters
2222 if( @$options['help'] ) {
@@ -34,8 +34,8 @@
3535 echo( "Locating inactive users..." );
3636 foreach( $users as $user ) {
3737 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
4040 $del[] = $user;
4141 $count++;
4242 }
Index: trunk/phase3/maintenance/userFunctions.inc
@@ -30,6 +30,27 @@
3131 }
3232
3333 /**
 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+/**
3455 * Retrieve all valid user IDs
3556 *
3657 * @return array

Status & tagging log