2006-01-04 12:33:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2006-01-16 13:57:29 +00:00
|
|
|
* Support functions for dealing with user accounts at a database level
|
2006-01-04 12:33:45 +00:00
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage Maintenance
|
|
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2006-01-07 13:09:30 +00:00
|
|
|
# Count the number of edits the specified user has made
|
2006-01-04 12:33:45 +00:00
|
|
|
function CountEdits( $user_id ) {
|
2006-01-05 23:52:18 +00:00
|
|
|
# We've *got* to pull this stuff off the master. If the user *has* made an edit, but it hasn't
|
|
|
|
|
# been replicated to the slaves yet, we'll end up falsely marking them as inactive. This could
|
|
|
|
|
# (and usually would) lead to their deletion.
|
2006-01-04 12:33:45 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
$sql = 'SELECT COUNT(rev_id) AS count FROM ' . $dbw->tableName( 'revision' ) . ' WHERE rev_user = ' . $user_id;
|
|
|
|
|
$res = $dbw->query( $sql );
|
|
|
|
|
$row = $dbw->fetchObject( $res );
|
2006-01-07 13:31:29 +00:00
|
|
|
return( $row->count );
|
2006-01-04 12:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-05 23:52:18 +00:00
|
|
|
# Return an array containing all valid user IDs
|
2006-01-04 12:33:45 +00:00
|
|
|
function GetUsers() {
|
|
|
|
|
# We're safe enough pulling this off a slave
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$sql = 'SELECT user_id FROM ' . $dbr->tableName( 'user' );
|
|
|
|
|
$res = $dbr->query( $sql );
|
|
|
|
|
$users = array();
|
|
|
|
|
while( $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
$users[] = $row->user_id;
|
|
|
|
|
}
|
|
|
|
|
return( $users );
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-05 23:52:18 +00:00
|
|
|
# Delete one or more users
|
2006-01-04 12:33:45 +00:00
|
|
|
function DeleteUsers( $users ) {
|
|
|
|
|
# Need a master, obviously
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
# We'll do it all in one go, for speed
|
|
|
|
|
$dbw->begin();
|
|
|
|
|
$table = $dbw->tableName( 'user' );
|
|
|
|
|
foreach( $users as $user ) {
|
|
|
|
|
$dbw->query( 'DELETE FROM ' . $table . ' WHERE user_id = ' . $user . ' LIMIT 1' );
|
|
|
|
|
}
|
|
|
|
|
$dbw->commit();
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-05 23:52:18 +00:00
|
|
|
?>
|