diff --git a/extension.json b/extension.json index f28cc0c8d..4d52c6539 100644 --- a/extension.json +++ b/extension.json @@ -185,7 +185,7 @@ ], "ListDefinedTags": "DiscussionToolsHooks::onListDefinedTags", "ChangeTagsListActive": "DiscussionToolsHooks::onListDefinedTags", - "ChangeTagsAllowedAdd": "DiscussionToolsHooks::onListDefinedTags" + "RecentChange_save": "DiscussionToolsHooks::onRecentChangeSave" }, "config": { "DiscussionToolsEnable": { diff --git a/includes/DiscussionToolsHooks.php b/includes/DiscussionToolsHooks.php index c1ae0f9c4..f5eca7b71 100644 --- a/includes/DiscussionToolsHooks.php +++ b/includes/DiscussionToolsHooks.php @@ -9,6 +9,17 @@ class DiscussionToolsHooks { + private static $tags = [ + 'discussiontools', + // Features: + 'discussiontools-reply', + 'discussiontools-edit', + 'discussiontools-newtopic', + // Input methods: + 'discussiontools-source', + 'discussiontools-visual', + ]; + public static function onRegistration() { global $wgLocaltimezone; // If $wgLocaltimezone isn't hard-coded, it is evaluated from the system @@ -59,20 +70,37 @@ class DiscussionToolsHooks { } /** - * Implements the ListDefinedTags, ChangeTagsListActive, and - * ChangeTagsAllowedAdd hooks, to populate core Special:Tags with the change - * tags in use by VisualEditor. + * Implements the ListDefinedTags and ChangeTagsListActive hooks, to + * populate core Special:Tags with the change tags in use by DiscussionTools. * * @param array &$tags Available change tags. */ public static function onListDefinedTags( &$tags ) { - $tags[] = 'discussiontools'; - // Features: - $tags[] = 'discussiontools-reply'; - $tags[] = 'discussiontools-edit'; - $tags[] = 'discussiontools-newsection'; - // Input methods: - $tags[] = 'discussiontools-source'; - $tags[] = 'discussiontools-visual'; + $tags = array_merge( $tags, static::$tags ); + } + + /** + * Implements the RecentChange_save hook, to add a whitelisted set of changetags + * to edits. + * + * @param RecentChange $recentChange + * @return bool + */ + public static function onRecentChangeSave( RecentChange $recentChange ) { + // only apply to api edits, since there's no case where discussiontools + // should be using the form-submit method. + if ( !defined( 'MW_API' ) ) { + return true; + } + $request = RequestContext::getMain()->getRequest(); + $tags = explode( ',', $request->getVal( 'dttags' ) ); + + $tags = array_values( array_intersect( $tags, static::$tags ) ); + + if ( $tags ) { + $recentChange->addTags( $tags ); + } + + return true; } } diff --git a/modules/controller.js b/modules/controller.js index 55d2cc144..a399c0c5e 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -109,7 +109,7 @@ function postReply( widget, parsoidData ) { etag: pageData.etag, token: pageData.token, // This appears redundant currently, but as editing / new-topics get added, we'll expand it - tags: [ 'discussiontools', 'discussiontools-reply', 'discussiontools-' + widget.mode ] + dttags: [ 'discussiontools', 'discussiontools-reply', 'discussiontools-' + widget.mode ].join( ',' ) } ); }