Page MenuHomePhabricator

Implement PHP service to format references
Closed, ResolvedPublic

Description

Input: a single Reference (already deserialized); output: a Wikitext string. (“Service” probably means something like “an interface, a class implementing it which gets other ‘services’ as constructor parameters, and a getter on WikibaseClient”.)

This service might live in Lib or Client; that probably depends on the other services it gets injected. If Lib is possible, we would prefer that.

The reference style is not part of this interface; for now, we only support a single style anyways.

Event Timeline

To separate the formatted reference values, this will probably need a message similar to our current wikibase-client-data-bridge-reference-snak-separator, but under a message key that’s not Bridge-specific. We could rename that message, or drop it (currently there are no translations for it) and recreate it separately. Maybe quickly discuss this with TranslateWiki.net folks.

Change 579276 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] WIP: Add ReferenceFormatter service

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

“Service” probably means something like “an interface, a class implementing it which gets other ‘services’ as constructor parameters, and a getter on WikibaseClient”.

I looked a bit into this. What I had in mind was the standard lazily initialized service pattern that you see all over WikibaseClient and WikibaseRepo:

private $dataBridgeReferenceFormatter = null;

public function getDataBridgeReferenceFormatter() {
	if ( $this->dataBridgeReferenceFormatter === null ) {
		 $this->dataBridgeReferenceFormatter = new DataBridgeReferenceFormatter( ... );
	}
	return $this->dataBridgeReferenceFormatter;
}

But I don’t think this works out directly – the DataBridgeReferenceFormatter needs a SnakFormatter and a MessageLocalizer injected, and both of these depend on a request context. I think the usual solution to that in Wikibase is to make the lazily initialized service a factory (e. g. WikibaseClient::getSnakFormatterFactory(), WikibaseClient::getDataAccessSnakFormatterFactory()), and that factory then has a method to create a new instance of the actual service given the request context (language etc.). I think that’s a good solution for our case here as well – we can even call the factory a more general ReferenceFormatterFactory, for now only with a method newDataBridgeReferenceFormatter() but anticipating that the same factory could in future create formatters for other styles as well (thus avoiding cluttering WikibaseClient itself with one field+getter per style).

Change 580369 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] Add ReferenceFormatterFactory

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

Change 579276 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Add ReferenceFormatter service

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

Change 580369 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Add ReferenceFormatterFactory

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