Page MenuHomePhabricator

Add date and time to newly-created comments in InlineComments
Closed, ResolvedPublic

Description

Currently, newly-created comments and replies in the InlineComments extensions appear with just the username, not the date and time; you need to reload the page to see those. That's because there's no easy way, within JavaScript, to display a datetime in the way that the current user prefers. Solving this may require creating an API action wihin InlineComments, so that the JS code can call the API to retrieve the correct string from PHP.

Event Timeline

@Yaron_Koren , on going through the codebase I understood a few things ,

  1. In makeComment.js the below code snippet gets the username and appends it to the textDiv when a comment is added.
if ( mw.config.get( 'wgUserName' ) !== null ) {
// username will be null if anon.
var author = document.createElement( 'div' );
author.className = 'mw-inlinecomment-author';
author.textContent = mw.config.get( 'wgUserName' );
textDiv.append(  author );
  1. In AnnotationFormatter.js the formatAuthor function formats the div to concatenate timestamp as well after the page is reloaded.
private function formatAuthor( $userId, $username, string $timestamp ) {
		return Html::rawElement(
			'div',
			[ 'class' => 'mw-inlinecomment-author' ],
			Linker::userLink( $userId, $username ) . $timestamp
		);
	}

I referred to these links https://www.mediawiki.org/wiki/API:Tutorial, https://www.mediawiki.org/w/api.php, https://www.mediawiki.org/wiki/Timestamp as well. To understand the codebase well, can you assist me further on how to proceed further and extract timestamp and implement the above functionality.

@Yaron_Koren I think I have figured out an implementation for this issue . I declared an AddTimestamp api which fetches timestamp from wfTimestampnow() and formats it in the same format as AnnotationFormatter.php and displays it with the author name and registered the api in extension.json . I have attached a screencast of the feature , should I make a draft PR as of now as more changes to AnnotationFormatter are yet to be done, also this is for makeComment.js , I believe similar changes have to be made for addReply.js as well.

@Rockingpenny4 - wow, this looks great! Yes, a patch would be great to see.

Change 1010349 had a related patch set uploaded (by Rockingpenny4; author: Rockingpenny4):

[mediawiki/extensions/InlineComments@master] Adds timestamp api to display correct date/time on comment creation

https://gerrit.wikimedia.org/r/1010349

Change 1010349 had a related patch set uploaded (by Rockingpenny4; author: Rockingpenny4):

[mediawiki/extensions/InlineComments@master] Add Timestamp display on comment creation

https://gerrit.wikimedia.org/r/1010349

Change 1010349 merged by jenkins-bot:

[mediawiki/extensions/InlineComments@master] Add Timestamp display on comment creation

https://gerrit.wikimedia.org/r/1010349

Change 1010852 had a related patch set uploaded (by Rockingpenny4; author: Rockingpenny4):

[mediawiki/extensions/InlineComments@master] Add timestamps to comment replies

https://gerrit.wikimedia.org/r/1010852

Change 1010852 merged by jenkins-bot:

[mediawiki/extensions/InlineComments@master] Add Timestamp display to comment replies

https://gerrit.wikimedia.org/r/1010852

Yaron_Koren claimed this task.

I think this can be closed. @Rockingpenny4 - thank you for your help with this!