Injected SubscriptionStore into UnsubscribeAction

Dependency injection is now available to actions,
extension already requires MW 1.37+

Bug: T253078
Change-Id: I473abac19ed5e6f3c6706797e91704ff635f64c6
This commit is contained in:
DannyS712 2021-08-02 02:55:33 +00:00
parent b46893eb7d
commit 88ba997bed
2 changed files with 15 additions and 6 deletions

View file

@ -413,7 +413,12 @@
}
},
"Actions": {
"dtunsubscribe": "MediaWiki\\Extension\\DiscussionTools\\Actions\\UnsubscribeAction"
"dtunsubscribe": {
"class": "MediaWiki\\Extension\\DiscussionTools\\Actions\\UnsubscribeAction",
"services": [
"DiscussionTools.SubscriptionStore"
]
}
},
"ServiceWiringFiles": [
"includes/ServiceWiring.php"

View file

@ -9,7 +9,6 @@ use HTMLForm;
use IContextSource;
use MediaWiki\Extension\DiscussionTools\SubscriptionItem;
use MediaWiki\Extension\DiscussionTools\SubscriptionStore;
use MediaWiki\MediaWikiServices;
use Page;
use Title;
use User;
@ -24,10 +23,17 @@ class UnsubscribeAction extends FormAction {
protected $subscriptionItem = null;
/**
* @inheritDoc
* @param Page $page
* @param IContextSource $context
* @param SubscriptionStore $subscriptionStore
*/
public function __construct( Page $page, IContextSource $context = null ) {
public function __construct(
Page $page,
IContextSource $context,
SubscriptionStore $subscriptionStore
) {
parent::__construct( $page, $context );
$this->subscriptionStore = $subscriptionStore;
}
/**
@ -51,8 +57,6 @@ class UnsubscribeAction extends FormAction {
$commentName = $this->getRequest()->getVal( 'commentname' );
if ( $commentName ) {
$this->subscriptionStore =
MediaWikiServices::getInstance()->getService( 'DiscussionTools.SubscriptionStore' );
$subscriptionItems = $this->subscriptionStore->getSubscriptionItemsForUser(
$this->getUser(),
[ $commentName ]