Page MenuHomePhabricator

Implement translatable edit summaries / multilingual comments using comment_data
Open, Stalled, MediumPublic8 Estimated Story Points

Description

Instead of copying Wikibase’s approach of constructing summaries with an autocomment like /* wbsetsitelink-add:1|frwiki */ and an autosummary containing the value, we want to use the comment_data field that’s available in the comment table thanks to T166732 to store the information we need to display a translated summary to the user in a structured way (JSON blob). The experience we gain here should be useful when using comment_data in Wikibase in the future (T215422).

Event Timeline

It turns out I slightly misunderstood the comment data field. While we can use it to store arbitrary JSON data, what we’re supposed to do (if I understand correctly) is pass a Message object into CommentStoreComment::newUnsavedComment(). The CommentStore will then take care of serializing and deserializing this Message, including its arguments, using the comment_data field, which we don’t use otherwise. (It even does this in a fashion that avoids conflicts with our own data, should we still have any, isn’t that nice?)

So while I did upload some proposed MediaWiki changes to hopefully increase the use of the comment data in MediaWiki ([attempted RecentChange support](https://gerrit.wikimedia.org/r/489741) and a hack to render messages in the user language), that’s not really necessary for us to use it: we can just start saving Messages with our CommentStoreComments right now.

$updater->saveRevision( CommentStoreComment::newUnsavedComment(
	$this->msg( 'wikibaseschema-edit-schema-custom-summary' ) // Edited schema; custom summary: $1
		->plaintextParams( $data['summary'] ?? '' )
) );

CommentStoreComment will render the message in the content language to set the comment text field, and the CommentStore will properly serialize the message on save (this part is already supported by MediaWiki). When the comment is loaded, at the moment the deserialized message will be discarded pretty quickly and only the comment text will be used (which means that the message will always be shown in the content language); however, this can be fixed in MediaWiki later (like my hack but done properly), at which point even old comments will magically be translated.

Thank you for your research! Starting to use that like you suggested seems to be a good idea 👍

When the comment is loaded, at the moment the deserialized message will be discarded pretty quickly and only the comment text will be used (which means that the message will always be shown in the content language); however, this can be fixed in MediaWiki later (like my hack but done properly), at which point even old comments will magically be translated.

In the meantime - is there a hook that lets us access the deserialized message? The documentation of the FormatAutocomments hook still feels very unclear to me.

I think the FormatAutocomments hook only comes into play later: that is only concerned with the comment text, and should run after the comment text has been generated from the comment data or message. I don’t think we can access the full comment object in there.

Change 490076 had a related patch set uploaded (by Michael Große; owner: Michael Große):
[mediawiki/extensions/WikibaseSchema@master] Add translatable message for created Schema in recent changes

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

Change 490311 had a related patch set uploaded (by Michael Große; owner: Michael Große):
[mediawiki/extensions/WikibaseSchema@master] Add translatable message for updated Schemas in recent changes

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

Change 490311 abandoned by Michael Große:
Add translatable message for updated Schemas in recent changes

Reason:
Has been incorporated by I1df7d55251c8381e3da8cc94cc670d2908fcc917

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