diff --git a/extension.json b/extension.json index 34d5e7ddc..b650bda6a 100644 --- a/extension.json +++ b/extension.json @@ -433,12 +433,18 @@ }, "APIModules": { "discussiontoolscompare": { - "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsCompare" + "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsCompare", + "services": [ + "DiscussionTools.CommentParser" + ] }, "discussiontoolsedit": { "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsEdit", "services": [ - "DiscussionTools.CommentParser" + "DiscussionTools.CommentParser", + "DiscussionTools.SubscriptionStore", + "SkinFactory", + "ConfigFactory" ] }, "discussiontoolsgetsubscriptions": { @@ -449,7 +455,10 @@ ] }, "discussiontoolspageinfo": { - "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPageInfo" + "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPageInfo", + "services": [ + "DiscussionTools.CommentParser" + ] }, "discussiontoolspreview": { "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPreview", diff --git a/includes/ApiDiscussionToolsCompare.php b/includes/ApiDiscussionToolsCompare.php index 0b1dee71b..967690d47 100644 --- a/includes/ApiDiscussionToolsCompare.php +++ b/includes/ApiDiscussionToolsCompare.php @@ -14,11 +14,21 @@ class ApiDiscussionToolsCompare extends ApiBase { use ApiDiscussionToolsTrait; use ApiParsoidTrait; + /** @var CommentParser */ + private $commentParser; + /** - * @inheritDoc + * @param ApiMain $main + * @param string $name + * @param CommentParser $commentParser */ - public function __construct( ApiMain $main, string $name ) { + public function __construct( + ApiMain $main, + string $name, + CommentParser $commentParser + ) { parent::__construct( $main, $name ); + $this->commentParser = $commentParser; } /** diff --git a/includes/ApiDiscussionToolsEdit.php b/includes/ApiDiscussionToolsEdit.php index 558502734..303e370a6 100644 --- a/includes/ApiDiscussionToolsEdit.php +++ b/includes/ApiDiscussionToolsEdit.php @@ -4,13 +4,15 @@ namespace MediaWiki\Extension\DiscussionTools; use ApiBase; use ApiMain; +use Config; +use ConfigFactory; use DerivativeContext; use DerivativeRequest; use MediaWiki\Extension\DiscussionTools\Hooks\HookUtils; use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentCommentItem; use MediaWiki\Extension\VisualEditor\ApiParsoidTrait; use MediaWiki\Logger\LoggerFactory; -use MediaWiki\MediaWikiServices; +use SkinFactory; use Title; use Wikimedia\ParamValidator\ParamValidator; use Wikimedia\ParamValidator\TypeDef\StringDef; @@ -25,18 +27,36 @@ class ApiDiscussionToolsEdit extends ApiBase { /** @var CommentParser */ private $commentParser; + /** @var SubscriptionStore */ + private $subscriptionStore; + + /** @var SkinFactory */ + private $skinFactory; + + /** @var Config */ + private $config; + /** * @param ApiMain $main * @param string $name * @param CommentParser $commentParser + * @param SubscriptionStore $subscriptionStore + * @param SkinFactory $skinFactory + * @param ConfigFactory $configFactory */ public function __construct( ApiMain $main, - $name, - CommentParser $commentParser + string $name, + CommentParser $commentParser, + SubscriptionStore $subscriptionStore, + SkinFactory $skinFactory, + ConfigFactory $configFactory ) { parent::__construct( $main, $name ); $this->commentParser = $commentParser; + $this->subscriptionStore = $subscriptionStore; + $this->skinFactory = $skinFactory; + $this->config = $configFactory->makeConfig( 'discussiontools' ); $this->setLogger( LoggerFactory::getInstance( 'DiscussionTools' ) ); } @@ -48,9 +68,8 @@ class ApiDiscussionToolsEdit extends ApiBase { $title = Title::newFromText( $params['page'] ); $result = null; - $dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' ); $autoSubscribe = - $dtConfig->get( 'DiscussionToolsAutoTopicSubEditor' ) === 'discussiontoolsapi' && + $this->config->get( 'DiscussionToolsAutoTopicSubEditor' ) === 'discussiontoolsapi' && HookUtils::shouldAddAutoSubscription( $this->getUser(), $title ); $subscribableHeadingName = null; $subscribableSectionTitle = ''; @@ -316,9 +335,9 @@ class ApiDiscussionToolsEdit extends ApiBase { } if ( $autoSubscribe && $subscribableHeadingName ) { - $subscriptionStore = MediaWikiServices::getInstance()->getService( 'DiscussionTools.SubscriptionStore' ); $subsTitle = $title->createFragmentTarget( $subscribableSectionTitle ); - $subscriptionStore->addAutoSubscriptionForUser( $this->getUser(), $subsTitle, $subscribableHeadingName ); + $this->subscriptionStore + ->addAutoSubscriptionForUser( $this->getUser(), $subsTitle, $subscribableHeadingName ); } // Check the post was successful (could have been blocked by ConfirmEdit) before @@ -383,9 +402,7 @@ class ApiDiscussionToolsEdit extends ApiBase { ParamValidator::PARAM_TYPE => 'string', ], 'useskin' => [ - ParamValidator::PARAM_TYPE => array_keys( - MediaWikiServices::getInstance()->getSkinFactory()->getInstalledSkins() - ), + ParamValidator::PARAM_TYPE => array_keys( $this->skinFactory->getInstalledSkins() ), ApiBase::PARAM_HELP_MSG => 'apihelp-parse-param-useskin', ], 'watchlist' => [ diff --git a/includes/ApiDiscussionToolsGetSubscriptions.php b/includes/ApiDiscussionToolsGetSubscriptions.php index 54378d543..1223761b7 100644 --- a/includes/ApiDiscussionToolsGetSubscriptions.php +++ b/includes/ApiDiscussionToolsGetSubscriptions.php @@ -18,7 +18,7 @@ class ApiDiscussionToolsGetSubscriptions extends ApiBase { */ public function __construct( ApiMain $main, - $name, + string $name, SubscriptionStore $subscriptionStore ) { parent::__construct( $main, $name ); diff --git a/includes/ApiDiscussionToolsPageInfo.php b/includes/ApiDiscussionToolsPageInfo.php index 8a8bf8a41..6a428fdde 100644 --- a/includes/ApiDiscussionToolsPageInfo.php +++ b/includes/ApiDiscussionToolsPageInfo.php @@ -19,11 +19,21 @@ class ApiDiscussionToolsPageInfo extends ApiBase { use ApiDiscussionToolsTrait; use ApiParsoidTrait; + /** @var CommentParser */ + private $commentParser; + /** - * @inheritDoc + * @param ApiMain $main + * @param string $name + * @param CommentParser $commentParser */ - public function __construct( ApiMain $main, string $name ) { + public function __construct( + ApiMain $main, + string $name, + CommentParser $commentParser + ) { parent::__construct( $main, $name ); + $this->commentParser = $commentParser; } /** diff --git a/includes/ApiDiscussionToolsPreview.php b/includes/ApiDiscussionToolsPreview.php index ff68d6aa2..c32cce2f0 100644 --- a/includes/ApiDiscussionToolsPreview.php +++ b/includes/ApiDiscussionToolsPreview.php @@ -30,7 +30,7 @@ class ApiDiscussionToolsPreview extends ApiBase { */ public function __construct( ApiMain $main, - $name, + string $name, CommentParser $commentParser, SkinFactory $skinFactory ) { diff --git a/includes/ApiDiscussionToolsSubscribe.php b/includes/ApiDiscussionToolsSubscribe.php index 5cf4a02e0..db411544d 100644 --- a/includes/ApiDiscussionToolsSubscribe.php +++ b/includes/ApiDiscussionToolsSubscribe.php @@ -19,7 +19,7 @@ class ApiDiscussionToolsSubscribe extends ApiBase { */ public function __construct( ApiMain $main, - $name, + string $name, SubscriptionStore $subscriptionStore ) { parent::__construct( $main, $name ); diff --git a/includes/ApiDiscussionToolsTrait.php b/includes/ApiDiscussionToolsTrait.php index b95e7548f..2ab3e00f5 100644 --- a/includes/ApiDiscussionToolsTrait.php +++ b/includes/ApiDiscussionToolsTrait.php @@ -7,7 +7,6 @@ use ApiResult; use DerivativeContext; use DerivativeRequest; use IContextSource; -use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; use Title; use TitleValue; @@ -16,6 +15,8 @@ use Wikimedia\Parsoid\Utils\DOMUtils; /** * Random methods we want to share between API modules. + * + * @property CommentParser $commentParser */ trait ApiDiscussionToolsTrait { /** @@ -32,8 +33,7 @@ trait ApiDiscussionToolsTrait { $title = TitleValue::newFromPage( $revision->getPage() ); - $parser = MediaWikiServices::getInstance()->getService( 'DiscussionTools.CommentParser' ); - return $parser->parse( $container, $title ); + return $this->commentParser->parse( $container, $title ); } /**