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.

expandtemplates[edit | edit source]

MediaWiki version: = 1.12

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

Parameters[edit | edit source]

  • text: Wikitext to preprocess
  • title: Act like the wikitext is on the page specified (default: API)
    • This only really matters when parsing links to the page itself or links to subpages, or when using magic words like {{PAGENAME}}.

Example[edit | edit source]

Expand wikitext {{Project:Sandbox}}

Possible errors[edit | edit source]

None.

parse[edit | edit source]

MediaWiki version: = 1.12

Returns parsed wikitext

Parameters[edit | edit source]

  • disablepp – Disable the PP Report from the parser output. Type: bool
  • oldid – Parse the content of this revision. Overrides page and pageid. Type: string
  • onlypst – Only do a pre-save transform (PST) on the input, don't parse it. Type: bool
    Returns the same wikitext, after a PST has been applied. Ignored if page, pageid or oldid is used. Type: bool
  • page – Parse the content of this page. Cannot be used together with text and title. Type: string
  • pageid – Parse the content of this page. Overrides page. Type: string
  • prop – Which pieces of information to get. A pipe character | separated list containing one or more of the following options:
    • text – Gives the parsed text of the wikitext.
    • langlinks – Gives the langlinks the parsed wikitext.
    • categories – Gives the categories of the parsed wikitext.
    • categorieshtml – Gives the html version of the categories.
    • languageshtml – Gives the html version of the languagelinks.
    • links – Gives the internal links in the parsed wikitext.
    • templates – Gives the templates in the parsed wikitext.
    • images – Gives the images in the parsed wikitext.
    • externallinks – Gives the external links in the parsed wikitext.
    • sections – Gives the sections in the parsed wikitext (TOC, table of contents).
    • revid – If page was used, specify the ID of the revision parsed.
    • displaytitle – Adds the title of the parsed wikitext.
    • headitems – Gives items to put in the <head> of the page.
    • headhtml – Gives parsed <head> of the page.
    • iwlinks – Gives interwiki links in the parsed wikitext.
NOTE: Section tree is only generated if there are more than 4 sections, if the __TOC__ keyword is present, or if sections is explicitly requested and the page contains headings/sub-headings (overrides __NOTOC__).
Type: string
  • pst – Do a pre-save transform (PST) on the input before parsing it (makes {{subst:}} work properly, expands tildes to signatures, etc.). Ignored if page, pageid or oldid is used. Type: bool
  • redirects – If the page parameter is set to a redirect, resolve it. Type: bool
  • section – Only retrieve the content of this section number. Type: string
  • sections – Retrieve the page's TOC (if any exists). Type: string
  • summary – Summary to parse. Type: string
  • text – Wikitext to parse. Type: string
  • title – Act like the wikitext is on this page (default: API). Type: string
    This only really matters when parsing links to the page itself or subpages, or when using magic words like {{PAGENAME}}.
  • uselang – The language code ("en" for English, "fr" for French, etc.) of the language in which the text or the page should be parsed. Type: string
    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.

Example[edit | edit source]

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

Possible errors[edit | edit source]

  • missingrev – There is no revision ID oldid
  • missingtitle – The page you specified doesn't exist
  • nosuchpageid – There is no page with ID $1
  • nosuchsection – There is no section sectionnumber in page
  • params – The page parameter cannot be used together with the text and title parameters
  • permissiondenied – You don't have permission to view deleted revisions
  • readapidenied – You need read permission to use this module

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.