Debian Codegraph @

extensions/AbuseFilter/includes/Api/UnblockAutopromote.php

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