Page MenuHomePhabricator

Define the wikifunctions API that Parsoid needs
Open, Needs TriagePublic

Description

Parsoid needs the wikifunctions API to support these capabilities:

  • Issue batch precompute requests for a set of wikifunction calls ( T373252 ) - the API should specify the request format. Parsoid doesn't expect any response for these calls
  • Issue a batch request for a set of wikifunction calls - the API should specify the request and response format. The API might need to support a query param that lets Parsoid specify a max latency within which it expects a response. For individual calls in the batch where the result may not be available with the requested latency, Parsoid will inject a placeholder. We need to work out whether Wikifunctions will return a timeout response for such calls, or return a custom placeholder.

For each of these requirements, dependent subtasks will be filed for the API endpoints.

Event Timeline

I was going to propose that the API was a hook, so the "request and response format" is just the method parameters and return value for hook.

Back from the original spec, I was thinking something of the format of FragmentProvider::renderFragmentFromWikitext( string $input ): ?ParserOutput and FragmentProvider::renderFragmentsFromWikitext( string[] $inputs ): ?ParserOutput[] (or if it must be a hook, onRenderFragmentFromWikitext( string $input ) etc.? Though that's rather bare-bones and makes it hard to distinguish errors from timeouts from not-ready-yet statuses, and doesn't specify latency/etc.

My proposal replaces the string in your hook with a FragmentType object; WIP is at https://gerrit.wikimedia.org/r/c/mediawiki/services/parsoid/+/821282. That will eventually allow for nested invocations. Right now ParserOutput is the way we write "fragment plus metadata", although the "fragment" part (as opposed to the "HTML string") is WIP. So:

FragmentProvider::renderFragmentFromWikitext( FragmentType[] $arguments ): ParserOutput|Placeholder

The `Placeholder' might be a singleton for now, but might eventually be a place to store the expected time until the value is ready (ie cache ttl) and/or a UUID that lets the fragment provider call back when the fragment is ready, etc.

LGTM. In discussion yesterday, Subbu, Arlo and I thought that we might want to return in the "not ready yet" / placeholder concept some meta-data for the parser about how long to expect to wait before trying again (for WF, ~5 seconds; for TimedMediaHandler, maybe ~60mins).