3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\Block\DatabaseBlock
;
22 use MediaWiki\Permissions\PermissionManager
;
27 trait ApiQueryBlockInfoTrait
{
28 use ApiBlockInfoTrait
;
31 * Filters hidden users (where the user doesn't have the right to view them)
32 * Also adds relevant block information
34 * @param bool $showBlockInfo
37 private function addBlockInfoToQuery( $showBlockInfo ) {
40 if ( $showBlockInfo ) {
41 $queryInfo = DatabaseBlock
::getQueryInfo();
44 'tables' => [ 'ipblocks' ],
45 'fields' => [ 'ipb_deleted' ],
50 $this->addTables( [ 'blk' => $queryInfo['tables'] ] );
51 $this->addFields( $queryInfo['fields'] );
52 $this->addJoinConds( $queryInfo['joins'] );
53 $this->addJoinConds( [
54 'blk' => [ 'LEFT JOIN', [
56 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() ),
60 // Don't show hidden names
61 if ( !$this->getPermissionManager()->userHasRight( $this->getUser(), 'hideuser' ) ) {
62 $this->addWhere( 'ipb_deleted = 0 OR ipb_deleted IS NULL' );
67 * @name Methods required from ApiQueryBase
71 /** @see ApiBase::getDB */
72 abstract protected function getDB();
74 /** @see ApiBase::getPermissionManager */
75 abstract protected function getPermissionManager(): PermissionManager
;
77 /** @see IContextSource::getUser */
78 abstract public function getUser();
80 /** @see ApiQueryBase::addTables */
81 abstract protected function addTables( $tables, $alias = null );
83 /** @see ApiQueryBase::addFields */
84 abstract protected function addFields( $fields );
86 /** @see ApiQueryBase::addWhere */
87 abstract protected function addWhere( $conds );
89 /** @see ApiQueryBase::addJoinConds */
90 abstract protected function addJoinConds( $conds );