3 * Prefix search of user names.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Handles searching prefixes of user names
28 class UserNamePrefixSearch
{
31 * Do a prefix search of user names and return a list of matching user names.
33 * @param string|User $audience The string 'public' or a user object to show the search for
34 * @param string $search
36 * @param int $offset How many results to offset from the beginning
37 * @return array Array of strings
39 public static function search( $audience, $search, $limit, $offset = 0 ) {
40 $user = User
::newFromName( $search );
42 $dbr = wfGetDB( DB_REPLICA
);
43 $prefix = $user ?
$user->getName() : '';
45 $cond = [ 'user_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ) ];
48 // Filter out hidden user names
49 if ( $audience === 'public' ||
!$audience->isAllowed( 'hideuser' ) ) {
50 $tables[] = 'ipblocks';
51 $cond['ipb_deleted'] = [ 0, null ];
52 $joinConds['ipblocks'] = [ 'LEFT JOIN', 'user_id=ipb_user' ];
55 $res = $dbr->selectFieldValues(
62 'ORDER BY' => 'user_name',
68 return $res === false ?
[] : $res;