2021-01-29 17:09:52 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools preference hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
|
|
|
use RequestContext;
|
|
|
|
use User;
|
|
|
|
|
|
|
|
class PreferenceHooks implements
|
|
|
|
GetPreferencesHook
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handler for the GetPreferences hook, to add and hide user preferences as configured
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @param array &$preferences
|
|
|
|
*/
|
|
|
|
public function onGetPreferences( $user, &$preferences ) {
|
2021-08-18 18:14:39 +00:00
|
|
|
if ( HookUtils::isFeatureAvailableToUser( $user ) ) {
|
|
|
|
$preferences['discussiontools-summary'] = [
|
|
|
|
'type' => 'info',
|
|
|
|
'default' => wfMessage( 'discussiontools-preference-summary' )->parse(),
|
|
|
|
'raw' => true,
|
|
|
|
'section' => 'editing/discussion',
|
|
|
|
];
|
|
|
|
}
|
2021-02-17 17:16:17 +00:00
|
|
|
foreach ( HookUtils::FEATURES as $feature ) {
|
|
|
|
if ( HookUtils::isFeatureAvailableToUser( $user, $feature ) ) {
|
|
|
|
$preferences["discussiontools-$feature"] = [
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => "discussiontools-preference-$feature",
|
|
|
|
'help-message' => "discussiontools-preference-$feature-help",
|
|
|
|
'section' => 'editing/discussion',
|
|
|
|
];
|
|
|
|
}
|
2021-01-29 17:09:52 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 12:30:28 +00:00
|
|
|
if ( isset( $preferences['discussiontools-' . HookUtils::SOURCEMODETOOLBAR] ) ) {
|
2021-03-08 13:25:59 +00:00
|
|
|
// Hide this option when it would have no effect
|
|
|
|
// (both reply tool and new topic tool are disabled)
|
2021-04-08 12:30:28 +00:00
|
|
|
$preferences['discussiontools-' . HookUtils::SOURCEMODETOOLBAR]['hide-if'] = [ 'AND',
|
|
|
|
[ '===', 'discussiontools-' . HookUtils::REPLYTOOL, '' ],
|
|
|
|
[ '===', 'discussiontools-' . HookUtils::NEWTOPICTOOL, '' ],
|
2021-03-08 13:25:59 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-01-29 17:09:52 +00:00
|
|
|
$preferences['discussiontools-showadvanced'] = [
|
|
|
|
'type' => 'api',
|
|
|
|
];
|
|
|
|
$preferences['discussiontools-abtest'] = [
|
|
|
|
'type' => 'api',
|
|
|
|
];
|
|
|
|
|
|
|
|
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()
|
|
|
|
->makeConfig( 'discussiontools' );
|
|
|
|
if (
|
|
|
|
!$dtConfig->get( 'DiscussionToolsEnable' ) ||
|
|
|
|
!$dtConfig->get( 'DiscussionToolsBeta' )
|
|
|
|
) {
|
|
|
|
// When out of beta, preserve the user preference in case we
|
|
|
|
// bring back the beta feature for a new sub-feature. (T272071)
|
|
|
|
$preferences['discussiontools-betaenable'] = [
|
|
|
|
'type' => 'api'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$preferences['discussiontools-editmode'] = [
|
|
|
|
'type' => 'api',
|
2021-05-05 06:59:38 +00:00
|
|
|
'validation-callback' => static function ( $value ) {
|
2021-01-29 17:09:52 +00:00
|
|
|
return in_array( $value, [ '', 'source', 'visual' ], true );
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the GetBetaFeaturePreferences hook, to add and hide user beta preferences as configured
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @param array &$preferences
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public static function onGetBetaFeaturePreferences( User $user, array &$preferences ): void {
|
2021-01-29 17:09:52 +00:00
|
|
|
$coreConfig = RequestContext::getMain()->getConfig();
|
|
|
|
$iconpath = $coreConfig->get( 'ExtensionAssetsPath' ) . '/DiscussionTools/images';
|
|
|
|
|
|
|
|
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()
|
|
|
|
->makeConfig( 'discussiontools' );
|
|
|
|
|
|
|
|
if (
|
|
|
|
$dtConfig->get( 'DiscussionToolsEnable' ) &&
|
|
|
|
$dtConfig->get( 'DiscussionToolsBeta' )
|
|
|
|
) {
|
|
|
|
$preferences['discussiontools-betaenable'] = [
|
|
|
|
'version' => '1.0',
|
|
|
|
'label-message' => 'discussiontools-preference-label',
|
|
|
|
'desc-message' => 'discussiontools-preference-description',
|
|
|
|
'screenshot' => [
|
|
|
|
'ltr' => "$iconpath/betafeatures-icon-DiscussionTools-ltr.svg",
|
|
|
|
'rtl' => "$iconpath/betafeatures-icon-DiscussionTools-rtl.svg",
|
|
|
|
],
|
|
|
|
'info-message' => 'discussiontools-preference-info-link',
|
|
|
|
'discussion-message' => 'discussiontools-preference-discussion-link',
|
|
|
|
'requirements' => [
|
|
|
|
'javascript' => true
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|