| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Api; |
| 22 |
|
| 23 |
use MediaWiki\Block\CompositeBlock; |
| 24 |
use MediaWiki\Block\HideUserUtils; |
| 25 |
use MediaWiki\MediaWikiServices; |
| 26 |
use MediaWiki\Permissions\Authority; |
| 27 |
use stdClass; |
| 28 |
use Wikimedia\Rdbms\IExpression; |
| 29 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 30 |
use Wikimedia\Rdbms\IResultWrapper; |
| 31 |
use Wikimedia\Rdbms\SelectQueryBuilder; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
trait ApiQueryBlockInfoTrait { |
| 37 |
use ApiBlockInfoTrait; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
private function addDeletedUserFilter() { |
| 47 |
|
| 48 |
$utils = MediaWikiServices::getInstance()->getHideUserUtils(); |
| 49 |
if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) { |
| 50 |
$this->addWhere( $utils->getExpression( $this->getDB() ) ); |
| 51 |
|
| 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 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 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 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
abstract protected function getDB(); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
abstract public function getAuthority(); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
abstract protected function addTables( $tables, $alias = null ); |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
abstract protected function addFields( $fields ); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
abstract protected function addWhere( $conds ); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
abstract protected function addJoinConds( $conds ); |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
abstract protected function getQueryBuilder(); |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
class_alias( ApiQueryBlockInfoTrait::class, 'ApiQueryBlockInfoTrait' ); |