MediaWiki master
ApiQueryBlockInfoTrait.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Api;
22
27use stdClass;
32
38
46 private function addDeletedUserFilter() {
47 // TODO: inject dependencies the way ApiWatchlistTrait does
48 $utils = MediaWikiServices::getInstance()->getHideUserUtils();
49 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
50 $this->addWhere( $utils->getExpression( $this->getDB() ) );
51 // The field is always false since we are filtering out rows where it is true
52 $this->addFields( [ 'hu_deleted' => '1=0' ] );
53 } else {
54 $this->addFields( [
55 'hu_deleted' => $utils->getExpression(
56 $this->getDB(),
57 'user_id',
58 HideUserUtils::HIDDEN_USERS
59 )
60 ] );
61 }
62 }
63
74 private function getBlockDetailsForRows( $rows ) {
75 $ids = [];
76 foreach ( $rows as $row ) {
77 $ids[] = (int)$row->user_id;
78 }
79 if ( !$ids ) {
80 return [];
81 }
82 $blocks = MediaWikiServices::getInstance()->getDatabaseBlockStore()
83 ->newListFromConds( [ 'bt_user' => $ids ] );
84 $blocksByUser = [];
85 foreach ( $blocks as $block ) {
86 $blocksByUser[$block->getTargetUserIdentity()->getId()][] = $block;
87 }
88 $infoByUser = [];
89 foreach ( $blocksByUser as $id => $userBlocks ) {
90 if ( count( $userBlocks ) > 1 ) {
91 $maybeCompositeBlock = CompositeBlock::createFromBlocks( ...$userBlocks );
92 } else {
93 $maybeCompositeBlock = $userBlocks[0];
94 }
95 $infoByUser[$id] = $this->getBlockDetails( $maybeCompositeBlock );
96 }
97 return $infoByUser;
98 }
99
100 /***************************************************************************/
101 // region Methods required from ApiQueryBase
108 abstract protected function getDB();
109
114 abstract public function getAuthority();
115
121 abstract protected function addTables( $tables, $alias = null );
122
127 abstract protected function addFields( $fields );
128
133 abstract protected function addWhere( $conds );
134
139 abstract protected function addJoinConds( $conds );
140
144 abstract protected function getQueryBuilder();
145
146 // endregion -- end of methods required from ApiQueryBase
147
148}
149
151class_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:37
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)