26require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Wrap all passwords of a certain type in a new layered type' );
40 'Password type to wrap passwords in (must inherit LayeredParameterizedPassword)',
true,
true );
41 $this->
addOption(
'verbose',
'Enables verbose output',
false,
false,
'v' );
49 $typeInfo = $passwordFactory->getTypes();
50 $layeredType = $this->
getOption(
'type' );
53 if ( !isset( $typeInfo[$layeredType] ) ) {
54 $this->
fatalError(
'Undefined password type' );
57 $passObj = $passwordFactory->newFromType( $layeredType );
59 $this->
fatalError(
'Layered parameterized password type must be used.' );
63 $typeConfig = $typeInfo[$layeredType];
64 $firstType = $typeConfig[
'types'][0];
68 $typeCond =
'user_password' . $dbw->buildLike(
":$firstType:", $dbw->anyString() );
71 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
75 $res = $dbw->select(
'user',
76 [
'user_id',
'user_name',
'user_password' ],
78 'user_id > ' . $dbw->addQuotes( $minUserId ),
83 'ORDER BY' =>
'user_id',
84 'LIMIT' => $this->getBatchSize(),
91 foreach (
$res as $row ) {
93 $this->
output(
"Updating password for user {$row->user_name} ({$row->user_id}).\n" );
98 $password = $passwordFactory->newFromCiphertext( $row->user_password );
100 $layeredPassword = $passwordFactory->newFromType( $layeredType );
101 $layeredPassword->partialCrypt( $password );
103 $updateUsers[] =
$user;
104 $dbw->update(
'user',
105 [
'user_password' => $layeredPassword->toString() ],
106 [
'user_id' => $row->user_id ],
110 $minUserId = $row->user_id;
114 $lbFactory->waitForReplication();
117 foreach ( $updateUsers as $user ) {
118 $user->clearSharedCache();
120 }
while (
$res->numRows() );
This password hash type layers one or more parameterized password types on top of each other.
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.
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.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Factory class for creating and checking Password objects.
static getMain()
Get the RequestContext object associated with the main request.
static newFromId( $id)
Static factory method for creation from a given user ID.
Maintenance script to wrap all passwords of a certain type in a specified layered type that wraps aro...
execute()
Do the actual work.
__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
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
require_once RUN_MAINTENANCE_IF_MAIN