Difference between revisions of "Template:ApiEx"

From RobotX
Jump to navigation Jump to search
m (Text replacement - "<translate>" to "")
m (Text replacement - "{{#translation:}}" to "")
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
<languages/>
+
 
</noinclude><includeonly>{{#switch:</translate>
+
</noinclude><includeonly>{{#switch:
 
| =
 
| =
 
{{{desc|}}}
 
{{{desc|}}}
Line 40: Line 40:
 
-->{{#if:{{{p8|}}}|&{{{p8}}}}}<!--
 
-->{{#if:{{{p8|}}}|&{{{p8}}}}}<!--
 
-->{{#if:{{{p9|}}}|&{{{p9}}}}}<!--
 
-->{{#if:{{{p9|}}}|&{{{p9}}}}}<!--
--> &#x5b;<!--T:8--> try in ApiSandbox</translate>&#x5d;]}}<!--
+
--> &#x5b; try in ApiSandbox&#x5d;]}}<!--
 
--></div><!--
 
--></div><!--
-->{{#if:{{{post|}}}|{{#ifeq:{{{collapse|}}}|no||{{collapse top|<!--T:7--> Result</translate>}}}}
+
-->{{#if:{{{post|}}}|{{#ifeq:{{{collapse|}}}|no||{{collapse top| Result}}}}
 
<table style="text-align:{{dir|{{pagelang}}|right|left}}; width:100%; margin:0.5em 0.2em; border-{{dir|{{pagelang}}|right|left}}:3px solid red">
 
<table style="text-align:{{dir|{{pagelang}}|right|left}}; width:100%; margin:0.5em 0.2em; border-{{dir|{{pagelang}}|right|left}}:3px solid red">
 
<tr>
 
<tr>
<td colspan="4" style="font-weight: bold; border-bottom: 1px solid gray;"><!--T:1--> Post parameters</translate></td>
+
<td colspan="4" style="font-weight: bold; border-bottom: 1px solid gray;"> Post parameters</td>
 
</tr><tr style="font-weight: bolder;">
 
</tr><tr style="font-weight: bolder;">
<th style="width: 20%;"><!--T:2--> Parameter name</translate></th>
+
<th style="width: 20%;"> Parameter name</th>
<th style="width: 20%;"><!--T:3--> Value</translate></th>
+
<th style="width: 20%;"> Value</th>
<th style="width: 20%;"><!--T:4--> Default</translate></th>
+
<th style="width: 20%;"> Default</th>
<th style="width: 40%;"><!--T:5--> Comment</translate></th>
+
<th style="width: 40%;"> Comment</th>
 
</tr>
 
</tr>
 
{{{post|}}}
 
{{{post|}}}
 
</table>
 
</table>
|{{#if:{{{result|}}}|{{#ifeq:{{{collapse|}}}|no||{{collapse top|<!--T:6--> Result</translate>|extrastyle=overflow:auto;}}}}}}
+
|{{#if:{{{result|}}}|{{#ifeq:{{{collapse|}}}|no||{{collapse top| Result|extrastyle=overflow:auto;}}}}}}
 
}}
 
}}
 
{{{result|}}}
 
{{{result|}}}
Line 62: Line 62:
 
}}</includeonly><noinclude>
 
}}</includeonly><noinclude>
 
{{documentation}}
 
{{documentation}}
[[Category:API templates{{#translation:}}]]
+
[[Category:API templates]]
 
</noinclude>
 
</noinclude>

Latest revision as of 15:32, 21 December 2019


Template documentation[view] [edit] [history] [purge]

Use this template on API documentation pages to format an example API request.

Note as an alternative, {{Api help}} transcludes localized API documentation generated from source code which normally has API examples in it.

User:SPage (WMF)/ApiEx utility creates a {{ApiEx}} template invocation if you paste an api.php URL into it.

Usage

{{ApiEx
| desc=Capitalization, localization, "_" => " ", "Project" => "Wikipedia", ...
| p1=action=query
| p2=titles=Project:articleA{{!}}article_B
| result=<source lang="xml">
<api>
  <query>
    <normalized>
      <n from="Project:articleA" to="Wikipedia:ArticleA" />
      <n from="article_B" to="Article B" />
    </normalized>
    <pages>
      <page ns="4" title="Wikipedia:ArticleA" missing="" />
      <page ns="0" title="Article B" missing="" />
    </pages>
  </query>
</api>
</source>
}}

Parameters

  • desc - API request description
  • lang - two-letter code for the wiki language. 'en' by default.
  • site - full URL of site to use in example (e.g., www.mediawiki.org). Overrides lang parameter.
  • p1-p9 - parameter groups, each containing either one param=value pair or multiple pairs each separated by an ampersand (&), e.g. p3=param=value&paramB=valueBbbb).
  • result - the result of the query execution. Add the template, preview, click the api.php link, and copy and paste the API response into the template as
    | result=<source lang="javascript">PASTE RESPONSE HERE</source>
  • post - a "list" of {{ApiEx/Post}} objects, to generate a post table
  • collapse - set to "no" to stop "result" and "post" sections from being collapsed with {{Collapse top}}/{{Collapse bottom}}
  • apisandbox - whether to show a "[try in ApiSandbox]" link that loads the example API query parameters into Special:ApiSandbox. Default is 1, add | apisandbox=0 to not show this link.

Notes

  • This template outputs a wikitext link. Any spaces in the URL parameters p1...p9 will garble the link, so change them to %20.
  • Similarly, any pipe-separate values in the URL parameters such as a group of pages "title1|title2" must be escaped, so use the {{!}} magic word.

Example

Capitalization, localization, "_" => " ", "Project" => "Wikipedia", ...