API:Parsing wikitext

From MediaWiki.org

Jump to: navigation, search
This page is part of the MediaWiki API documentation.
MediaWiki API


These API modules allow calling the parser for preprocessing and rendering.

Retrieving just the raw source wikitext can be done through prop=revisions.

Contents

[edit] expandtemplates

MediaWiki version: 1.12

Returns preprocessed wikitext (comments stripped, templates expanded, etc.)

[edit] Parameters

  • text: Wikitext to preprocess
  • title: Act like the wikitext is on this page (default: API)
    • This only really matters when parsing links to self (like this) or links to subpages.

[edit] Example

Expand wikitext {{Project:Sandbox}}

api.php ? action=expandtemplates & text=%7B%7BProject:Sandbox%7D%7D

<?xml version="1.0" encoding="utf-8"?>
<api>
  <expandtemplates>
{| style=&quot;background-color: transparent; border:1px dotted #000000;padding:2px;margin:2px;&quot;
| ''Welcome to the '''Wikipedia Sandbox'''! This page allows you to carry out experiments. To edit, click &lt;span class=&quot;plainlinks&quot;&gt;'''[http://en.wikipedia.org/w/index.php?title=API&amp;action=edit here]'''&lt;/span&gt; or '''edit this page''' above (or the views section for obscure browsers), make your changes and click the '''Save page''' button when finished. Content will '''not''' stay permanently; this page is '''automatically cleaned''' every 12 hours, although it tends to be overwritten by other testing users much faster than that.''
 
''Please do not place copyrighted, offensive, or libelous content in the sandbox(es). If you have any questions regarding [[Wikipedia]], please see [[Wikipedia:Questions]]. Thanks!''
 
:''This page is a virtual sandbox on Wikipedia. For uses of sandboxes, see the article [[sandbox]].
 
''You may also use the templates''
&lt;font style=&quot;font-size: 12px;&quot;&gt;
[[Template:X1|X1]], [[Template:X2|X2]], [[Template:X3|X3]], [[Template:X4|X4]], [[Template:X5|X5]], [[Template:X6|X6]], [[Template:X7|X7]], [[Template:X8|X8]], and [[Template:X9|X9]]&lt;/font&gt;
for experimental purposes.&lt;br /&gt;
 
''Try other sandboxes:'' &lt;font style=&quot;font-size: 12px;&quot;&gt;[[Wikipedia:Sandbox|Main Sandbox]] | [[Wikipedia:Tutorial (Editing)/sandbox|Tutorial Sandbox 1]] | [[Wikipedia:Tutorial (Formatting)/sandbox|Tutorial Sandbox 2]] | [[Wikipedia:Tutorial (Wikipedia links)/sandbox|Tutorial Sandbox 3]] | [[Wikipedia:Tutorial (Related site links)/sandbox|Tutorial Sandbox 4]] | [[Wikipedia:Tutorial (External links)/sandbox|Tutorial Sandbox 5]]&lt;/font&gt;&lt;br&gt;''For a sandbox of your own, [[Wikipedia:User page#How do I create a user subpage?|create a user subpage]].''
|
{| style=&quot;background-color: transparent;&quot;
|-
|&lt;table class=&quot;noprint Template-Shortcut&quot; style=&quot;border:1px solid #999; background:#fff; margin: .3em .3em .3em 1em; padding:3px; float:right&quot;&gt;&lt;th class=&quot;noprint&quot; align=&quot;center&quot; valign=&quot;top&quot;&gt;&lt;small&gt;[[Wikipedia:Shortcut|Shortcuts]]:&lt;br /&gt;[[WP:SB]]&lt;br /&gt;[[WP:SAND]]&lt;br /&gt;[[WP:SANDBOX]]&lt;br /&gt;[[WP:TEST]]&lt;/small&gt;&lt;/th&gt;&lt;/table&gt;
|-
|&lt;div style=&quot;border: 1px solid black; text-align: center; padding:5px; font-size: small; background: #eeeeee; white-space: nowrap;&quot;&gt;
More info:&lt;br&gt;
[[Wikipedia:Introduction|Introduction to Wikipedia]]&lt;br&gt;
[[Wikipedia:About the Sandbox|About the Sandbox]]&lt;br&gt;
[[Wikipedia:Tutorial|Editing tutorial]]&lt;/div&gt;
|}
|}
&lt;/sub&gt;
 
 
 
This is a test</expandtemplates>
</api>

[edit] Possible errors

None.

[edit] parse

MediaWiki version: 1.12

Returns parsed wikitext

[edit] Parameters

  • text: Wikitext to parse
  • title: Act like the wikitext is on this page (default: API)
    • This only really matters when parsing links to self (like this) or links to subpages.
  • page: Parse the content of this page. Cannot be used together with text or title
  • prop: Which properties to get (all by default)
    • text: The generated HTML
    • langlinks: A list of language links in the wikitext fragment
    • categories: A list of category links in the wikitext fragment
    • links: A list of internal links in the wikitext fragment
    • templates: A list of templates used in the wikitext fragment
    • images: A list of images used in the wikitext fragment
    • externallinks: A list of external links used in the wikitext fragment
    • sections: A list of sections present in the wikitext fragment
    • revid: If page was used, specify the ID of the revision parsed

[edit] Example

Parse wikitext [[foo]] [[API:Query|bar]] [http://www.example.com/ baz]

api.php ? action=parse & text=%5B%5Bfoo%5D%5D%20%5B%5BAPI:Query|bar%5D%5D%20%5Bhttp://www.example.com/%20baz%5D

<?xml version="1.0" encoding="utf-8"?>
<api>
  <parse>
    <text>&lt;p&gt;&lt;a href=&quot;/wiki/Foo&quot; title=&quot;Foo&quot;&gt;foo&lt;/a&gt; &lt;a href=&quot;/w/index.php?title=API:Query&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;API:Query (page does not exist)&quot;&gt;bar&lt;/a&gt; &lt;a href=&quot;http://www.example.com/&quot; class=&quot;external text&quot; title=&quot;http://www.example.com/&quot; rel=&quot;nofollow&quot;&gt;baz&lt;/a&gt;
&lt;/p&gt;</text>
    <langlinks />
    <categories />
    <links>
      <pl ns="0" exists="">Foo</pl>
      <pl ns="0">API:Query</pl>
    </links>
    <templates />
    <images />
    <externallinks>
      <el>http://www.example.com/</el>
    </externallinks>
    <sections />
  </parse>
</api>

[edit] Possible errors

  • code: params
    • info: The page parameter cannot be used together with the text and title parameters
  • code: missingtitle
    • info: The page you specified doesn't exist
Personal tools