MediaWiki  1.33.0
checkUsernames.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
34 class CheckUsernames extends Maintenance {
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  function execute() {
43  $dbr = $this->getDB( DB_REPLICA );
44 
45  $maxUserId = 0;
46  do {
47  $res = $dbr->select( 'user',
48  [ 'user_id', 'user_name' ],
49  [ 'user_id > ' . $maxUserId ],
50  __METHOD__,
51  [
52  'ORDER BY' => 'user_id',
53  'LIMIT' => $this->getBatchSize(),
54  ]
55  );
56 
57  foreach ( $res as $row ) {
58  if ( !User::isValidUserName( $row->user_name ) ) {
59  $this->output( sprintf( "Found: %6d: '%s'\n", $row->user_id, $row->user_name ) );
60  wfDebugLog( 'checkUsernames', $row->user_name );
61  }
62  }
63  $maxUserId = $row->user_id;
64  } while ( $res->numRows() );
65  }
66 }
67 
69 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$res
$res
Definition: database.txt:21
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
User\isValidUserName
static isValidUserName( $name)
Is the input a valid username?
Definition: User.php:993
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1043
php
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:35
$dbr
$dbr
Definition: testCompression.php:50
CheckUsernames
Maintenance script to check that database usernames are actually valid.
Definition: checkUsernames.php:34
CheckUsernames\execute
execute()
Do the actual work.
Definition: checkUsernames.php:42
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition: Maintenance.php:367
as
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
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1373
$maintClass
$maintClass
Definition: checkUsernames.php:68
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
CheckUsernames\__construct
__construct()
Default constructor.
Definition: checkUsernames.php:36
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:375