Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
66 / 66 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
ApiQueryCheckUser | |
100.00% |
66 / 66 |
|
100.00% |
8 / 8 |
12 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
5 | |||
mustBePosted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isWriteMode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAllowedParams | |
100.00% |
37 / 37 |
|
100.00% |
1 / 1 |
1 | |||
getExamplesMessages | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
getHelpUrls | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
needsToken | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\CheckUser\Api; |
4 | |
5 | use ApiBase; |
6 | use ApiQuery; |
7 | use ApiQueryBase; |
8 | use MediaWiki\CheckUser\Services\ApiQueryCheckUserResponseFactory; |
9 | use MediaWiki\ParamValidator\TypeDef\UserDef; |
10 | use Wikimedia\ParamValidator\ParamValidator; |
11 | use Wikimedia\ParamValidator\TypeDef\EnumDef; |
12 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
13 | |
14 | /** |
15 | * CheckUser API Query Module |
16 | */ |
17 | class ApiQueryCheckUser extends ApiQueryBase { |
18 | |
19 | private ApiQueryCheckUserResponseFactory $responseFactory; |
20 | |
21 | /** |
22 | * @param ApiQuery $query |
23 | * @param string $moduleName |
24 | * @param ApiQueryCheckUserResponseFactory $responseFactory |
25 | */ |
26 | public function __construct( $query, $moduleName, ApiQueryCheckUserResponseFactory $responseFactory ) { |
27 | parent::__construct( $query, $moduleName, 'cu' ); |
28 | $this->responseFactory = $responseFactory; |
29 | } |
30 | |
31 | public function execute() { |
32 | $this->checkUserRightsAny( 'checkuser' ); |
33 | |
34 | $response = $this->responseFactory->newFromRequest( $this ); |
35 | $result = $this->getResult(); |
36 | |
37 | switch ( $response->getRequestType() ) { |
38 | case 'userips': |
39 | $result->addValue( [ 'query', $this->getModuleName() ], 'userips', $response->getResponseData() ); |
40 | $result->addIndexedTagName( [ 'query', $this->getModuleName(), 'userips' ], 'ip' ); |
41 | break; |
42 | |
43 | case 'actions': |
44 | $result->addValue( [ 'query', $this->getModuleName() ], 'edits', $response->getResponseData() ); |
45 | $result->addIndexedTagName( [ 'query', $this->getModuleName(), 'edits' ], 'action' ); |
46 | break; |
47 | |
48 | case 'ipusers': |
49 | $result->addValue( [ 'query', $this->getModuleName() ], 'ipusers', $response->getResponseData() ); |
50 | $result->addIndexedTagName( [ 'query', $this->getModuleName(), 'ipusers' ], 'user' ); |
51 | break; |
52 | |
53 | default: |
54 | $this->dieWithError( 'apierror-checkuser-invalidmode', 'invalidmode' ); |
55 | } |
56 | } |
57 | |
58 | /** @inheritDoc */ |
59 | public function mustBePosted() { |
60 | return true; |
61 | } |
62 | |
63 | /** @inheritDoc */ |
64 | public function isWriteMode() { |
65 | return true; |
66 | } |
67 | |
68 | /** @inheritDoc */ |
69 | public function getAllowedParams() { |
70 | return [ |
71 | 'request' => [ |
72 | ParamValidator::PARAM_REQUIRED => true, |
73 | ParamValidator::PARAM_TYPE => [ |
74 | 'userips', |
75 | 'edits', |
76 | 'actions', |
77 | 'ipusers', |
78 | ], |
79 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [ |
80 | 'edits' => 'apihelp-query+checkuser-paramvalue-request-actions' |
81 | ], |
82 | EnumDef::PARAM_DEPRECATED_VALUES => [ |
83 | 'edits' => true, |
84 | ] |
85 | ], |
86 | 'target' => [ |
87 | ParamValidator::PARAM_REQUIRED => true, |
88 | ParamValidator::PARAM_TYPE => 'user', |
89 | UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'temp', 'cidr' ], |
90 | ], |
91 | 'reason' => [ |
92 | ParamValidator::PARAM_DEFAULT => '', |
93 | ParamValidator::PARAM_REQUIRED => $this->getConfig()->get( 'CheckUserForceSummary' ) |
94 | ], |
95 | 'limit' => [ |
96 | ParamValidator::PARAM_DEFAULT => 500, |
97 | ParamValidator::PARAM_TYPE => 'limit', |
98 | IntegerDef::PARAM_MIN => 1, |
99 | IntegerDef::PARAM_MAX => 500, |
100 | IntegerDef::PARAM_MAX2 => $this->getConfig()->get( 'CheckUserMaximumRowCount' ), |
101 | ], |
102 | 'timecond' => [ |
103 | ParamValidator::PARAM_DEFAULT => '-2 weeks' |
104 | ], |
105 | 'xff' => null, |
106 | ]; |
107 | } |
108 | |
109 | /** @inheritDoc */ |
110 | protected function getExamplesMessages(): array { |
111 | return [ |
112 | 'action=query&list=checkuser&curequest=userips&cutarget=Jimbo_Wales' |
113 | => 'apihelp-query+checkuser-example-1', |
114 | 'action=query&list=checkuser&curequest=actions&cutarget=127.0.0.1/16&xff=1&cureason=Some_check' |
115 | => 'apihelp-query+checkuser-example-2', |
116 | ]; |
117 | } |
118 | |
119 | /** @inheritDoc */ |
120 | public function getHelpUrls() { |
121 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:CheckUser#API'; |
122 | } |
123 | |
124 | /** @inheritDoc */ |
125 | public function needsToken() { |
126 | return 'csrf'; |
127 | } |
128 | } |