| 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 |
|
| 25 |
|
| 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 |
|
| 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 |
|
| 51 |
|
| 52 |
public function getAllowedParams() { |
| 53 |
return [ |
| 54 |
'commentname' => [ |
| 55 |
ParamValidator::PARAM_REQUIRED => true, |
| 56 |
ParamValidator::PARAM_ISMULTI => true, |
| 57 |
], |
| 58 |
]; |
| 59 |
} |
| 60 |
} |