Page MenuHomePhabricator

Cleanup getRouteUrl() for module-based Handlers
Closed, ResolvedPublic1 Estimated Story Points

Description

I noticed a little gotcha while making a wikibase.v1 module at https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/1273300. The Handler::getPath() method is relative to the module base path, but I see that getRouteUrl() uses getPath() as the $routeWithModulePrefix argument, which seems like a contradiction...which looks wrong. Any redirect based logic using getRouteUrl() seems like it will be broken.

This seemed to cause the redirect CI failures.

I think there should be a getFullPath() method for use by getRouteUrl(). Looking at what uses getPath(), it seems like they want they want the prefixed path (except for getSupportedPathParams, which could use either but may as well use the unprefixed one). Maybe it would make more sense for getPath() to have the prefix and have a getRelativePath() method for unprefixed paths.

Event Timeline

See T419147: Attribution API: Redirects move to the wrong REST url/endpoint and T420669: REST: Improve PageRedirectHelper path behavior for use in REST modules.

In the latter, I said:

In fact, I'm concerned that moving the Wikidata REST endpoints into a module without doing so will cause bugs

And then I promptly got distracted and forgot all about this. Sorry.

I suggested similar things as you. The change we made to fix AttributionApi means that modifying getPath() will break that code. So I'm inclined to add getFullPath() and leave getPath() alone. That's probably safer to prevent surprised third party breakage as well, on the unlikely chance that someone somewhere is using this in their private wiki.

How does that sound to you?

I suggested similar things as you. The change we made to fix AttributionApi means that modifying getPath() will break that code. So I'm inclined to add getFullPath() and leave getPath() alone. That's probably safer to prevent surprised third party breakage as well, on the unlikely chance that someone somewhere is using this in their private wiki.

How does that sound to you?

Sound good. Would you update getRouteUrl() or add a getRouteFullUrl()? At a glance, I learn toward the former since getRouteUrl() prepends the router's base URL, which seems like it would be nonsense without the module prefix in $path.

Change #1276099 had a related patch set uploaded (by Aaron Schulz; author: Aaron Schulz):

[mediawiki/core@master] rest: fix Handler::getRouteUrl() for module-based Handler instances

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

Change #1276099 merged by jenkins-bot:

[mediawiki/core@master] rest: fix Handler::getRouteUrl() for module-based Handler instances

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