T425499: Create a REST endpoint solution for "imageinfo" added a parallel imageinfo REST endpoint to the CommonsMetadata extension (GET /commonsmetadata/{version}/file/{title}/imageinfo). That work makes a structured, cacheable alternative to action=query&prop=imageinfo available for single-file lookups. This task is for the work to make InstantCommons use that endpoint instead of the Action API for better cacheability, rate limiting, and error handling.
The action API path used by ForeignAPIRepo / ForeignAPIFile for InstantCommons lookups has two drawbacks compared to a dedicated REST endpoint:
- Cacheability: action API responses carry Vary: Cookie and are harder to cache at the CDN layer; a plain REST GET on a public endpoint is fully cacheable.
- Error handling: REST status codes map cleanly to HTTP errors; the action API tunnels errors inside a 200 response, requiring extra parsing.
Implementation
The work in T425499: Create a REST endpoint solution for "imageinfo" verifies that there is a parallel REST endpoint for imageinfo details that is detail-complete to what InstantCommons expects. While the output includes all needed information, we want to not have regressions in terms of how the operation is being handled today (with Action API) so Core's functionality will fetch from the REST endpoint if it is set up and exists, and then convert the response data to mimic the shape that arrives from imageinfo action API so the rest of the code can remain untouched in the way it handles the operations.
For this to work, we've added three keys to the $wgForeignFileRepos config to change its behavior conditionally to use the REST API:
restapiurl => https://commons.wikimedia.org/w/rest.php
restapiversion => v0-beta
restapiimageinfopath => /commonsmetadata/{version}/file/{title}/imageinfoThe version value is intentionally config-driven so upgrading from v0-beta to v1 (or any future version) requires only a config change.
Fallback
Fallback to action API is automatic on any fetch failure, ensuring no regression for existing deployments or repos that don't expose the endpoint.