mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 09:43:30 +00:00
Prevent using the reply tool together with Convenient Discussions gadget
Parts of the implementation copied from the Popups extension. Bug: T298909 Change-Id: I2c42c6ff1c5d84da9333f8f74a4aec5c8fea704b
This commit is contained in:
parent
38ff32c0e7
commit
e6fff19e7e
|
@ -8,6 +8,7 @@ $cfg['directory_list'] = array_merge(
|
|||
'../../extensions/VisualEditor',
|
||||
'../../extensions/Echo',
|
||||
'../../extensions/EventLogging',
|
||||
'../../extensions/Gadgets',
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -17,6 +18,7 @@ $cfg['exclude_analysis_directory_list'] = array_merge(
|
|||
'../../extensions/VisualEditor',
|
||||
'../../extensions/Echo',
|
||||
'../../extensions/EventLogging',
|
||||
'../../extensions/Gadgets',
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -636,6 +636,10 @@
|
|||
"value": "2022-07-12",
|
||||
"description": "Date on which the internal timestamp format has changed (T304595), in ISO 8601 format."
|
||||
},
|
||||
"DiscussionToolsConflictingGadgetName": {
|
||||
"value": "convenientDiscussions",
|
||||
"description": "Internal name of the Convenient Discussions gadget, which conflicts with the reply tool. Reply tool will be unavailable when the user has this gadget enabled."
|
||||
},
|
||||
"DTSchemaEditAttemptStepSamplingRate": {
|
||||
"value": 0,
|
||||
"description": "Rate at which to sample sessions for instrumentation; overrides WikimediaEvents rate if set to any number other than 0"
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
"discussiontools-preference-autotopicsub-help": "When you start a new discussion or comment in an existing discussion, you will be automatically notified when others post new comments to it.",
|
||||
"discussiontools-preference-description": "Enables experimental talk page features:\n* [https://www.mediawiki.org/wiki/Talk_pages_project/Replying Reply] to talk page comments with one click.\n* [https://www.mediawiki.org/wiki/Talk_pages_project/New_discussion Add new topics] using an inline form.\n* [https://www.mediawiki.org/wiki/Talk_pages_project/Notifications Receive notifications] when new comments are added in sections you have subscribed to.\n* [https://www.mediawiki.org/wiki/Talk_pages_project/Usability Show metadata] about each discussion and enable a new page layout.\n\nYou can customize these features in your [[Special:Preferences#mw-prefsection-editing-discussion|preferences]].\n\nUpdates will be posted on the [https://www.mediawiki.org/wiki/Talk_pages_project/Updates talk pages project's updates page].\n\nPlease note:\n* Over time, new experimental features will be added.\n* Some of the features above may not be available at your wiki yet.",
|
||||
"discussiontools-preference-discussion-link": "https://www.mediawiki.org/wiki/Talk:Talk_pages_project",
|
||||
"discussiontools-preference-gadget-conflict": "To enable quick replying, you will first need to [[$1|disable the Convenient Discussions gadget]] in your Gadget preferences.",
|
||||
"discussiontools-preference-info-link": "https://www.mediawiki.org/wiki/Special:MyLanguage/Talk_pages_project/Feature_summary",
|
||||
"discussiontools-preference-label": "Discussion tools",
|
||||
"discussiontools-preference-newtopictool": "Enable quick topic adding",
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
"discussiontools-preference-autotopicsub-help": "Used in [[Special:Preferences]].\n\nUsed as help text for the checkbox {{msg-mw|discussiontools-preference-autotopicsub}}",
|
||||
"discussiontools-preference-description": "Used in [[Special:Preferences]].\n\nUsed as description for the checkbox to enable discussion tools as a Beta Feature.\n\nThe label for this checkbox is {{msg-mw|discussiontools-preference-label}}.",
|
||||
"discussiontools-preference-discussion-link": "{{optional|Used on [[Special:Preferences]] as a link to a page where users can discuss this Beta Feature. Defaults to a page on MediaWiki.org.}}",
|
||||
"discussiontools-preference-gadget-conflict": "Additional label shown instead of {{msg-mw|discussiontools-preference-replytool}} when it can't be enabled due to a conflict with a gadget.",
|
||||
"discussiontools-preference-info-link": "{{optional|Used on [[Special:Preferences]] as a link to a page where users can learn about this Beta Feature. Defaults to a page on MediaWiki.org.}}",
|
||||
"discussiontools-preference-label": "Used in [[Special:Preferences]].\n\nUsed as label for checkbox to enable discussion tools as Beta Feature.\n\nThe description for this checkbox is: {{msg-mw|discussiontools-preference-description}}",
|
||||
"discussiontools-preference-newtopictool": "Used in [[Special:Preferences]] in the section titled {{msg-mw|prefs-discussion}}, in the same list with:\n* {{msg-mw|Discussiontools-preference-replytool}}.\n\nUsed as label for checkbox to enable the new topic tool.\n\nThe help text for this checkbox is: {{msg-mw|discussiontools-preference-newtopictool-help}}",
|
||||
|
|
|
@ -13,6 +13,7 @@ use ExtensionRegistry;
|
|||
use IContextSource;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
||||
use MediaWiki\Extension\DiscussionTools\ContentThreadItemSet;
|
||||
use MediaWiki\Extension\Gadgets\GadgetRepo;
|
||||
use MediaWiki\Extension\VisualEditor\ParsoidHelper;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
@ -54,6 +55,10 @@ class HookUtils {
|
|||
self::VISUALENHANCEMENTS_REPLY,
|
||||
];
|
||||
|
||||
public const FEATURES_CONFLICT_WITH_GADGET = [
|
||||
self::REPLYTOOL,
|
||||
];
|
||||
|
||||
protected static $propCache = [];
|
||||
|
||||
/**
|
||||
|
@ -113,6 +118,39 @@ class HookUtils {
|
|||
return $parser->parse( $container, $title );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserIdentity $user
|
||||
* @param string $feature Feature to check for
|
||||
* @return bool
|
||||
*/
|
||||
public static function featureConflictsWithGadget( UserIdentity $user, string $feature ) {
|
||||
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()
|
||||
->makeConfig( 'discussiontools' );
|
||||
$gadgetName = $dtConfig->get( 'DiscussionToolsConflictingGadgetName' );
|
||||
if ( !$gadgetName ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !in_array( $feature, static::FEATURES_CONFLICT_WITH_GADGET ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$extensionRegistry = ExtensionRegistry::getInstance();
|
||||
if ( $extensionRegistry->isLoaded( 'Gadgets' ) ) {
|
||||
$gadgetsRepo = GadgetRepo::singleton();
|
||||
$match = array_search( $gadgetName, $gadgetsRepo->getGadgetIds() );
|
||||
if ( $match !== false ) {
|
||||
try {
|
||||
return $gadgetsRepo->getGadget( $gadgetName )
|
||||
->isEnabled( $user );
|
||||
} catch ( \InvalidArgumentException $e ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a DiscussionTools feature is available to this user
|
||||
*
|
||||
|
@ -191,6 +229,9 @@ class HookUtils {
|
|||
$services = MediaWikiServices::getInstance();
|
||||
$optionsLookup = $services->getUserOptionsLookup();
|
||||
if ( $feature ) {
|
||||
if ( static::featureConflictsWithGadget( $user, $feature ) ) {
|
||||
return false;
|
||||
}
|
||||
// Check for a specific feature
|
||||
$enabled = $optionsLookup->getOption( $user, 'discussiontools-' . $feature );
|
||||
// `null` means there is no user option for this feature, so it must be enabled
|
||||
|
|
|
@ -103,6 +103,14 @@ class PreferenceHooks implements
|
|||
'section' => 'editing/discussion',
|
||||
];
|
||||
}
|
||||
|
||||
// Make this option unavailable when a conflicting Convenient Discussions gadget exists
|
||||
// (we can't use 'disable-if' or 'hide-if', because they don't let us change the labels).
|
||||
if ( HookUtils::featureConflictsWithGadget( $user, $feature ) ) {
|
||||
$preferences["discussiontools-$feature"]['disabled'] = true;
|
||||
$preferences["discussiontools-$feature"]['help-message'] =
|
||||
[ 'discussiontools-preference-gadget-conflict', 'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue