MediaWiki master
ApiQueryBlockInfoTrait.php
Go to the documentation of this file.
1<?php
29
35
43 private function addDeletedUserFilter() {
44 // TODO: inject dependencies the way ApiWatchlistTrait does
45 $utils = MediaWikiServices::getInstance()->getHideUserUtils();
46 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
47 $this->addWhere( $utils->getExpression( $this->getDB() ) );
48 // The field is always false since we are filtering out rows where it is true
49 $this->addFields( [ 'hu_deleted' => '1=0' ] );
50 } else {
51 $this->addFields( [
52 'hu_deleted' => $utils->getExpression(
53 $this->getDB(),
54 'user_id',
55 HideUserUtils::HIDDEN_USERS
56 )
57 ] );
58 }
59 }
60
71 private function getBlockDetailsForRows( $rows ) {
72 $ids = [];
73 foreach ( $rows as $row ) {
74 $ids[] = (int)$row->user_id;
75 }
76 if ( !$ids ) {
77 return [];
78 }
79 $blocks = MediaWikiServices::getInstance()->getDatabaseBlockStore()
80 ->newListFromConds( [ 'bt_user' => $ids ] );
81 $blocksByUser = [];
82 foreach ( $blocks as $block ) {
83 $blocksByUser[$block->getTargetUserIdentity()->getId()][] = $block;
84 }
85 $infoByUser = [];
86 foreach ( $blocksByUser as $id => $userBlocks ) {
87 if ( count( $userBlocks ) > 1 ) {
88 $maybeCompositeBlock = CompositeBlock::createFromBlocks( ...$userBlocks );
89 } else {
90 $maybeCompositeBlock = $userBlocks[0];
91 }
92 $infoByUser[$id] = $this->getBlockDetails( $maybeCompositeBlock );
93 }
94 return $infoByUser;
95 }
96
97 /***************************************************************************/
98 // region Methods required from ApiQueryBase
105 abstract protected function getDB();
106
111 abstract public function getAuthority();
112
118 abstract protected function addTables( $tables, $alias = null );
119
124 abstract protected function addFields( $fields );
125
130 abstract protected function addWhere( $conds );
131
136 abstract protected function addJoinConds( $conds );
137
141 abstract protected function getQueryBuilder();
142
143 // endregion -- end of methods required from ApiQueryBase
144
145}
getAuthority()
getDB()
addJoinConds( $conds)
addWhere( $conds)
addFields( $fields)
addTables( $tables, $alias=null)
getQueryBuilder()
Helpers for building queries that determine whether a user is hidden.
Service locator for MediaWiki core services.
Build SELECT queries with a fluent interface.
trait ApiBlockInfoTrait
trait ApiQueryBlockInfoTrait
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.