Config: Explicitly check feature availability in the client

Don't assume a feature is available because the code has
loaded and the user option is set. Export the logic from
Hooks.php to the client.

Change-Id: Ica0e58de7ed0d59e3b09645193eb2b691ae41c39
This commit is contained in:
Ed Sanders 2021-01-14 19:04:18 +00:00
parent 99acd2a925
commit c42e86f0f6
2 changed files with 10 additions and 1 deletions

View file

@ -267,6 +267,14 @@ class Hooks {
'ext.discussionTools.init'
] );
$output->addJsConfigVars(
'wgDiscussionToolsFeaturesEnabled',
[
'replytool' => static::isFeatureEnabledForOutput( $output, 'replytool' ),
'newtopictool' => static::isFeatureEnabledForOutput( $output, 'newtopictool' ),
]
);
$services = MediaWikiServices::getInstance();
$optionsLookup = $services->getUserOptionsLookup();
$req = $output->getRequest();

View file

@ -4,6 +4,7 @@ var
$pageContainer,
newTopicController,
$overlay,
featuresEnabled = mw.config.get( 'wgDiscussionToolsFeaturesEnabled' ),
Parser = require( './Parser.js' ),
ThreadItem = require( './ThreadItem.js' ),
logger = require( './logger.js' ),
@ -276,7 +277,7 @@ function init( $container, state ) {
}
}
if ( mw.user.options.get( 'discussiontools-newtopictool' ) ) {
if ( featuresEnabled.newtopictool && mw.user.options.get( 'discussiontools-newtopictool' ) ) {
if ( newTopicController ) {
// Stop the torn down controller from re-appearing
newTopicController.$replyLink.off( 'click keypress', newTopicController.onReplyLinkClickHandler );