26require_once __DIR__ .
'/Maintenance.php';
35 parent::__construct();
36 $this->
addOption(
'delete',
'Actually delete the account' );
37 $this->
addOption(
'ignore-groups',
'List of comma-separated groups to exclude',
false,
true );
38 $this->
addOption(
'ignore-touched',
'Skip accounts touched in last N days',
false,
true );
42 $this->
output(
"Remove unused accounts\n\n" );
44 # Do an initial scan for inactive accounts and report the result
45 $this->
output(
"Checking for unused user accounts...\n" );
48 $res =
$dbr->select(
'user', [
'user_id',
'user_name',
'user_touched' ],
'', __METHOD__ );
49 if ( $this->
hasOption(
'ignore-groups' ) ) {
50 $excludedGroups = explode(
',', $this->
getOption(
'ignore-groups' ) );
54 $touched = $this->
getOption(
'ignore-touched',
"1" );
55 if ( !ctype_digit( $touched ) ) {
56 $this->
error(
"Please put a valid positive integer on the --ignore-touched parameter.",
true );
58 $touchedSeconds = 86400 * $touched;
59 foreach (
$res as $row ) {
60 # Check the account, but ignore it if it's within a $excludedGroups
61 # group or if it's touched within the $touchedSeconds seconds.
62 $instance = User::newFromId( $row->user_id );
63 if ( count( array_intersect( $instance->getEffectiveGroups(), $excludedGroups ) ) == 0
64 && $this->isInactiveAccount( $row->user_id,
true )
67 # Inactive; print out the name and flag it
68 $del[] = $row->user_id;
69 $this->
output( $row->user_name .
"\n" );
72 $count = count( $del );
73 $this->
output(
"...found {$count}.\n" );
75 # If required, go back and delete each marked account
76 if ( $count > 0 && $this->
hasOption(
'delete' ) ) {
77 $this->
output(
"\nDeleting unused accounts..." );
79 $dbw->delete(
'user', [
'user_id' => $del ], __METHOD__ );
80 $dbw->delete(
'user_groups', [
'ug_user' => $del ], __METHOD__ );
81 $dbw->delete(
'user_former_groups', [
'ufg_user' => $del ], __METHOD__ );
82 $dbw->delete(
'user_properties', [
'up_user' => $del ], __METHOD__ );
83 $dbw->delete(
'logging', [
'log_user' => $del ], __METHOD__ );
84 $dbw->delete(
'recentchanges', [
'rc_user' => $del ], __METHOD__ );
85 $this->
output(
"done.\n" );
86 # Update the site_stats.ss_users field
87 $users = $dbw->selectField(
'user',
'COUNT(*)', [], __METHOD__ );
90 [
'ss_users' => $users ],
94 } elseif ( $count > 0 ) {
95 $this->
output(
"\nRun the script again with --delete to remove them from the database.\n" );
115 'filearchive' =>
'fa'
120 foreach ( $checks as $table => $fprefix ) {
121 $conds = [ $fprefix .
'_user' => $id ];
122 $count += (int)$dbo->selectField( $table,
'COUNT(*)', $conds, __METHOD__ );
125 $conds = [
'log_user' => $id,
'log_type != ' . $dbo->addQuotes(
'newusers' ) ];
126 $count += (int)$dbo->selectField(
'logging',
'COUNT(*)', $conds, __METHOD__ );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Maintenance script that removes unused user accounts from the database.
execute()
Do the actual work.
isInactiveAccount( $id, $master=false)
Could the specified user account be deemed inactive? (No edits, no deleted edits, no log entries,...
__construct()
Default constructor.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
require_once RUN_MAINTENANCE_IF_MAIN