MediaWiki  master
UserNamePrefixSearch.php
Go to the documentation of this file.
1 <?php
24 
31 
41  public static function search( $audience, $search, $limit, $offset = 0 ) {
42  $user = User::newFromName( $search );
43 
44  $dbr = wfGetDB( DB_REPLICA );
45  $prefix = $user ? $user->getName() : '';
46  $tables = [ 'user' ];
47  $cond = [ 'user_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ) ];
48  $joinConds = [];
49 
50  // Filter out hidden user names
51  if ( $audience === 'public' || !MediaWikiServices::getInstance()
52  ->getPermissionManager()
53  ->userHasRight( $audience, 'hideuser' )
54  ) {
55  $tables[] = 'ipblocks';
56  $cond['ipb_deleted'] = [ 0, null ];
57  $joinConds['ipblocks'] = [ 'LEFT JOIN', 'user_id=ipb_user' ];
58  }
59 
60  $res = $dbr->selectFieldValues(
61  $tables,
62  'user_name',
63  $cond,
64  __METHOD__,
65  [
66  'LIMIT' => $limit,
67  'ORDER BY' => 'user_name',
68  'OFFSET' => $offset
69  ],
70  $joinConds
71  );
72 
73  return $res;
74  }
75 }
Handles searching prefixes of user names.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static search( $audience, $search, $limit, $offset=0)
Do a prefix search of user names and return a list of matching user names.
const DB_REPLICA
Definition: defines.php:25
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:515