Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UnblockAutopromote
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
10
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
4
 mustBePosted
n/a
0 / 0
n/a
0 / 0
1
 isWriteMode
n/a
0 / 0
n/a
0 / 0
1
 getAllowedParams
n/a
0 / 0
n/a
0 / 0
1
 needsToken
n/a
0 / 0
n/a
0 / 0
1
 getExamplesMessages
n/a
0 / 0
n/a
0 / 0
1
1<?php
2
3namespace MediaWiki\Extension\AbuseFilter\Api;
4
5use MediaWiki\Api\ApiBase;
6use MediaWiki\Api\ApiMain;
7use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore;
8use MediaWiki\ParamValidator\TypeDef\UserDef;
9use Wikimedia\ParamValidator\ParamValidator;
10
11class UnblockAutopromote extends ApiBase {
12
13    public function __construct(
14        ApiMain $main,
15        string $action,
16        private readonly BlockAutopromoteStore $afBlockAutopromoteStore
17    ) {
18        parent::__construct( $main, $action );
19    }
20
21    /**
22     * @inheritDoc
23     */
24    public function execute() {
25        $this->checkUserRightsAny( 'abusefilter-modify' );
26
27        $params = $this->extractRequestParams();
28        $target = $params['user'];
29
30        $block = $this->getAuthority()->getBlock();
31        if ( $block && $block->isSitewide() ) {
32            $this->dieBlocked( $block );
33        }
34
35        $msg = $this->msg( 'abusefilter-tools-restoreautopromote' )->inContentLanguage()->text();
36        $res = $this->afBlockAutopromoteStore->unblockAutopromote( $target, $this->getUser(), $msg );
37
38        if ( !$res ) {
39            $this->dieWithError( [ 'abusefilter-reautoconfirm-none', $target->getName() ], 'notsuspended' );
40        }
41
42        $finalResult = [ 'user' => $target->getName() ];
43        $this->getResult()->addValue( null, $this->getModuleName(), $finalResult );
44    }
45
46    /**
47     * @codeCoverageIgnore Merely declarative
48     * @inheritDoc
49     */
50    public function mustBePosted() {
51        return true;
52    }
53
54    /**
55     * @codeCoverageIgnore Merely declarative
56     * @inheritDoc
57     */
58    public function isWriteMode() {
59        return true;
60    }
61
62    /**
63     * @codeCoverageIgnore Merely declarative
64     * @inheritDoc
65     */
66    public function getAllowedParams() {
67        return [
68            'user' => [
69                ParamValidator::PARAM_TYPE => 'user',
70                ParamValidator::PARAM_REQUIRED => true,
71                UserDef::PARAM_RETURN_OBJECT => true,
72                UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name' ],
73            ],
74            'token' => null,
75        ];
76    }
77
78    /**
79     * @codeCoverageIgnore Merely declarative
80     * @inheritDoc
81     */
82    public function needsToken() {
83        return 'csrf';
84    }
85
86    /**
87     * @codeCoverageIgnore Merely declarative
88     * @inheritDoc
89     */
90    protected function getExamplesMessages() {
91        return [
92            'action=abusefilterunblockautopromote&user=Example&token=123ABC'
93                => 'apihelp-abusefilterunblockautopromote-example-1',
94        ];
95    }
96}