MediaWiki master
checkUsernames.php
Go to the documentation of this file.
1<?php
25
26// @codeCoverageIgnoreStart
27require_once __DIR__ . '/Maintenance.php';
28// @codeCoverageIgnoreEnd
29
39
40 public function __construct() {
41 parent::__construct();
42 $this->addDescription( 'Verify that database usernames are actually valid' );
43 $this->setBatchSize( 1000 );
44 }
45
46 public function execute() {
47 $dbr = $this->getReplicaDB();
48 $userNameUtils = $this->getServiceContainer()->getUserNameUtils();
49
50 $maxUserId = 0;
51 do {
52 $res = $dbr->newSelectQueryBuilder()
53 ->select( [ 'user_id', 'user_name' ] )
54 ->from( 'user' )
55 ->where( $dbr->expr( 'user_id', '>', $maxUserId ) )
56 ->orderBy( 'user_id' )
57 ->limit( $this->getBatchSize() )
58 ->caller( __METHOD__ )
59 ->fetchResultSet();
60
61 foreach ( $res as $row ) {
62 if ( !$userNameUtils->isValid( $row->user_name ) ) {
63 $this->output( sprintf( "Found: %6d: '%s'\n", $row->user_id, $row->user_name ) );
64 wfDebugLog( 'checkUsernames', $row->user_name );
65 }
66 }
67 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable $res has at at least one item
68 $maxUserId = $row->user_id;
69 } while ( $res->numRows() );
70 }
71}
72
73// @codeCoverageIgnoreStart
74$maintClass = CheckUsernames::class;
75require_once RUN_MAINTENANCE_IF_MAIN;
76// @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.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.