Page MenuHomePhabricator

Implement translatable edit summaries / multilingual comments using comment_data
Open, Stalled, NormalPublic8 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

Lucas_Werkmeister_WMDE triaged this task as Normal priority.Feb 8 2019, 5:47 PM
Lucas_Werkmeister_WMDE created this task.

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 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

Lucas_Werkmeister_WMDE set the point value for this task to 8.Feb 25 2019, 2:11 PM
JTannerWMF moved this task from Inbox to External on the Growth-Team board.Mar 19 2019, 6:20 PM