4 * Support functions for dealing with user accounts at a database level
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
11 # Count the number of edits the specified user has made
12 function CountEdits( $user_id ) {
13 # We've *got* to pull this stuff off the master. If the user *has* made an edit, but it hasn't
14 # been replicated to the slaves yet, we'll end up falsely marking them as inactive. This could
15 # (and usually would) lead to their deletion.
16 $dbw =& wfGetDB( DB_MASTER );
17 $sql = 'SELECT COUNT(rev_id) AS count FROM ' . $dbw->tableName( 'revision' ) . ' WHERE rev_user = ' . $user_id;
18 $res = $dbw->query( $sql );
19 $row = $dbw->fetchObject( $res );
20 return( $row->count );
23 # Return an array containing all valid user IDs
25 # We're safe enough pulling this off a slave
26 $dbr =& wfGetDB( DB_SLAVE );
27 $sql = 'SELECT user_id FROM ' . $dbr->tableName( 'user' );
28 $res = $dbr->query( $sql );
30 while( $row = $dbr->fetchObject( $res ) ) {
31 $users[] = $row->user_id;
36 # Delete one or more users
37 function DeleteUsers( $users ) {
38 # Need a master, obviously
39 $dbw =& wfGetDB( DB_MASTER );
40 # We'll do it all in one go, for speed
42 $table = $dbw->tableName( 'user' );
43 foreach( $users as $user ) {
44 $dbw->query( 'DELETE FROM ' . $table . ' WHERE user_id = ' . $user . ' LIMIT 1' );