Remove Revision::getRevisionText from ApiQueryDeletedrevs
[lhc/web/wiklou.git] / includes / api / ApiQueryBlockInfoTrait.php
1 <?php
2 /**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 use MediaWiki\Block\DatabaseBlock;
22 use MediaWiki\Permissions\PermissionManager;
23
24 /**
25 * @ingroup API
26 */
27 trait ApiQueryBlockInfoTrait {
28 use ApiBlockInfoTrait;
29
30 /**
31 * Filters hidden users (where the user doesn't have the right to view them)
32 * Also adds relevant block information
33 *
34 * @param bool $showBlockInfo
35 * @return void
36 */
37 private function addBlockInfoToQuery( $showBlockInfo ) {
38 $db = $this->getDB();
39
40 if ( $showBlockInfo ) {
41 $queryInfo = DatabaseBlock::getQueryInfo();
42 } else {
43 $queryInfo = [
44 'tables' => [ 'ipblocks' ],
45 'fields' => [ 'ipb_deleted' ],
46 'joins' => [],
47 ];
48 }
49
50 $this->addTables( [ 'blk' => $queryInfo['tables'] ] );
51 $this->addFields( $queryInfo['fields'] );
52 $this->addJoinConds( $queryInfo['joins'] );
53 $this->addJoinConds( [
54 'blk' => [ 'LEFT JOIN', [
55 'ipb_user=user_id',
56 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() ),
57 ] ],
58 ] );
59
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' );
63 }
64 }
65
66 /**
67 * @name Methods required from ApiQueryBase
68 * @{
69 */
70
71 /** @see ApiBase::getDB */
72 abstract protected function getDB();
73
74 /** @see ApiBase::getPermissionManager */
75 abstract protected function getPermissionManager(): PermissionManager;
76
77 /** @see IContextSource::getUser */
78 abstract public function getUser();
79
80 /** @see ApiQueryBase::addTables */
81 abstract protected function addTables( $tables, $alias = null );
82
83 /** @see ApiQueryBase::addFields */
84 abstract protected function addFields( $fields );
85
86 /** @see ApiQueryBase::addWhere */
87 abstract protected function addWhere( $conds );
88
89 /** @see ApiQueryBase::addJoinConds */
90 abstract protected function addJoinConds( $conds );
91
92 /**@}*/
93
94 }