Create a hidden revision tag for talk page comments

Bug: T262107
Depends-On: I21159d03eebaf46ad94f4273ba698a59b8019185
Change-Id: Iceddfaf6a4bcc5e8b5c85c8cd5638bf14aa7db03
This commit is contained in:
Bartosz Dziewoński 2021-07-22 20:05:34 +02:00
parent 47510a22f3
commit ad04b24ffd
5 changed files with 44 additions and 6 deletions

View file

@ -93,6 +93,8 @@
"echo-pref-tooltip-dt-subscription": "Notify me about activity on my talk page subscriptions.",
"tag-discussiontools": "-",
"tag-discussiontools-description": "Edit made using DiscussionTools",
"tag-discussiontools-added-comment": "-",
"tag-discussiontools-added-comment-description": "A talk page comment was added in this edit",
"tag-discussiontools-edit": "Edit comment",
"tag-discussiontools-edit-description": "User edited an existing comment with DiscussionTools",
"tag-discussiontools-newtopic": "[{{int:discussiontools-replywidget-newtopic-link}} New topic]",

View file

@ -102,6 +102,8 @@
"echo-pref-tooltip-dt-subscription": "{{doc-echo-pref-tooltip|title=Echo-category-title-dt-subscription}}",
"tag-discussiontools": "{{ignored}}Short description of the discussiontools tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit made using DiscussionTools.\n\nSee also:\n* {{msg-mw|Tag-discussiontools-description}}\n{{Related|tag-discussiontools}}",
"tag-discussiontools-description": "Long description of the discussiontools tag ({{msg-mw|Tag-discussiontools}}).\n\nShown on [[Special:Tags]].\n\nSee also:\n* {{msg-mw|Tag-discussiontools}}\n{{Related|tag-discussiontools}}",
"tag-discussiontools-added-comment": "{{ignored}}Short description of the discussiontools-added-comment tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit that adds a talk page comment (or comments), even if it wasn't made using DiscussionTools.\n\nSee also:\n* {{msg-mw|Tag-discussiontools-added-comment-description}}\n{{Related|tag-discussiontools}}",
"tag-discussiontools-added-comment-description": "Long description of the discussiontools-added-comment tag ({{msg-mw|Tag-discussiontools-added-comment}}).\n\nShown on [[Special:Tags]].\n\nSee also:\n* {{msg-mw|Tag-discussiontools-added-comment}}\n{{Related|tag-discussiontools}}",
"tag-discussiontools-edit": "Short description of the discussiontools-edit tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit to an existing comment made using DiscussionTools.\n\nThis message is always shown directly after {{msg-mw|tag-discussiontools}} and a comma.\n\nSee also:\n* {{msg-mw|Tag-discussiontools-edit-description}}\n{{Related|tag-discussiontools}}",
"tag-discussiontools-edit-description": "Long description of the discussiontools-edit tag ({{msg-mw|Tag-discussiontools-edit}}).\n\nShown on [[Special:Tags]].\n\nSee also:\n* {{msg-mw|Tag-discussiontools-edit}}\n{{Related|tag-discussiontools}}",
"tag-discussiontools-newtopic": "Short description of the discussiontools-newtopic tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit made using DiscussionTools to create a new section of a talk page.\n\nThis message is always shown directly after {{msg-mw|tag-discussiontools}} and a comma.\n\nSee also:\n* {{msg-mw|Tag-discussiontools-newtopic-description}}\n{{Related|tag-discussiontools}}",

View file

@ -26,6 +26,7 @@ class TagHooks implements
'discussiontools-reply',
'discussiontools-edit',
'discussiontools-newtopic',
'discussiontools-added-comment',
// Input methods:
'discussiontools-source',
'discussiontools-visual',

View file

@ -9,6 +9,8 @@
namespace MediaWiki\Extension\DiscussionTools\Notifications;
use ChangeTags;
use DeferredUpdates;
use EchoEvent;
use Error;
use IDBAccessObject;
@ -76,11 +78,6 @@ class EventDispatcher {
$userFactory = $services->getUserFactory();
$oldRevRecord = $revisionStore->getPreviousRevision( $newRevRecord, IDBAccessObject::READ_LATEST );
if ( $oldRevRecord === null ) {
// TODO: Handle page creation (oldRevRecord = null?)
return;
}
$title = Title::newFromLinkTarget(
$newRevRecord->getPageAsLinkTarget()
);
@ -96,7 +93,14 @@ class EventDispatcher {
return;
}
$oldParser = self::getParsedRevision( $oldRevRecord );
if ( $oldRevRecord !== null ) {
$oldParser = self::getParsedRevision( $oldRevRecord );
} else {
// Page creation
$doc = DOMUtils::parseHTML( '' );
$container = DOMCompat::getBody( $doc );
$oldParser = CommentParser::newFromGlobalState( $container );
}
$newParser = self::getParsedRevision( $newRevRecord );
self::generateEventsFromParsers( $events, $oldParser, $newParser, $newRevRecord, $title, $user );
@ -190,6 +194,14 @@ class EventDispatcher {
}
}
if ( $addedComments ) {
// It's a bit weird to do this here, in the middle of the hook handler for Echo. However:
// * Echo calls this from a PageSaveComplete hook handler as a DeferredUpdate,
// which is exactly how we would do this otherwise
// * It allows us to reuse the generated comment trees without any annoying caching
static::addCommentChangeTag( $newRevRecord );
}
foreach ( $addedComments as $newComment ) {
// Ignore comments by other users, e.g. in case of reverts or a discussion being moved.
// TODO: But what about someone signing another's comment?
@ -228,6 +240,19 @@ class EventDispatcher {
}
}
/**
* Add our change tag for a revision that adds new comments.
*
* @param RevisionRecord $newRevRecord
*/
protected static function addCommentChangeTag( RevisionRecord $newRevRecord ) {
// Unclear if DeferredUpdates::addCallableUpdate() is needed,
// but every extension does it that way.
DeferredUpdates::addCallableUpdate( static function () use ( $newRevRecord ) {
ChangeTags::addTags( [ 'discussiontools-added-comment' ], null, $newRevRecord->getId() );
} );
}
/**
* Return all users subscribed to a comment
*

View file

@ -42,4 +42,12 @@ class MockEventDispatcher extends EventDispatcher {
);
}
/**
* No-op for testing
*
* @param RevisionRecord $newRevRecord
*/
public static function addCommentChangeTag( RevisionRecord $newRevRecord ) {
}
}