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).
|mediawiki/extensions/WikibaseSchema||master||+7 -3||Add translatable message for updated Schemas in recent changes|
|Resolved||Lydia_Pintscher||T212564 create Schema entity|
|Resolved||None||T213724 Add schema creations to recent changes|
|Stalled||None||T215637 Implement translatable edit summaries / multilingual comments using comment_data|
- Mentioned In
- T323875: Turn edit summary hashtags into change tags
T318010: Improved edit summary data in mediawiki_history
T297464: Decide on the UX design for the edit summary
T218889: [Epic] Create translatable edit summaries using FormatAutocomments hook
- Mentioned Here
- T166732: Refactor comment storage in the database and abstract access in MediaWiki
T215422: Migrate Wikibase to use comment_data field instead of SummaryFormatter
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.
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.