Page MenuHomePhabricator

Reading List REST Interface: improve title handling in /lists/pages/{project}/{title}
Open, LowPublic

Description

Summary: add title handling to the MW REST Reading Lists /lists/pages/{project}/{title} endpoint equivalent to the existing RESTBase normalization

Details:

The /lists/pages/{project}/{title} endpoint accepts a "title" parameter. The new MW REST Reading Lists endpoints, and the existing Action API Reading Lists endpoints, treat this parameter strictly as a string. Titles with invalid characters do not cause an error. Instead, the endpoints return a 200. (And a presumably empty results list, as a list should never be able to contain an entry with an invalid title.)

However, the existing production /lists/pages/{project}/{title}, which is implemented in RESTBase and forwards calls to the Action API, will return a 400

Here is an example Action API call containing an invalid title, which returns 200 (and an empty list):
https://en.wikipedia.org/w/api.php?action=query&format=json&meta=readinglists&formatversion=2&rlproject=en.wikipedia.org&rltitle=Cheese|

Here is the equivalent RESTBase call, which returns 400:
https://en.wikipedia.org/api/rest_v1/data/lists/pages/https%3A%2F%2Fen.wikipedia.org/Cheese%7C

Error body for the RESTBase call is:

{
"type": "https://mediawiki.org/wiki/HyperSwitch/errors/bad_request",
"method": "get",
"detail": "title-invalid-characters",
"uri": "/en.wikipedia.org/v1/data/lists/pages/https%3A%2F%2Fen.wikipedia.org/Cheese%7C"
}

To execute that, you'd need reading lists to be set up for your user to execute the Action API version of that call. This can be done via the WMF mobile app, or via the API Sandbox using a url like this:
https://en.wikipedia.org/w/api.php?action=readinglists&format=json&command=setup&token=redacted&formatversion=2

You'd want to actually execute that in the sandbox, as it has to be POSTed with a valid token.

The reason the RESTBase endpoint gives an error while the Action API one does not is that RESTBase is performing title normalization via normalize_title_filter.js.

The new MW REST endpoints are currently validating titles on entry creation here, using the same technique as the Action API entry creation endpoint. Hopefully, we can use similar code as part of the changes for this task. However, the RESTBase code says it normalizes the title, which implies that it might, at least in some circumstances, modify a nonconforming title for use without returning an error. The MW REST endpoint does not do that. So we should evaluate what the RESTBase code actually does and consider normalization vs validation.

None of this is likely a major issue for the mobile apps, which I suspect (but have not confirmed) will probably not allow users to submit a request with an invalid title in the first place. And even if that could occur, I suspect the mobile apps would not have trouble processing an empty results list.