Add preference to expand the "Advanced" menu when replying

* Add the preference
* Only display it when the reply tool is enabled
* Use it when opening the reply tool
* Save it when the menu is toggled from the reply tool interface

Bug: T261539
Change-Id: Icb8fa6b3f1e9a3644669f21b08f34ea8c175f2f9
This commit is contained in:
Bartosz Dziewoński 2020-10-15 17:04:36 +02:00
parent fe520ab175
commit 2f28cfdf56
4 changed files with 35 additions and 6 deletions

View file

@ -11,6 +11,7 @@
"discussiontools-preference-discussion-link": "https:\/\/www.mediawiki.org\/wiki\/Talk:Talk_pages_project",
"discussiontools-preference-replytool": "Enable quick replying",
"discussiontools-preference-replytool-help": "This will show you a link to reply to talk page comments in one click. You can learn more about this feature by reading the [https:\/\/www.mediawiki.org\/wiki\/Special:MyLanguage\/Talk_pages_project\/Feature_summary feature summary].",
"discussiontools-preference-showadvanced": "Expand the \"{{int:discussiontools-replywidget-advanced}}\" menu when replying",
"discussiontools-replylink": "reply",
"discussiontools-replywidget-abandon": "Are you sure you want to discard the comment you are writing?",
"discussiontools-replywidget-abandon-discard": "Discard comment",

View file

@ -17,6 +17,7 @@
"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-replytool": "Used in [[Special:Preferences]].\n\nUsed as label for checkbox to enable the reply tool.\n\nThe help text for this checkbox is: {{msg-mw|discussiontools-preference-replytool-help}}",
"discussiontools-preference-replytool-help": "Used in [[Special:Preferences]].\n\nUsed as help text for the checkbox {{msg-mw|discussiontools-preference-replytool}}",
"discussiontools-preference-showadvanced": "Used in [[Special:Preferences]].\n\nUsed as label for checkbox to always expand the \"Advanced\" menu.",
"discussiontools-replylink": "Label for the reply link added after each comment. Use the same casing as section edit links.\n* {{Related|editsection}}.",
"discussiontools-replywidget-abandon": "Message shown when abandoning a comment\n\nSee also {{msg-mw|mw-widgets-abandonedit}}.",
"discussiontools-replywidget-abandon-discard": "Label for button to abandon a comment\n\nThis button follows {{msg-mw|discussiontools-replywidget-abandon}}.",

View file

@ -183,8 +183,9 @@ class Hooks {
* @param array &$preferences Their preferences object
*/
public static function onGetPreferences( User $user, array &$preferences ) {
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()
->makeConfig( 'discussiontools' );
$services = MediaWikiServices::getInstance();
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
$optionsLookup = $services->getUserOptionsLookup();
if (
$dtConfig->get( 'DiscussionToolsEnable' ) &&
@ -198,7 +199,25 @@ class Hooks {
];
}
$api = [ 'type' => 'api' ];
if (
$dtConfig->get( 'DiscussionToolsEnable' ) &&
(
// The 'hide-if' mechanism can't hide the empty section name, so instead hide the option
// here if we're in beta mode and the user has not enabled the beta feature
!$dtConfig->get( 'DiscussionToolsBeta' ) ||
$optionsLookup->getOption( $user, 'discussiontools-betaenable' )
)
) {
$basePrefName = $dtConfig->get( 'DiscussionToolsBeta' ) ?
'discussiontools-betaenable' : 'discussiontools-replytool';
$preferences['discussiontools-showadvanced'] = [
'type' => 'toggle',
'label-message' => 'discussiontools-preference-showadvanced',
'section' => 'editing/discussion',
'hide-if' => [ '!==', $basePrefName, '1' ],
];
}
$preferences['discussiontools-editmode'] = [
'type' => 'api',
'validation-callback' => function ( $value ) {

View file

@ -281,11 +281,15 @@ ReplyWidget.prototype.saveEditMode = function ( mode ) {
};
ReplyWidget.prototype.onAdvancedToggleClick = function () {
var showAdvanced = !this.showAdvanced;
mw.track( 'dt.schemaVisualEditorFeatureUse', {
feature: 'dtReply',
action: 'advanced-' + ( this.showAdvanced ? 'hide' : 'show' )
action: 'advanced-' + ( showAdvanced ? 'show' : 'hide' )
} );
this.toggleAdvanced();
this.api.saveOption( 'discussiontools-showadvanced', +showAdvanced ).then( function () {
mw.user.options.set( 'discussiontools-showadvanced', +showAdvanced );
} );
this.toggleAdvanced( showAdvanced );
};
ReplyWidget.prototype.toggleAdvanced = function ( showAdvanced ) {
@ -398,7 +402,11 @@ ReplyWidget.prototype.setup = function ( data ) {
summary += mw.msg( 'discussiontools-defaultsummary-reply' );
}
this.toggleAdvanced( !!this.storage.get( this.storagePrefix + '/showAdvanced' ) || !!data.showAdvanced );
this.toggleAdvanced(
!!this.storage.get( this.storagePrefix + '/showAdvanced' ) ||
!!+mw.user.options.get( 'discussiontools-showadvanced' ) ||
!!data.showAdvanced
);
this.editSummaryInput.setValue( summary );