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