Page MenuHomePhabricator

Allow extensions to specify a custom PARAM_TYPE
Open, Needs TriagePublic

Description

Problem
There is no way for an extension to implement a new PARAM_TYPE and therefor update the ApiSandbox to support that param type. For instance, if an extension wanted to create a json param type (that would allow JSON input) there would not be a way to do this (that I can find) and provide a custom input in the ApiSandbox (with codemirror, client and server-side validation, etc.)

Event Timeline

Anomie added a subscriber: Anomie.

I note that creating a new parameter type outside of core has many more requirements than just making it possible to create a widget in ApiSandbox. You'd also need to plug in to several places in the PHP code:

I note there's some patches working towards much of the above at https://gerrit.wikimedia.org/r/434717 and https://gerrit.wikimedia.org/r/434718.

As for ApiSandbox, we'd need some way for SpecialApiSandbox to load the extension's ResourceLoader module for extending ApiSandbox, and then probably use of mw.hook() from createWidgetForParameter() and possibly also ApiSandbox.PageLayout.prototype.makeWidgetFieldLayouts() to get that code called from the right places.

Does that make sense to you?

dbarratt renamed this task from Allow extensions to modify mw.special.ApiSandbox.Util.createWidgetForParameter() to Allow extensions to specify a custom PARAM_TYPE.Nov 21 2018, 5:28 PM
dbarratt updated the task description. (Show Details)

@Anomie yes it does, I've updated the description to be more broad in what I was trying to do. :)

For some background, I was working on T209133 and I initially created a special page (and a non-localized custom route). But then I was thinking it might be better if it was a module in the action API (which would allow different return formats, etc.).

However, the UX on the Sandbox would be sub-optimal as the only allowed field for the query (GraphQL schema) and the variables (JSON) would be a text field. Ideally, I'd like to be able to create a graphql param type that would use something like https://github.com/graphql/codemirror-graphql in the sandbox and the extension would validate the param value and ensure that it's valid.

Anyways, feels like there are probably more use-cases than the one I have, so I abstracted the description. Ideally the Action API would expose a param type system that any extension would plugin to.