MediaWiki master
checkUsernames.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
35
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Verify that database usernames are actually valid' );
39 $this->setBatchSize( 1000 );
40 }
41
42 public function execute() {
43 $dbr = $this->getReplicaDB();
44 $userNameUtils = $this->getServiceContainer()->getUserNameUtils();
45
46 $maxUserId = 0;
47 do {
48 $res = $dbr->newSelectQueryBuilder()
49 ->select( [ 'user_id', 'user_name' ] )
50 ->from( 'user' )
51 ->where( 'user_id > ' . $maxUserId )
52 ->orderBy( 'user_id' )
53 ->limit( $this->getBatchSize() )
54 ->fetchResultSet();
55
56 foreach ( $res as $row ) {
57 if ( !$userNameUtils->isValid( $row->user_name ) ) {
58 $this->output( sprintf( "Found: %6d: '%s'\n", $row->user_id, $row->user_name ) );
59 wfDebugLog( 'checkUsernames', $row->user_name );
60 }
61 }
62 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable $res has at at least one item
63 $maxUserId = $row->user_id;
64 } while ( $res->numRows() );
65 }
66}
67
68$maintClass = CheckUsernames::class;
69require_once RUN_MAINTENANCE_IF_MAIN;
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
$maintClass
Maintenance script to check that database usernames are actually valid.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)