API:Parsing wikitext

From MediaWiki.org
Jump to: navigation, search
Tools clipart.png This page is part of the MediaWiki API documentation.
Language: English  • Deutsch • español • 日本語
MediaWiki API

Quick overview:

v · d · e

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 the page itself or links to subpages, or when using magic words like {{PAGENAME}}.

[edit] Example

Expand wikitext {{Project:Sandbox}}

[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 the page itself or links to subpages, or when using magic words like {{PAGENAME}}.
    If you are interested in simply getting the rendered content of a page, you can bypass the api and simply add action=render to your url, like so: /w/index.php?title=API:Parsing_wikitext&action=render. However, this method has been deprecated, using the Parse API is better. More info here.
  • 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
  • pst: Do a pre-save-transform (makes {{subst:}} work properly, expands tildes to signatures, etc.)
  • uselang: The language code ("uselang=en" for English, "uselang=fr" for French, and so on) of the language in which the text or the page should be parsed.
    This is useful for language-dependent content, such as generated by the {{LangSwitch}} template at the Commons, or generally by things dependent on {{int:Lang}}. Prior to MediaWiki 1.17, this worked by accident; since 1.17, it works by design.

[edit] Example

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

[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.

Note: missingtitle is returned only for syntactically invalid page titles (eg. empty). Trying to fetching a missing page will return the rendered HTML of the "page missing" notice, not an error. However, you can check the revid attribute of <param>, which will always be "0" for missing pages.