Page MenuHomePhabricator

Add web API caller to Scribunto
Closed, DuplicatePublicFeature

Description

Feature summary (what you would like to be able to do and where):
I would like to see a mw.API added to Scribunto, which would allow fetching data about pages and other stuff from other endpoints to Lua to handle when rendering the page.

For security reasons, the allowed API links can be restricted to those chosen by interface administrators and system administrators. This is to prevent malicious use of APIs to fetch malware to execute on the MediaWiki server.

Also, all calls with the web API caller would increment the expensive parser function count, including duplicate calls; after reaching the limit further calls would return an empty string.

The only calls that would be doable here are GET requests; any PUT, POST, or UPDATE requests cannot be done.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
Certain tasks such as getting all the categories in a page, getting channels in a Discord server, etc. require accessing the MediaWiki API to do this effectively. While some functions are effectively implemented in Lua for getting data (like title.exists), others remain missing for a long time.

Benefits (why should this be implemented?):
I see this as an interim solution for getting information about current MediaWiki pages until stuff like T50175 are properly implemented in Lua. In any case, this is a permanent solution for fetching data about other websites, including other wikis, other Discord servers, other tweets, etc., even if Wikimedia wikis might not use this, other wikis might still find this useful.

Event Timeline

I would like to note that it is already doable with External Data.

local tbl = mw.ext.externalData.getExternalData{ url = 'https://en.wikipedia.org/w/api.php?action=query&prop=categories&titles=Albert%20Einstein&format=json', data = { category = '$.query.pages.*.categories.*.title' } }