Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiDiscussionToolsGetSubscriptions
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\DiscussionTools;
4
5use ApiBase;
6use ApiMain;
7use Wikimedia\ParamValidator\ParamValidator;
8
9class ApiDiscussionToolsGetSubscriptions extends ApiBase {
10
11    private SubscriptionStore $subscriptionStore;
12
13    public function __construct(
14        ApiMain $main,
15        string $name,
16        SubscriptionStore $subscriptionStore
17    ) {
18        parent::__construct( $main, $name );
19        $this->subscriptionStore = $subscriptionStore;
20    }
21
22    /**
23     * @inheritDoc
24     */
25    public function execute() {
26        $user = $this->getUser();
27        if ( !$user->isRegistered() ) {
28            $this->dieWithError( 'apierror-mustbeloggedin-generic', 'notloggedin' );
29        }
30
31        $params = $this->extractRequestParams();
32        $itemNames = $params['commentname'];
33        $items = $this->subscriptionStore->getSubscriptionItemsForUser(
34            $user,
35            $itemNames
36        );
37
38        // Ensure consistent formatting in JSON and XML formats
39        $this->getResult()->addIndexedTagName( 'subscriptions', 'subscription' );
40        $this->getResult()->addArrayType( 'subscriptions', 'kvp', 'name' );
41
42        foreach ( $items as $item ) {
43            $this->getResult()->addValue( 'subscriptions', $item->getItemName(), $item->getState() );
44        }
45    }
46
47    /**
48     * @inheritDoc
49     */
50    public function getAllowedParams() {
51        return [
52            'commentname' => [
53                ParamValidator::PARAM_REQUIRED => true,
54                ParamValidator::PARAM_ISMULTI => true,
55            ],
56        ];
57    }
58
59    /**
60     * @inheritDoc
61     */
62    public function isInternal() {
63        return true;
64    }
65}