Page MenuHomePhabricator

Investigate how to add translatable edit comment for creating a schema
Closed, ResolvedPublic

Description

Wikibase stores edit summaries/comments like /* wbcreateclaim-create:1 */ [[Property:P1]]: [[Q2]] and then renders them using interface messages when viewing the summary (on diff pages, histories, etc.). Are there any other extensions which provide translatable edit summaries in other ways? And if we want to go with Wikibase’s approach, how do we do that without completely depending on Wikibase?

Event Timeline

Lucas_Werkmeister_WMDE renamed this task from Investigate how to add translatable revision summary for creating a schema to Investigate how to add translatable edit comment for creating a schema.Jan 29 2019, 2:09 PM
Lucas_Werkmeister_WMDE triaged this task as Medium priority.
Lucas_Werkmeister_WMDE created this task.
Lucas_Werkmeister_WMDE updated the task description. (Show Details)

Investigation Result

This is done in Wikibase in \Wikibase\Lib\AutoCommentFormatter by using the FormatAutocomments hook.

Also, it seems like Wikibase is the only extension using that hook.

Besides its test, the AutoCommentFormatter is used only in ClientHooks.php and RepoHooks.php. Also, AutoCommentFormatter is not subclassed.

The comment in the database is created by \Wikibase\SummaryFormatter. This class is much more integrated into the rest of Wikibase and I'm unsure how suitable it is to be extracted.

Possible Ways to Proceed

  1. We could extract AutoCommentFormatter into a library and use it in WikibaseSchema.
  2. On the other hand, this is not much more than listening to the hook for our message string and replacing it with the message. So we could also keep this pretty simple.

While the current SummaryFormatter is integrated fairly closely to Wikibase, I feel like it would be possible to split it up into:

  • a generic SummaryFormatter class, where formatArg does little more than calling strval() on each message argument, and
  • a WikibaseSummaryFormatter, which extends SummaryFormatter and augments formatArg to correctly format arguments that are snaks, entity IDs, data values, etc.

To accommodate the hack in formatKeyValuePairs (“if the key looks like an entity ID, apply entity ID formatting”), a formatKey method could probably also be introduced, analogous to formatArg.

Then, I think we could extract a small package to handle automatically translated summaries (generate them with SummaryFormatter and display them with AutoCommentFormatter), and use a Wikibase-specific variant of that in Wikibase (i. ., WikibaseSummaryFormatter would stay in Wikibase) and the general variant for WikibaseSchema, because we don’t need support for entity ID arguments etc. there.

I was initially drawn towards just leaving the Wikibase thing and using the hook in our own way. (Option 1 from @Michael)

However, I can see this could be a useful package to exist separately although it is some more work.

I guess the plan would be something like:
a new usecase: "get schema history"
then a mediawiki presentation layer which uses the now extracted SummaryFormatter and the hook