subscriptionStore = $subscriptionStore; } /** * @inheritDoc */ public function execute() { // This should probably use dependency injection, but the check is only temporary $services = MediaWikiServices::getInstance(); $dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' ); if ( $dtConfig->get( 'DiscussionTools_' . HookUtils::TOPICSUBSCRIPTION ) === 'unavailable' ) { $this->dieWithError( [ 'apierror-moduledisabled', $this->getModuleName() ] ); } $user = $this->getUser(); if ( !$user || $user->isAnon() ) { // TODO: More specific error message $this->dieWithError( 'apierror-mustbeloggedin-generic', 'notloggedin' ); } '@phan-var User $user'; $params = $this->extractRequestParams(); $title = Title::newFromText( $params['page'] ); $result = null; if ( !$title ) { $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] ); return; } $commentName = $params['commentname']; $subscribe = $params['subscribe']; if ( $subscribe ) { $this->subscriptionStore->addSubscriptionForUser( $user, $title, $commentName ); } else { $this->subscriptionStore->removeSubscriptionForUser( $user, $commentName ); } // TODO: Subscribe should be tri-state: // * subscribe (add row) // * ubsubscribe (delete row) // * mute (set state=0) $result = [ 'page' => $title, 'commentname' => $commentName, 'subscribe' => $subscribe ]; $this->getResult()->addValue( null, $this->getModuleName(), $result ); } /** * @inheritDoc */ public function getAllowedParams() { return [ 'page' => [ ParamValidator::PARAM_REQUIRED => true, ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-page', ], 'token' => [ ParamValidator::PARAM_REQUIRED => true, ], 'commentname' => [ ParamValidator::PARAM_REQUIRED => true, ApiBase::PARAM_HELP_MSG => 'apihelp-discussiontoolsedit-param-commentname', ], 'subscribe' => [ ParamValidator::PARAM_TYPE => 'boolean', ParamValidator::PARAM_REQUIRED => true, ], ]; } /** * @inheritDoc */ public function needsToken() { return 'csrf'; } /** * @inheritDoc */ public function isInternal() { return true; } /** * @inheritDoc */ public function isWriteMode() { return true; } }