4 * Support functions for the removeUnusedAccounts script
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
11 define( 'ACTION_REPORT', 0 );
12 define( 'ACTION_DELETE', 1 );
15 * Count the number of edits the specified user has made
16 * @param $user_id A database user id.
17 * @return integer Number of edits made by the given user.
19 function CountEdits( $user_id ) {
20 # We've *got* to pull this stuff off the master. If the user *has* made
21 # an edit, but it hasn't been replicated to the slaves yet, we'll end up
22 # falsely marking them as inactive. This could (and usually would) lead
24 $dbw =& wfGetDB( DB_MASTER );
25 $sql = 'SELECT COUNT(rev_id) AS count FROM ' . $dbw->tableName( 'revision' ) . ' WHERE rev_user = ' . $user_id;
26 $res = $dbw->query( $sql );
27 $row = $dbw->fetchObject( $res );
28 return( $row->count );
32 * Return an array containing all valid user IDs
33 * @return array Array of User:: object(s).
36 # We're safe enough pulling this off a slave
37 $dbr =& wfGetDB( DB_SLAVE );
38 $sql = 'SELECT user_id FROM ' . $dbr->tableName( 'user' );
39 $res = $dbr->query( $sql );
41 while( $row = $dbr->fetchObject( $res ) ) {
42 $users[] = $row->user_id;
48 * Delete one or more users.
49 * You will probably use GetUsers() first to get a list of users :o)
50 * @param array An array of User:: object(s)
52 function DeleteUsers( $users ) {
53 # Need a master, obviously
54 $dbw =& wfGetDB( DB_MASTER );
55 # We'll do it all in one go, for speed
57 $table = $dbw->tableName( 'user' );
58 foreach( $users as $user ) {
59 $dbw->query( 'DELETE FROM ' . $table . ' WHERE user_id = ' . $user . ' LIMIT 1' );