34require_once __DIR__ .
'/../Maintenance.php';
59 parent::__construct();
63 $this->
addOption(
'user',
'If specified, only checks the given user',
false,
true );
64 $this->
addOption(
'delete',
'Really delete. To prevent accidents, you must provide this flag.' );
65 $this->
addOption(
'prefix',
"Instead of deleting, make passwords invalid by prefixing with "
66 .
"':null:'. Make sure PasswordConfig has a 'null' entry. This is meant for testing before "
68 $this->
addOption(
'unprefix',
'Instead of deleting, undo the effect of --prefix.' );
74 + (
int)$this->
hasOption(
'unprefix' ) !== 1
76 $this->
fatalError(
"Exactly one of the 'delete', 'prefix', 'unprefix' options must be used\n" );
81 !isset( $passwordHashTypes[
'null'] )
82 || $passwordHashTypes[
'null'][
'class'] !== InvalidPassword::class
86'null' password entry missing. To use password prefixing, add
88to your configuration (and
remove once the passwords were deleted).
95 if (
$user !==
false ) {
97 $this->user = $userNameUtils->getCanonical(
$user );
98 if ( $this->user ===
false ) {
111 $this->
output(
"done. (wrote $this->total rows)\n" );
130 ->set( [
'user_password' => PasswordFactory::newInvalidPassword()->toString() ] )
131 ->where( [
'user_name' => $userBatch ] )
132 ->caller( __METHOD__ )->execute();
133 } elseif ( $this->
getOption(
'prefix' ) ) {
143 $dbw->
expr(
'user_password',
'!=', PasswordFactory::newInvalidPassword()->toString() ),
144 $dbw->
expr(
'user_password',
'!=',
null ),
145 'user_name' => $userBatch,
147 ->caller( __METHOD__ )->execute();
148 } elseif ( $this->
getOption(
'unprefix' ) ) {
158 'user_name' => $userBatch,
160 ->caller( __METHOD__ )->execute();
176 if ( $this->user !==
null ) {
177 $this->
output(
"\t ... querying '$this->user'\n" );
185 $this->
output(
"\t ... querying from '$lastUsername'\n" );
186 $users = $dbw->newSelectQueryBuilder()
187 ->select(
'user_name' )
189 ->where( $dbw->expr(
'user_name',
'>', $lastUsername ) )
190 ->orderBy(
'user_name ASC' )
192 ->caller( __METHOD__ )->fetchFieldValues();
195 $lastUsername = end( $users );
202class_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.
addDescription( $text)
Set the description text.
$wgPasswordConfig
Config variable stub for the PasswordConfig setting, for use by phpdoc and IDEs.