Page MenuHomePhabricator

Create a [[Special:Api]] to allow access of the Api through alternate syntax
Closed, DeclinedPublic

Description

A slightly useful addition to MediaWiki would be a special page method of accessing the API.

Basically through a query where rather than /api.php?a=1&b=2&c=3 you could use /wiki/Special:Api/a=1/b=2/c=3.

There are two explanatory uses for a Api special page:

The first one deals with not knowing where the Api exists.

When programming an extension, a external tool, or such. The location of the script root is not always known, however we will know the Short Url form, and be able to access a special page, or article on the wiki. But the API is not as easily accessed, because we can't find the location of api.php, since we don't even know if the wiki is using /api.php or /w/api.php or if they have it in a complete different root.

Of course, this issue isn't that hard to step over with an external tool where we can query for that info, or just force the user to specify where it is.

However that's not the case with the second issue. Interwiki links:

Interwiki links always give us a format that we can use to point to a page on another wiki, it doesn't matter if they are in short or long form we can point to a special page on another wiki. However, even doing a bunch of parsing of urls, we won't always even know how to find an api.php on the other wiki, in fact using short urls, we'll never correctly know.

The addition of a [[Special:Api]] would allow for extensions to be able to grab an interwiki url, and then grab data on the wiki on the other side of that interwiki link. Various things like stats, WikiText, or namespace info needed for transwiki stuff could be grabbed and used in a variety of ways for an extension.


Version: unspecified
Severity: enhancement

Details

Reference
bz12905

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 10:05 PM
bzimport set Reference to bz12905.

API and other raw pages may be accessed only from main entry point

(In reply to comment #1)

API and other raw pages may be accessed only from main entry point

That doesn't mean we can't do an HTTP 302 to it, does it? (Please correct me if I'm wrong, which would mean IE is even more brain-damaged than I give it credit for. CCing to Brion to check.)

Anyway, added [[Special:API]] in r30537, which just HTTP redirects to api.php. Stuff like [[Special:API/action=query&list=allpages&aplimit=5]] also works.

Ya, redirect was one of my thoughts.

Though, actually the reason why I suggested the / separation, is because of the differences in short and long urls.

With that setup, this would work:
/wiki/Special:API/action=query&list=allpages&aplimit=5
As it would redirect to something like:
/api.php?action=query&list=allpages&aplimit=5

However, long urls offer up:
/index.php?title=Special:Api/action=query&list=allpages&aplimit=5
Which will actually redirect to:
/api.php?action=query
Because the & is considered part of the actual query. It's also not possible to externally detect things like that, because it's possible that someone may be using path to query rewrites which do have the & issue, but no ? exists in the url.

That's why I suggested the / separated format where all the /'s would be replaced with &'s and put into the query. Because it works universally no matter what the setup.

(In reply to comment #3)

Ya, redirect was one of my thoughts.

Though, actually the reason why I suggested the / separation, is because of the
differences in short and long urls.

With that setup, this would work:
/wiki/Special:API/action=query&list=allpages&aplimit=5
As it would redirect to something like:
/api.php?action=query&list=allpages&aplimit=5

However, long urls offer up:
/index.php?title=Special:Api/action=query&list=allpages&aplimit=5
Which will actually redirect to:
/api.php?action=query
Because the & is considered part of the actual query. It's also not possible to
externally detect things like that, because it's possible that someone may be
using path to query rewrites which do have the & issue, but no ? exists in the
url.

That's why I suggested the / separated format where all the /'s would be
replaced with &'s and put into the query. Because it works universally no
matter what the setup.

Slashes are also bad, because pagenames can contain slashes. Then again, they can also contain ampersands. It should be noted that ampersands did work when urlencoded.

Anyway, that's all moot now, because Brion reverted my commit. The path to api.php can be gotten quite easily through other means (like grabbing the wgScriptPath variable through JavaScript and appending /api.php).