MediaWiki master
checkUsernames.php
Go to the documentation of this file.
1<?php
11
12// @codeCoverageIgnoreStart
13require_once __DIR__ . '/Maintenance.php';
14// @codeCoverageIgnoreEnd
15
25
26 public function __construct() {
27 parent::__construct();
28 $this->addDescription( 'Verify that database usernames are actually valid' );
29 $this->setBatchSize( 1000 );
30 }
31
32 public function execute() {
33 $dbr = $this->getReplicaDB();
34 $userNameUtils = $this->getServiceContainer()->getUserNameUtils();
35
36 $maxUserId = 0;
37 do {
38 $res = $dbr->newSelectQueryBuilder()
39 ->select( [ 'user_id', 'user_name' ] )
40 ->from( 'user' )
41 ->where( $dbr->expr( 'user_id', '>', $maxUserId ) )
42 ->orderBy( 'user_id' )
43 ->limit( $this->getBatchSize() )
44 ->caller( __METHOD__ )
45 ->fetchResultSet();
46
47 foreach ( $res as $row ) {
48 if ( !$userNameUtils->isValid( $row->user_name ) ) {
49 $this->output( sprintf( "Found: %6d: '%s'\n", $row->user_id, $row->user_name ) );
50 wfDebugLog( 'checkUsernames', $row->user_name );
51 }
52 }
53 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable $res has at at least one item
54 $maxUserId = $row->user_id;
55 } while ( $res->numRows() );
56 }
57}
58
59// @codeCoverageIgnoreStart
60$maintClass = CheckUsernames::class;
61require_once RUN_MAINTENANCE_IF_MAIN;
62// @codeCoverageIgnoreEnd
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...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
getReplicaDB(string|false $virtualDomain=false)
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.