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     *  - systemblocktype - system block type, if any
34     *  - blockcomponents - If the block is a composite block, this will be an array of block
35     *    info arrays
36     */
37    private function getBlockDetails(
38        Block $block,
39        $language = null
40    ) {
41        return ( new ApiBlockInfoHelper )->getBlockDetails(
42            $block, $language ?? $this->getLanguage(), $this->getUser() );
43    }
44
45    /**
46     * Get the API error code, to be used in ApiMessage::create or ApiBase::dieWithError
47     * @param Block $block
48     * @return string
49     */
50    private function getBlockCode( Block $block ): string {
51        return ( new ApiBlockInfoHelper )->getBlockCode( $block );
52    }
53
54    // region   Methods required from ApiBase
55    /** @name   Methods required from ApiBase
56     * @{
57     */
58
59    /**
60     * @see IContextSource::getLanguage
61     * @return Language
62     */
63    abstract public function getLanguage();
64
65    /**
66     * @see IContextSource::getUser
67     * @return UserIdentity
68     */
69    abstract public function getUser();
70
71    /** @} */
72    // endregion -- end of methods required from ApiBase
73
74}
75
76/** @deprecated class alias since 1.43 */
77class_alias( ApiBlockInfoTrait::class, 'ApiBlockInfoTrait' );