Merge "Fix AbstractBlock param types in documentation"
[lhc/web/wiklou.git] / includes / api / ApiBlockInfoTrait.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\AbstractBlock;
22 use MediaWiki\Block\SystemBlock;
23
24 /**
25 * @ingroup API
26 */
27 trait ApiBlockInfoTrait {
28
29 /**
30 * Get basic info about a given block
31 * @param AbstractBlock $block
32 * @return array Array containing several keys:
33 * - blockid - ID of the block
34 * - blockedby - username of the blocker
35 * - blockedbyid - user ID of the blocker
36 * - blockreason - reason provided for the block
37 * - blockedtimestamp - timestamp for when the block was placed/modified
38 * - blockexpiry - expiry time of the block
39 * - systemblocktype - system block type, if any
40 */
41 private function getBlockDetails( AbstractBlock $block ) {
42 $vals = [];
43 $vals['blockid'] = $block->getId();
44 $vals['blockedby'] = $block->getByName();
45 $vals['blockedbyid'] = $block->getBy();
46 $vals['blockreason'] = $block->getReason();
47 $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
48 $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
49 $vals['blockpartial'] = !$block->isSitewide();
50 if ( $block instanceof SystemBlock ) {
51 $vals['systemblocktype'] = $block->getSystemBlockType();
52 }
53 return $vals;
54 }
55
56 }