MediaWiki master
HideUserUtils.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Block;
4
7
16 public const SHOWN_USERS = 1;
17
21 public const HIDDEN_USERS = 2;
22
36 public function getExpression(
38 string $userIdField = 'user_id',
39 $status = self::SHOWN_USERS
40 ) {
41 // Use a scalar subquery, not IN/EXISTS, to avoid materialization (T360160)
42 return '(' .
44 ->select( '1' )
45 // $userIdField may be e.g. block_target.bt_user so an inner table
46 // alias is necessary to ensure that that refers to the outer copy
47 // of the block_target table.
48 ->from( 'block_target', 'hu_block_target' )
49 ->join( 'block', 'hu_block', 'hu_block.bl_target=hu_block_target.bt_id' )
50 ->where( [ "hu_block_target.bt_user=$userIdField", 'hu_block.bl_deleted' => 1 ] )
51 ->caller( __METHOD__ )
52 ->getSQL() .
53 ') ' .
54 ( $status === self::HIDDEN_USERS ? 'IS NOT NULL' : 'IS NULL' );
55 }
56
69 public function addFieldToBuilder(
71 $userIdField = 'user_id',
72 $deletedFieldAlias = 'hu_deleted'
73 ) {
74 $cond = '(' .
75 $qb->newSubquery()
76 ->select( '1' )
77 // $userIdField may be e.g. block_target.bt_user so an inner table
78 // alias is necessary to ensure that that refers to the outer copy
79 // of the block_target table.
80 ->from( 'block_target', 'hu_block_target' )
81 ->join( 'block', 'hu_block', 'hu_block.bl_target=hu_block_target.bt_id' )
82 ->where( [ "hu_block_target.bt_user=$userIdField", 'hu_block.bl_deleted' => 1 ] )
83 ->caller( __METHOD__ )
84 ->getSQL() .
85 ') IS NOT NULL';
86 $qb->select( [ $deletedFieldAlias => $cond ] );
87 }
88}
Helpers for building queries that determine whether a user is hidden.
getExpression(IReadableDatabase $dbr, string $userIdField='user_id', $status=self::SHOWN_USERS)
Get an SQL expression suitable for use in WHERE clause which will be true for either hidden or non-hi...
const HIDDEN_USERS
Select users that are hidden.
const SHOWN_USERS
Select users that are not hidden.
addFieldToBuilder(SelectQueryBuilder $qb, $userIdField='user_id', $deletedFieldAlias='hu_deleted')
Add a field and related joins to the query builder.
Build SELECT queries with a fluent interface.
newSubquery()
Get an empty SelectQueryBuilder which can be used to build a subquery of this query.
select( $fields)
Add a field or an array of fields to the query.
A database connection without write operations.
newSelectQueryBuilder()
Create an empty SelectQueryBuilder which can be used to run queries against this connection.