27require_once __DIR__ .
'/../Maintenance.php';
51 parent::__construct();
55 $this->
addOption(
'user',
'If specified, only checks the given user',
false,
true );
56 $this->
addOption(
'delete',
'Really delete. To prevent accidents, you must provide this flag.' );
57 $this->
addOption(
'prefix',
"Instead of deleting, make passwords invalid by prefixing with "
58 .
"':null:'. Make sure PasswordConfig has a 'null' entry. This is meant for testing before "
60 $this->
addOption(
'unprefix',
'Instead of deleting, undo the effect of --prefix.' );
66 + (
int)$this->
hasOption(
'unprefix' ) !== 1
68 $this->
fatalError(
"Exactly one of the 'delete', 'prefix', 'unprefix' options must be used\n" );
73 !isset( $passwordHashTypes[
'null'] )
74 || $passwordHashTypes[
'null'][
'class'] !== InvalidPassword::class
78'null' password entry missing. To use password prefixing, add
80to your configuration (and
remove once the passwords were deleted).
87 if (
$user !==
false ) {
89 $this->user = $userNameUtils->getCanonical(
$user );
90 if ( $this->user ===
false ) {
103 $this->
output(
"done. (wrote $this->total rows)\n" );
121 [
'user_password' => PasswordFactory::newInvalidPassword()->toString() ],
122 [
'user_name' => $userBatch ],
125 } elseif ( $this->
getOption(
'prefix' ) ) {
128 'user_password' ] ) ],
131 "user_password != " . $dbw->
addQuotes( PasswordFactory::newInvalidPassword()->toString() ),
132 'user_password IS NOT NULL',
133 'user_name' => $userBatch,
137 } elseif ( $this->
getOption(
'unprefix' ) ) {
139 [
'user_password = ' . $dbw->
buildSubString(
'user_password', strlen(
':null:' ) + 1 ) ],
142 'user_name' => $userBatch,
161 if ( $this->user !==
null ) {
162 $this->
output(
"\t ... querying '$this->user'\n" );
170 $this->
output(
"\t ... querying from '$lastUsername'\n" );
171 $users = $dbw->newSelectQueryBuilder()
172 ->select(
'user_name' )
174 ->where( [
'user_name > ' . $dbw->addQuotes( $lastUsername ) ] )
175 ->orderBy(
'user_name ASC' )
177 ->caller( __METHOD__ )->fetchFieldValues();
180 $lastUsername = end( $users );
Delete unused local passwords.
execute()
Do the actual work.
__construct()
Default constructor.
string null $user
User to run on, or null for all.
int $total
Number of deleted passwords.
processUsers(array $userBatch, IDatabase $dbw)
getUserBatches()
This method iterates through the requested users and returns their names in batches of self::$mBatchS...
getUserDB()
Get the primary DB handle for the current user batch.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$wgPasswordConfig
Config variable stub for the PasswordConfig setting, for use by phpdoc and IDEs.
Advanced database interface for IDatabase handles that include maintenance methods.