MediaWiki  1.34.0
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 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
UserNamePrefixSearch\search
static search( $audience, $search, $limit, $offset=0)
Do a prefix search of user names and return a list of matching user names.
Definition: UserNamePrefixSearch.php:41
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:515
$res
$res
Definition: testCompression.php:52
$dbr
$dbr
Definition: testCompression.php:50
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
UserNamePrefixSearch
Handles searching prefixes of user names.
Definition: UserNamePrefixSearch.php:30