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).
|Resolved||Lydia_Pintscher||T212564 create Schema entity|
|Resolved||None||T213724 Add schema creations to recent changes|
|Stalled||Lucas_Werkmeister_WMDE||T215637 Implement translatable edit summaries / multilingual comments using comment_data|
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.
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.