20require_once __DIR__ .
'/../Maintenance.php';
45 parent::__construct();
49 $this->
addOption(
'user',
'If specified, only checks the given user',
false,
true );
50 $this->
addOption(
'delete',
'Really delete. To prevent accidents, you must provide this flag.' );
51 $this->
addOption(
'prefix',
"Instead of deleting, make passwords invalid by prefixing with "
52 .
"':null:'. Make sure PasswordConfig has a 'null' entry. This is meant for testing before "
54 $this->
addOption(
'unprefix',
'Instead of deleting, undo the effect of --prefix.' );
60 + (
int)$this->
hasOption(
'unprefix' ) !== 1
62 $this->
fatalError(
"Exactly one of the 'delete', 'prefix', 'unprefix' options must be used\n" );
67 !isset( $passwordHashTypes[
'null'] )
68 || $passwordHashTypes[
'null'][
'class'] !== InvalidPassword::class
72'null' password entry missing. To use password prefixing, add
74to your configuration (and
remove once the passwords were deleted).
81 if (
$user !==
false ) {
83 $this->user = $userNameUtils->getCanonical(
$user );
84 if ( $this->user ===
false ) {
97 $this->
output(
"done. (wrote $this->total rows)\n" );
116 ->set( [
'user_password' => PasswordFactory::newInvalidPassword()->toString() ] )
117 ->where( [
'user_name' => $userBatch ] )
118 ->caller( __METHOD__ )->execute();
119 } elseif ( $this->
getOption(
'prefix' ) ) {
129 $dbw->
expr(
'user_password',
'!=', PasswordFactory::newInvalidPassword()->toString() ),
130 $dbw->
expr(
'user_password',
'!=',
null ),
131 'user_name' => $userBatch,
133 ->caller( __METHOD__ )->execute();
134 } elseif ( $this->
getOption(
'unprefix' ) ) {
144 'user_name' => $userBatch,
146 ->caller( __METHOD__ )->execute();
162 if ( $this->user !==
null ) {
163 $this->
output(
"\t ... querying '$this->user'\n" );
171 $this->
output(
"\t ... querying from '$lastUsername'\n" );
172 $users = $dbw->newSelectQueryBuilder()
173 ->select(
'user_name' )
175 ->where( $dbw->expr(
'user_name',
'>', $lastUsername ) )
176 ->orderBy(
'user_name ASC' )
178 ->caller( __METHOD__ )->fetchFieldValues();
181 $lastUsername = end( $users );
188class_alias( DeleteLocalPasswords::class,
'DeleteLocalPasswords' );
Delete unused local passwords.
processUsers(array $userBatch, IDatabase $dbw)
execute()
Do the actual work.
__construct()
Default constructor.
getUserDB()
Get the primary DB handle for the current user batch.
string null $user
User to run on, or null for all.
getUserBatches()
This method iterates through the requested users and returns their names in batches of self::$mBatchS...
int $total
Number of deleted passwords.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
getServiceContainer()
Returns the main service container.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
$wgPasswordConfig
Config variable stub for the PasswordConfig setting, for use by phpdoc and IDEs.
Update the CREDITS list by merging in the list of git commit authors.