MediaWiki master
ApiQueryBlockInfoTrait.php
Go to the documentation of this file.
1<?php
30
36
45 private function addBlockInfoToQuery( $showBlockInfo ) {
46 wfDeprecated( __METHOD__, '1.42' );
47 $db = $this->getDB();
48
49 if ( $showBlockInfo ) {
50 $queryInfo = DatabaseBlock::getQueryInfo();
51 } else {
52 $queryInfo = [
53 'tables' => [ 'ipblocks' ],
54 'fields' => [ 'ipb_deleted' ],
55 'joins' => [],
56 ];
57 }
58
59 $this->addTables( [ 'blk' => $queryInfo['tables'] ] );
60 $this->addFields( $queryInfo['fields'] );
61 $this->addJoinConds( $queryInfo['joins'] );
62 $this->addJoinConds( [
63 'blk' => [ 'LEFT JOIN', [
64 'ipb_user=user_id',
65 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() ),
66 ] ],
67 ] );
68
69 // Don't show hidden names
70 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
71 $this->addWhere( [ 'ipb_deleted' => [ 0, null ] ] );
72 }
73 }
74
82 private function addDeletedUserFilter() {
83 // TODO: inject dependencies the way ApiWatchlistTrait does
84 $utils = MediaWikiServices::getInstance()->getHideUserUtils();
85 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
86 $this->addWhere( $utils->getExpression( $this->getDB() ) );
87 // The field is always false since we are filtering out rows where it is true
88 $this->addFields( [ 'hu_deleted' => '1=0' ] );
89 } else {
90 $this->addFields( [
91 'hu_deleted' => $utils->getExpression(
92 $this->getDB(),
93 'user_id',
94 HideUserUtils::HIDDEN_USERS
95 )
96 ] );
97 }
98 }
99
110 private function getBlockDetailsForRows( $rows ) {
111 $ids = [];
112 foreach ( $rows as $row ) {
113 $ids[] = (int)$row->user_id;
114 }
115 if ( !$ids ) {
116 return [];
117 }
118 $blocks = MediaWikiServices::getInstance()->getDatabaseBlockStore()
119 ->newListFromConds( [ 'bt_user' => $ids ] );
120 $blocksByUser = [];
121 foreach ( $blocks as $block ) {
122 $blocksByUser[$block->getTargetUserIdentity()->getId()][] = $block;
123 }
124 $infoByUser = [];
125 foreach ( $blocksByUser as $id => $userBlocks ) {
126 if ( count( $userBlocks ) > 1 ) {
127 $maybeCompositeBlock = CompositeBlock::createFromBlocks( ...$userBlocks );
128 } else {
129 $maybeCompositeBlock = $userBlocks[0];
130 }
131 $infoByUser[$id] = $this->getBlockDetails( $maybeCompositeBlock );
132 }
133 return $infoByUser;
134 }
135
136 /***************************************************************************/
137 // region Methods required from ApiQueryBase
144 abstract protected function getDB();
145
150 abstract public function getAuthority();
151
157 abstract protected function addTables( $tables, $alias = null );
158
163 abstract protected function addFields( $fields );
164
169 abstract protected function addWhere( $conds );
170
175 abstract protected function addJoinConds( $conds );
176
180 abstract protected function getQueryBuilder();
181
182 // endregion -- end of methods required from ApiQueryBase
183
184}
getAuthority()
getDB()
addJoinConds( $conds)
addWhere( $conds)
addFields( $fields)
addTables( $tables, $alias=null)
getQueryBuilder()
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
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.