Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
2 / 4
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiBlockInfoTrait
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
2.15
0.00% covered (danger)
0.00%
0 / 1
 getBlockDetails
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getBlockCode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLanguage
n/a
0 / 0
n/a
0 / 0
0
 getUser
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\Api;
8
9use MediaWiki\Block\Block;
10use MediaWiki\Language\Language;
11use MediaWiki\User\UserIdentity;
12
13/**
14 * @ingroup API
15 */
16trait ApiBlockInfoTrait {
17
18    /**
19     * Get basic info about a given block
20     * @param Block $block
21     * @param Language|null $language
22     * @return array Array containing several keys:
23     *  - blockid - ID of the block
24     *  - blockedby - username of the blocker
25     *  - blockedbyid - user ID of the blocker
26     *  - blockreason - reason provided for the block
27     *  - blockedtimestamp - timestamp for when the block was placed/modified
28     *  - blockedtimestampformatted - blockedtimestamp, formatted for the current locale
29     *  - blockexpiry - expiry time of the block
30     *  - blockexpiryformatted - blockexpiry formatted for the current locale, omitted if infinite
31     *  - blockexpiryrelative - relative time to blockexpiry (e.g. 'in 5 days'), omitted if infinite
32     *  - blockpartial - block only applies to certain pages, namespaces and/or actions
33     *  - blockhidden - true if the block is hidden from users without the hideuser right, omitted if false
34     *  - systemblocktype - system block type, if any
35     *  - blockcomponents - If the block is a composite block, this will be an array of block
36     *    info arrays
37     */
38    private function getBlockDetails(
39        Block $block,
40        $language = null
41    ) {
42        return ( new ApiBlockInfoHelper )->getBlockDetails(
43            $block, $language ?? $this->getLanguage(), $this->getUser() );
44    }
45
46    /**
47     * Get the API error code, to be used in ApiMessage::create or ApiBase::dieWithError
48     * @param Block $block
49     * @return string
50     */
51    private function getBlockCode( Block $block ): string {
52        return ( new ApiBlockInfoHelper )->getBlockCode( $block );
53    }
54
55    // region   Methods required from ApiBase
56    /** @name   Methods required from ApiBase
57     * @{
58     */
59
60    /**
61     * @see IContextSource::getLanguage
62     * @return Language
63     */
64    abstract public function getLanguage();
65
66    /**
67     * @see IContextSource::getUser
68     * @return UserIdentity
69     */
70    abstract public function getUser();
71
72    /** @} */
73    // endregion -- end of methods required from ApiBase
74
75}
76
77/** @deprecated class alias since 1.43 */
78class_alias( ApiBlockInfoTrait::class, 'ApiBlockInfoTrait' );