MediaWiki master
ApiQueryBlockInfoTrait.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Api;
8
13use stdClass;
18
24
32 private function addDeletedUserFilter() {
33 // TODO: inject dependencies the way ApiWatchlistTrait does
34 $utils = MediaWikiServices::getInstance()->getHideUserUtils();
35 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
36 $this->addWhere( $utils->getExpression( $this->getDB() ) );
37 // The field is always false since we are filtering out rows where it is true
38 $this->addFields( [ 'hu_deleted' => '1=0' ] );
39 } else {
40 $this->addFields( [
41 'hu_deleted' => $utils->getExpression(
42 $this->getDB(),
43 'user_id',
44 HideUserUtils::HIDDEN_USERS
45 )
46 ] );
47 }
48 }
49
60 private function getBlockDetailsForRows( $rows ) {
61 $ids = [];
62 foreach ( $rows as $row ) {
63 $ids[] = (int)$row->user_id;
64 }
65 if ( !$ids ) {
66 return [];
67 }
68
69 $blockConds = [ 'bt_user' => $ids ];
70 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
71 $blockConds['bl_deleted'] = 0;
72 }
73
74 $blocks = MediaWikiServices::getInstance()->getDatabaseBlockStore()->newListFromConds( $blockConds );
75 $blocksByUser = [];
76 foreach ( $blocks as $block ) {
77 $blocksByUser[$block->getTargetUserIdentity()->getId()][] = $block;
78 }
79 $infoByUser = [];
80 foreach ( $blocksByUser as $id => $userBlocks ) {
81 if ( count( $userBlocks ) > 1 ) {
82 $maybeCompositeBlock = CompositeBlock::createFromBlocks( ...$userBlocks );
83 } else {
84 $maybeCompositeBlock = $userBlocks[0];
85 }
86 $infoByUser[$id] = $this->getBlockDetails( $maybeCompositeBlock );
87 }
88 return $infoByUser;
89 }
90
91 /***************************************************************************/
92 // region Methods required from ApiQueryBase
99 abstract protected function getDB();
100
105 abstract public function getAuthority();
106
112 abstract protected function addTables( $tables, $alias = null );
113
118 abstract protected function addFields( $fields );
119
124 abstract protected function addWhere( $conds );
125
130 abstract protected function addJoinConds( $conds );
131
135 abstract protected function getQueryBuilder();
136
137 // endregion -- end of methods required from ApiQueryBase
138
139}
140
142class_alias( ApiQueryBlockInfoTrait::class, 'ApiQueryBlockInfoTrait' );
Helpers for building queries that determine whether a user is hidden.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Build SELECT queries with a fluent interface.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:23
A database connection without write operations.
Result wrapper for grabbing data queried from an IDatabase object.
addTables( $tables, $alias=null)
addWhere( $conds)
addJoinConds( $conds)
addFields( $fields)