From 2577d5aa28f3e381de7cb9000fed0444fc17d678 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 18 Feb 2020 18:28:17 +0000 Subject: [PATCH] Add beta feature preference Bug: T245539 Change-Id: I8bb2c10255a13c291bc97c591612cadaf0e4339f --- extension.json | 5 +++ i18n/en.json | 4 ++ i18n/qqq.json | 4 ++ .../betafeatures-icon-DiscussionTools-ltr.svg | 31 ++++++++++++++ .../betafeatures-icon-DiscussionTools-rtl.svg | 31 ++++++++++++++ includes/DiscussionToolsHooks.php | 41 ++++++++++++++++++- 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 images/betafeatures-icon-DiscussionTools-ltr.svg create mode 100644 images/betafeatures-icon-DiscussionTools-rtl.svg diff --git a/extension.json b/extension.json index ec8473da6..5be2ead3a 100644 --- a/extension.json +++ b/extension.json @@ -184,6 +184,7 @@ "BeforePageDisplay": [ "DiscussionToolsHooks::onBeforePageDisplay" ], + "GetBetaFeaturePreferences": "DiscussionToolsHooks::onGetBetaPreferences", "ListDefinedTags": "DiscussionToolsHooks::onListDefinedTags", "ChangeTagsListActive": "DiscussionToolsHooks::onListDefinedTags", "RecentChange_save": "DiscussionToolsHooks::onRecentChangeSave" @@ -193,6 +194,10 @@ "value": true, "description": "Enable DiscussionTools on talk pages." }, + "DiscussionToolsBeta": { + "value": false, + "description": "Make DiscussionTools a BetaFeature." + }, "DiscussionToolsUseVisualEditor": { "value": false, "description": "Use VisualEditor for editing replies (both visual and wikitext)." diff --git a/i18n/en.json b/i18n/en.json index 1e7b5737c..80d828c2b 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,6 +5,10 @@ "discussiontools": "Discussion tools", "discussiontools-defaultsummary-reply": "Reply", "discussiontools-desc": "Tools to enhance discussion pages.", + "discussiontools-preference-label": "Discussion tools", + "discussiontools-preference-description": "Enable a new workflow for [//www.mediawiki.org/wiki/Talk_pages_project/replying replying to specific comments] on talk pages.\n\nPlease note that over time new tools for interacting with talk pages will be added.\n\nUpdates about these features will be posted on the [//www.mediawiki.org/wiki/Talk_pages_project/Updates talk pages project's updates page].", + "discussiontools-preference-info-link": "\/\/mediawiki.org\/wiki\/Talk_pages_project", + "discussiontools-preference-discussion-link": "\/\/mediawiki.org\/wiki\/Talk:Talk_pages_project", "discussiontools-replylink": "Reply", "discussiontools-replywidget-anon-warning": "You are not logged in. To receive attribution with your name instead of your IP address, you can [$1 log in] or [$2 create an account].", "discussiontools-replywidget-cancel": "Cancel", diff --git a/i18n/qqq.json b/i18n/qqq.json index f8bfed346..2997c8f64 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -9,6 +9,10 @@ "discussiontools": "{{name}}", "discussiontools-defaultsummary-reply": "Default edit summary for a reply.\n\n'''Note that this is a noun (''a reply''), not a verb (''to reply''). Alternatively you can use a paste tense verb if that's more natural in your language.'''", "discussiontools-desc": "{{desc\n| name = DiscussionTools\n| url = https://www.mediawiki.org/wiki/Extension:DiscussionTools\n}}", + "discussiontools-preference-description": "Used in [[Special:Preferences]].\n\nUsed as description for the checkbox to enable discussion tools.\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-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.\n\nThe description for this checkbox is: {{msg-mw|discussiontools-preference-description}}", "discussiontools-replylink": "Label for the reply link added after each comment.", "discussiontools-replywidget-anon-warning": "Warning message to be displayed when anonymous user starts writing a new topic or reply.\n* $1 is a URL to log in.\n* $2 is a URL to register an account.", "discussiontools-replywidget-cancel": "Label for the cancel button in the reply widget", diff --git a/images/betafeatures-icon-DiscussionTools-ltr.svg b/images/betafeatures-icon-DiscussionTools-ltr.svg new file mode 100644 index 000000000..8126e1aa5 --- /dev/null +++ b/images/betafeatures-icon-DiscussionTools-ltr.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/betafeatures-icon-DiscussionTools-rtl.svg b/images/betafeatures-icon-DiscussionTools-rtl.svg new file mode 100644 index 000000000..17acbf60e --- /dev/null +++ b/images/betafeatures-icon-DiscussionTools-rtl.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/includes/DiscussionToolsHooks.php b/includes/DiscussionToolsHooks.php index 9966ff840..55e43b8df 100644 --- a/includes/DiscussionToolsHooks.php +++ b/includes/DiscussionToolsHooks.php @@ -50,6 +50,11 @@ class DiscussionToolsHooks { $title = $output->getTitle(); $actionName = Action::getActionName( $output->getContext() ); $req = $output->getRequest(); + $user = $skin->getUser(); + $enabled = $dtConfig->get( 'DiscussionToolsEnable' ) && ( + !$dtConfig->get( 'DiscussionToolsBeta' ) || + $user->getOption( 'discussiontools-betaenable' ) + ); if ( // Don't show on edit pages @@ -61,7 +66,7 @@ class DiscussionToolsHooks { // Query parameter to load on any wikitext page for testing $req->getVal( 'dtenable' ) || // If configured, load on all talk pages - ( $dtConfig->get( 'DiscussionToolsEnable' ) && $title->isTalkPage() ) + ( $enabled && $title->isTalkPage() ) // TODO: Allow non talk pages to be treated as talk pages // using a magic word. ) @@ -72,6 +77,40 @@ class DiscussionToolsHooks { } } + /** + * Handler for the GetBetaPreferences hook, to add and hide user beta preferences as configured + * + * @param User $user The user object + * @param array &$preferences Their preferences object + */ + public static function onGetBetaPreferences( User $user, array &$preferences ) { + $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 + ] + ]; + } + } + /** * Implements the ListDefinedTags and ChangeTagsListActive hooks, to * populate core Special:Tags with the change tags in use by DiscussionTools.