Template talk:ApiEx
Add topicUse plain spaces
[edit]Sure wish you used plain ASCII " " spaces. Wouldn't have to go nuts cleaning them up after each cut and paste to try out parts of them.
In fact perhaps any spaces at all is a barrier to people wanting to paste parts of them... Jidanni 20:46, 21 March 2009 (UTC)
- Yes, it's a pain. I mentioned converting spaces in the p1-p9 URL parameters to %20 in the template documentation. The template could/should escape spaces for you, but the invocation of the API in your own code might need URL escaping, so reminding readers that URL parameters may need escaping isn't harmful. -- SPage (WMF) (talk) 00:25, 25 February 2015 (UTC)
- OP was talking about spaces between the parameters, which was fixed over two years ago by replacing them with margins. --121.219.123.17 02:32, 25 February 2015 (UTC)
Mysterious post parameter ?
[edit]The explanation says
- post - a "list" of ApiEx/Post objects, to generate a post table
I don't understand that. It would be nice to have an example.
Do any pages use {{ApiEx/Post }}? API:Edit#Example doesn't use it, I would expect it to.
Thanks for working on this!
-- SPage (WMF) (talk) 22:20, 5 February 2015 (UTC)
Switch output to json
[edit]Now that API output is JSON by default, the examples should probably switch to
| result=<source lang="javascript">{ "query": { "pages": { ...
I did this already in API:Properties#Examples -- SPage (WMF) (talk) 22:24, 5 February 2015 (UTC)
- I don't disagree that we should start using JSON when we can, though there are a rather large number of examples to check (~250) and probably convert if we want to go back and do them all. – Robin Hood (talk) 06:21, 6 February 2015 (UTC)
Generate API output, bot or on-the-fly
[edit]When I clicked [Expand] I thought my browser was actually making the API request, but I believe a human manually pasted the output into the template's result
parameter.
That's predictable, but it means the examples drift out of date. Some ideas (also see phab:T88755):
- a bot could find instances of this template, run the query, and replace the source parameter with result. Downside is unpredictability, e.g. many would include
"warnings": { "query": { "*": "Formatting of continuation data will be changing soon. T...
- with some JavaScript support, when you click the API example it could actually run the query and display a result in a box. For bonus points it could let you tweak the parameters, similar to what the OOjs UI Living style guide is doing.
- the examples could have a link to Special:ApiSandbox, pre-populating its the fields for you.
-- SPage (WMF) (talk) 02:35, 7 February 2015 (UTC)
- Whether we do them on-the-fly or via a bot, the primary problem I see is the various non-query examples, almost all of which do something, and most of them require elevated permissions. I don't think you want a bot e-mailing something as it tries to generate an example for that, or in an on-the-fly scenario, have some prankster decide it would be fun to edit the API:Move example so that it moves a high-use template when clicked on. As to your point about warnings being included, I think most bots could strip those with relative ease. A little string parsing before processing would do the trick, or whatever methods are available with the bot's Json parser. – Robin Hood (talk) 07:00, 7 February 2015 (UTC)
Adding a link to [try in sandbox]
[edit]Special:ApiSandbox has a neat trick: if you take any api.php
query string, and add it as the "hash" or URL fragment #param1=val1¶m2=val2
on the end of Special:ApiSandbox, then the ApiSandbox form preloads with those parameters. For example
- https://en.wikipedia.org/w/api.php?action=query&prop=pageimages%7Cpageterms&titles=Albert%20Einstein
- https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&prop=pageimages%7Cpageterms&titles=Albert%20Einstein
I'm trying to add a [try in ApiSandbox] link to this template for phab:T89680. It's a useful hack that will encourage developers to play with our APIs in the Data and developer hub. My work in progress template modification is at User:SPage_(WMF)/ApiEx, demo/tests at User:SPage_(WMF)/APIExTest. I hope it's reliable enough to default to on. As usual, I'm not sure about i18n/localization.
-- SPage (WMF) (talk) 02:10, 27 March 2015 (UTC)
- My local change in User:SPage_(WMF)/ApiEx worked so I added the code to {{ApiEx }}. But it doesn't do anything! No matter if I purge the page or reload, I don't see [try in ApiSandbox]. I only see if it I remove the mysterious {{TNT}} in front, and trying to force
apisandbox=1
doesn't help. See tests at User:SPage_(WMF)/APIExTest So something needs updating for TNT to work this this, but I'm not sure how. Shirayuki, you are my only hope :) -- SPage (WMF) (talk) 10:22, 13 April 2015 (UTC)
- Nobody's changed anything that I can see, but "[try in ApiSandbox]" is appearing in {{TNT|ApiEx}} and {{TNTN|ApiEx}} now! I still welcome feedback. phab:T89229 is the related bug to add a similar link after example queries in generated API help. -- SPage (WMF) (talk) 10:00, 19 April 2015 (UTC)
- @SPage (WMF):
{{TNTN|ApiEx}}
returnsTemplate:ApiEx/en
. So any changes on Template:ApiEx should be applied to Template:ApiEx/en explicitly by a translation admin. See also the log. --Shirayuki (talk) 10:50, 19 April 2015 (UTC)
- @SPage (WMF):
Bug: <translate> tag appears around Result table heading (unless you use TNT)
[edit]Demonstration:
Result |
---|
dummy result |
This doesn't happen if you use translatable template, {{TNT|ApiEx|parameters ...result stuff}}, but it is distracting. User:Shirayuki, do you have any ideas?
-- SPage (WMF) (talk) 08:45, 8 April 2015 (UTC)
- For example, see Template:VisualEditor Portal. --Shirayuki (talk) 08:57, 8 April 2015 (UTC)
- I'm not sure what you mean. Are you saying Template:VisualEditor Portal's use of
#invoke:Template translation
avoids the unwanted <translate> <translate> markup appearing? SPage (WMF) (talk) 09:54, 13 April 2015 (UTC)- Yes. See also Template:VisualEditor Portal/core.
{{VisualEditor Portal}}
returns the suitable translation (e.g. Template:VisualEditor Portal/core/ja) and does not show the unwanted tags. --Shirayuki (talk) 11:42, 13 April 2015 (UTC)
- Yes. See also Template:VisualEditor Portal/core.
- I'm not sure what you mean. Are you saying Template:VisualEditor Portal's use of
Extra space after sandbox link
[edit]When using this template without a "Result" box, I'm seeing an extra <p> tag following the sandbox link. For example, API:Parsing_wikitext#GET_request. I assume this is happening due to the conditional logic that displays the Result box, but I wasn't able to fix it. Any ideas why this is happening? APaskulin (WMF) (talk) 18:59, 16 May 2022 (UTC)