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 $blocks = MediaWikiServices::getInstance()->getDatabaseBlockStore()
69 ->newListFromConds( [ 'bt_user' => $ids ] );
70 $blocksByUser = [];
71 foreach ( $blocks as $block ) {
72 $blocksByUser[$block->getTargetUserIdentity()->getId()][] = $block;
73 }
74 $infoByUser = [];
75 foreach ( $blocksByUser as $id => $userBlocks ) {
76 if ( count( $userBlocks ) > 1 ) {
77 $maybeCompositeBlock = CompositeBlock::createFromBlocks( ...$userBlocks );
78 } else {
79 $maybeCompositeBlock = $userBlocks[0];
80 }
81 $infoByUser[$id] = $this->getBlockDetails( $maybeCompositeBlock );
82 }
83 return $infoByUser;
84 }
85
86 /***************************************************************************/
87 // region Methods required from ApiQueryBase
94 abstract protected function getDB();
95
100 abstract public function getAuthority();
101
107 abstract protected function addTables( $tables, $alias = null );
108
113 abstract protected function addFields( $fields );
114
119 abstract protected function addWhere( $conds );
120
125 abstract protected function addJoinConds( $conds );
126
130 abstract protected function getQueryBuilder();
131
132 // endregion -- end of methods required from ApiQueryBase
133
134}
135
137class_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)