MediaWiki master
fixWrongPasswordPrefixes.php
Go to the documentation of this file.
1<?php
7
12
13// @codeCoverageIgnoreStart
14require_once __DIR__ . '/Maintenance.php';
15// @codeCoverageIgnoreEnd
16
25 public function __construct() {
26 parent::__construct();
27 $this->setBatchSize( 100 );
28 }
29
31 protected function getUpdateKey() {
32 return __CLASS__;
33 }
34
36 protected function doDBUpdates(): LoggedUpdateOutcome {
37 $dbw = $this->getPrimaryDB();
38 $batchSize = $this->getBatchSize();
39 $minUserId = 0;
40
41 while ( true ) {
42 $res = $dbw->newSelectQueryBuilder()
43 ->select( [ 'user_id', 'user_password' ] )
44 ->from( 'user' )
45 ->where( $dbw->expr( 'user_id', '>', $minUserId ) )
46 ->andWhere(
47 $dbw->expr( 'user_password', IExpression::LIKE, new LikeValue( ':A:', $dbw->anyString() ) )
48 )
49 ->orderBy( 'user_id' )
50 ->limit( $batchSize )
51 ->caller( __METHOD__ )
52 ->fetchResultSet();
53
54 if ( $res->numRows() === 0 ) {
55 break;
56 }
57
58 foreach ( $res as $row ) {
59 $passwordHash = substr( $row->user_password, 3 );
60 if ( strpos( $passwordHash, ':' ) > 0 ) {
61 $dbw->newUpdateQueryBuilder()
62 ->update( 'user' )
63 ->set( [ 'user_password' => ':B:' . $passwordHash ] )
64 ->where( [ 'user_id' => $row->user_id ] )
65 ->caller( __METHOD__ )
66 ->execute();
67 }
68
69 $minUserId = $row->user_id;
70 }
71 }
72
73 $this->output( "Wrongly prefixed user password hashes, if present, have been fixed.\n" );
74 return LoggedUpdateOutcome::COMPLETE;
75 }
76}
77
78// @codeCoverageIgnoreStart
79$maintClass = FixWrongPasswordPrefixes::class;
80require_once RUN_MAINTENANCE_IF_MAIN;
81// @codeCoverageIgnoreEnd
$maintClass
An error in a previous version of MediaWiki caused B type passwords to be written with an :A: prefix ...
getUpdateKey()
Get the update key name to go in the update log table.string
doDBUpdates()
Do the actual work.All child classes will need to implement this.LoggedUpdateOutcome|bool The outcome...
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
getPrimaryDB(string|false $virtualDomain=false)
Content of like value.
Definition LikeValue.php:14
LoggedUpdateOutcome
Enum representing the outcome of LoggedUpdateMaintenance\doDbUpdates().