Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
55 / 55 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ApiQueryCheckUserResponseFactory | |
100.00% |
55 / 55 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
newFromRequest | |
100.00% |
44 / 44 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\CheckUser\Services; |
4 | |
5 | use MediaWiki\CheckUser\Api\ApiQueryCheckUser; |
6 | use MediaWiki\CheckUser\Api\CheckUser\ApiQueryCheckUserAbstractResponse; |
7 | use MediaWiki\CheckUser\Api\CheckUser\ApiQueryCheckUserActionsResponse; |
8 | use MediaWiki\CheckUser\Api\CheckUser\ApiQueryCheckUserIpUsersResponse; |
9 | use MediaWiki\CheckUser\Api\CheckUser\ApiQueryCheckUserUserIpsResponse; |
10 | use MediaWiki\CommentStore\CommentStore; |
11 | use MediaWiki\Config\Config; |
12 | use MediaWiki\Revision\ArchivedRevisionLookup; |
13 | use MediaWiki\Revision\RevisionStore; |
14 | use MediaWiki\User\UserFactory; |
15 | use MediaWiki\User\UserIdentityLookup; |
16 | use MediaWiki\User\UserNameUtils; |
17 | use MessageLocalizer; |
18 | use Wikimedia\Rdbms\IConnectionProvider; |
19 | |
20 | class ApiQueryCheckUserResponseFactory { |
21 | |
22 | private IConnectionProvider $dbProvider; |
23 | private Config $config; |
24 | private MessageLocalizer $messageLocalizer; |
25 | private CheckUserLogService $checkUserLogService; |
26 | private UserNameUtils $userNameUtils; |
27 | private CheckUserLookupUtils $checkUserLookupUtils; |
28 | private UserIdentityLookup $userIdentityLookup; |
29 | private CommentStore $commentStore; |
30 | private RevisionStore $revisionStore; |
31 | private ArchivedRevisionLookup $archivedRevisionLookup; |
32 | private UserFactory $userFactory; |
33 | |
34 | public function __construct( |
35 | IConnectionProvider $dbProvider, |
36 | Config $config, |
37 | MessageLocalizer $messageLocalizer, |
38 | CheckUserLogService $checkUserLogService, |
39 | UserNameUtils $userNameUtils, |
40 | CheckUserLookupUtils $checkUserLookupUtils, |
41 | UserIdentityLookup $userIdentityLookup, |
42 | CommentStore $commentStore, |
43 | RevisionStore $revisionStore, |
44 | ArchivedRevisionLookup $archivedRevisionLookup, |
45 | UserFactory $userFactory |
46 | ) { |
47 | $this->dbProvider = $dbProvider; |
48 | $this->config = $config; |
49 | $this->messageLocalizer = $messageLocalizer; |
50 | $this->checkUserLogService = $checkUserLogService; |
51 | $this->userNameUtils = $userNameUtils; |
52 | $this->checkUserLookupUtils = $checkUserLookupUtils; |
53 | $this->userIdentityLookup = $userIdentityLookup; |
54 | $this->commentStore = $commentStore; |
55 | $this->revisionStore = $revisionStore; |
56 | $this->archivedRevisionLookup = $archivedRevisionLookup; |
57 | $this->userFactory = $userFactory; |
58 | } |
59 | |
60 | /** |
61 | * @param ApiQueryCheckUser $module The module that is handling the request (you should be able to use $this). |
62 | * @return ApiQueryCheckUserAbstractResponse |
63 | */ |
64 | public function newFromRequest( ApiQueryCheckUser $module ): ApiQueryCheckUserAbstractResponse { |
65 | // No items for the factory method exist yet, but will be added later. |
66 | switch ( $module->extractRequestParams()['request'] ) { |
67 | case 'userips': |
68 | return new ApiQueryCheckUserUserIpsResponse( |
69 | $module, |
70 | $this->dbProvider, |
71 | $this->config, |
72 | $this->messageLocalizer, |
73 | $this->checkUserLogService, |
74 | $this->userNameUtils, |
75 | $this->checkUserLookupUtils, |
76 | $this->userIdentityLookup, |
77 | ); |
78 | case 'edits': |
79 | $module->addDeprecation( |
80 | [ |
81 | 'apiwarn-deprecation-withreplacement', 'curequest=edits', 'curequest=actions' |
82 | ], |
83 | 'curequest=edits' |
84 | ); |
85 | // fall-through to 'actions' for now, eventually delete this entire case statement once 'edits' is |
86 | // removed after hard-deprecation. |
87 | case 'actions': |
88 | return new ApiQueryCheckUserActionsResponse( |
89 | $module, |
90 | $this->dbProvider, |
91 | $this->config, |
92 | $this->messageLocalizer, |
93 | $this->checkUserLogService, |
94 | $this->userNameUtils, |
95 | $this->checkUserLookupUtils, |
96 | $this->userIdentityLookup, |
97 | $this->commentStore, |
98 | $this->userFactory |
99 | ); |
100 | case 'ipusers': |
101 | return new ApiQueryCheckUserIpUsersResponse( |
102 | $module, |
103 | $this->dbProvider, |
104 | $this->config, |
105 | $this->messageLocalizer, |
106 | $this->checkUserLogService, |
107 | $this->userNameUtils, |
108 | $this->checkUserLookupUtils, |
109 | $this->userFactory |
110 | ); |
111 | default: |
112 | $module->dieWithError( 'apierror-checkuser-invalidmode', 'invalidmode' ); |
113 | } |
114 | } |
115 | } |