MediaWiki REL1_28
wrapOldPasswords.php
Go to the documentation of this file.
1<?php
23require_once __DIR__ . '/Maintenance.php';
24
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Wrap all passwords of a certain type in a new layered type' );
36 $this->addOption( 'type',
37 'Password type to wrap passwords in (must inherit LayeredParameterizedPassword)', true, true );
38 $this->addOption( 'verbose', 'Enables verbose output', false, false, 'v' );
39 $this->setBatchSize( 100 );
40 }
41
42 public function execute() {
44
45 if ( !$wgAuth->allowSetLocalPassword() ) {
46 $this->error( '$wgAuth does not allow local passwords. Aborting.', true );
47 }
48
49 $passwordFactory = new PasswordFactory();
50 $passwordFactory->init( RequestContext::getMain()->getConfig() );
51
52 $typeInfo = $passwordFactory->getTypes();
53 $layeredType = $this->getOption( 'type' );
54
55 // Check that type exists and is a layered type
56 if ( !isset( $typeInfo[$layeredType] ) ) {
57 $this->error( 'Undefined password type', true );
58 }
59
60 $passObj = $passwordFactory->newFromType( $layeredType );
61 if ( !$passObj instanceof LayeredParameterizedPassword ) {
62 $this->error( 'Layered parameterized password type must be used.', true );
63 }
64
65 // Extract the first layer type
66 $typeConfig = $typeInfo[$layeredType];
67 $firstType = $typeConfig['types'][0];
68
69 // Get a list of password types that are applicable
70 $dbw = $this->getDB( DB_MASTER );
71 $typeCond = 'user_password' . $dbw->buildLike( ":$firstType:", $dbw->anyString() );
72
73 $minUserId = 0;
74 do {
75 $this->beginTransaction( $dbw, __METHOD__ );
76
77 $res = $dbw->select( 'user',
78 [ 'user_id', 'user_name', 'user_password' ],
79 [
80 'user_id > ' . $dbw->addQuotes( $minUserId ),
81 $typeCond
82 ],
83 __METHOD__,
84 [
85 'ORDER BY' => 'user_id',
86 'LIMIT' => $this->mBatchSize,
87 'LOCK IN SHARE MODE',
88 ]
89 );
90
92 $updateUsers = [];
93 foreach ( $res as $row ) {
94 if ( $this->hasOption( 'verbose' ) ) {
95 $this->output( "Updating password for user {$row->user_name} ({$row->user_id}).\n" );
96 }
97
98 $user = User::newFromId( $row->user_id );
100 $password = $passwordFactory->newFromCiphertext( $row->user_password );
102 $layeredPassword = $passwordFactory->newFromType( $layeredType );
103 $layeredPassword->partialCrypt( $password );
104
105 $updateUsers[] = $user;
106 $dbw->update( 'user',
107 [ 'user_password' => $layeredPassword->toString() ],
108 [ 'user_id' => $row->user_id ],
109 __METHOD__
110 );
111
112 $minUserId = $row->user_id;
113 }
114
115 $this->commitTransaction( $dbw, __METHOD__ );
116
117 // Clear memcached so old passwords are wiped out
118 foreach ( $updateUsers as $user ) {
119 $user->clearSharedCache();
120 }
121 } while ( $res->numRows() );
122 }
123}
124
125$maintClass = "WrapOldPasswords";
126require_once RUN_MAINTENANCE_IF_MAIN;
$wgAuth $wgAuth
Authentication plugin.
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...
error( $err, $die=0)
Throw an error to the user.
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.
Factory class for creating and checking Password objects.
static getMain()
Static methods.
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.
$res
Definition database.txt:21
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
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
Definition hooks.txt:249
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:23