API:Parsing wikitext
Language: | English • Deutsch • español • 日本語 • 中文 |
---|
This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
parse | ||
---|---|---|
This module cannot be used as a Generator . |
||
Prefix | ||
Required rights | none | |
Post only? | No | |
Generated help | Current | |
Version added |
|
Returns parsed wikitext. Partly overlaps with the functionality provided by Expandtemplates. Retrieving just the raw source wikitext can be done through prop=revisions. Extension:TextExtracts provides additional APIs.
Parameters[edit]
The uselang
parameter from the main module is also useful with Parse to localize various items. Please see that page for details. Note: MediaWiki wikis include several other parameters for this module which are added by extensions. They are not documented here.
title
: Act like the wikitext is on this page. Note: This only really matters when parsing links to the page itself or subpages, or when using magic words like{{PAGENAME}}
. Type: string (Default:API
.)text
: Wikitext to parse. Type: stringsummary
: Summary to parse. Type: string 1.16+page
: Parse the content of this page. Cannot be used together withtext
andtitle
. Type: stringpageid
: Parse the content of this page. Overridespage
. Type: integer 1.17+redirects
: If thepage
parameter is set to a redirect, resolve it. Type: bool 1.14+oldid
: Parse the content of this revision. Overridespage
andpageid
. Type: integer 1.13+prop
: Which pieces of information to get. A pipe character|
separated list containing one or more of the following options: (Default:text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle|iwlinks|properties
)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. 1.17+languageshtml
: Gives the html version of the language links. 1.17+ (deprecated in 1.23) (removed in 1.24)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
: Ifpage
was used, specify the ID of the revision parsed. 1.13+displaytitle
: Adds the title of the parsed wikitext. 1.15+headitems
: Gives items to put in the <head> of the page. 1.16+ (deprecated in 1.28)headhtml
: Gives parsed <head> of the page. 1.16+modules
: Gives the ResourceLoader modules used on the page. To load, usemw.loader.using()
. Either jsconfigvars or encodedjsconfigvars must be requested jointly with modules. 1.24+jsconfigvars
: Gives the JavaScript configuration variables specific to the page. To apply, usemw.config.set()
. 1.26+encodedjsconfigvars
: Gives the JavaScript configuration variables specific to the page as a JSON string. 1.26+indicators
: Gives the HTML of page status indicators used on the page. 1.25+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 ifsections
is explicitly requested and the page contains headings/sub-headings (overrides __NOTOC__). Type: string 1.17+wikitext
: Gives the original wikitext that was parsed. 1.17+properties
: Gives various properties defined in the parsed wikitext. 1.20+limitreportdata
: Gives the limit report in a structured way. Gives no data, when disablepp is set. 1.23+limitreporthtml
: Gives the html version of the PP report. Returns empty ifdisablepp
is true. 1.23+parsetree
: Gives the XML parse tree of revision content (requires contentmodel=wikitext). 1.26+
pst
: Do a pre-save transform (PST) on the input before parsing it (makes{{subst:}}
work properly, expands tildes to signatures, etc.). Ignored ifpage
,pageid
oroldid
is used. Type: bool 1.14+onlypst
: Only do a pre-save transform (PST) on the input, don't parse it. Returns the same wikitext, after a PST has been applied. Ignored ifpage
,pageid
oroldid
is used. Type: bool 1.14+effectivelanglinks
: Includes language links supplied by extensions (for use with prop=langlinks). Type: bool 1.22+section
: Only retrieve the content of this section number. When the value isnew
adds a new section, but then requires thetext
param. Type: string 1.17+sectiontitle
: The title for the new section Type: string 1.25+disablepp
: Replaced bydisablelimitreport
. Type: bool 1.17+ (deprecated in 1.26)disablelimitreport
: Omit the limit report ("NewPP limit report") from the parser output. Type: bool 1.26+disableeditsection
: Disable edit section links from the parser output. Type: bool 1.24+disabletidy
: Do not run HTML cleanup (e.g. tidy) on the parser output. Type: bool 1.26+generatexml
: Generate the XML parse tree (requires contentmodel=wikitext). Useprop=parsetree
instead. Type: bool 1.20+ (deprecated in 1.26)preview
: Parse in preview mode. Type: bool 1.22+sectionpreview
: Parse in section preview mode (enables preview mode too). Type: bool 1.22+disabletoc
: Disable table of contents in output. Type: bool 1.23+contentformat
: Content serialization format used for the input text. Only valid when used with text. One value: text/x-wiki, text/javascript, application/json, text/css, text/plain. 1.21+contentmodel
: Content model of the input text. Only valid when used with text. Possible values:wikitext
,javascript
,css
,text
,json
. (Default: model of the specified title, orwikitext
if title is not specified) 1.21+
Example[edit]
Parse wikitext: [[foo]] [[API:Query|bar]] [http://www.example.com/ baz]
Result |
---|
{
"parse": {
"title": "API",
"text": {
"*": "<p><a href=\"/wiki/Foo\" title=\"Foo\" class=\"mw-redirect\">foo</a> <a href=\"/w/index.php?title=API:Query&action=edit&redlink=1\" class=\"new\" title=\"API:Query (page does not exist)\">bar</a> <a rel=\"nofollow\" class=\"external text\" href=\"http://www.example.com/\">baz</a></p>\n\n\n<!-- \nNewPP limit report\nParsed by mw1193\nCPU time usage: 0.013 seconds\nReal time usage: 0.016 seconds\nPreprocessor visited node count: 1/1000000\nPreprocessor generated node count: 0/1500000\nPost\u2010expand include size: 0/2097152 bytes\nTemplate argument size: 0/2097152 bytes\nHighest expansion depth: 1/40\nExpensive parser function count: 0/500\n-->\n\n<!-- \nTransclusion expansion time report (%,ms,calls,template)\n100.00% 0.000 1 - -total\n-->\n"
},
"langlinks": [],
"categories": [],
"links": [
{
"ns": 0,
"*": "Foo",
"exists": ""
},
{
"ns": 0,
"*": "API:Query"
}
],
"templates": [],
"images": [],
"externallinks": [
"http://www.example.com/"
],
"sections": [],
"displaytitle": "API",
"iwlinks": [],
"properties": []
}
}
|
Possible errors[edit]
Code | Info |
---|---|
invalidsection | The section parameter must be a valid section id or 'new' |
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.
The following documentation is the output of Special:ApiHelp/parse, generated from parse's source code. |
action=parse
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0+
Parses content and returns parser output.
See the various prop-modules of action=query to get information from the current version of a page.
There are several ways to specify the text to parse:
- Specify a page or revision, using page, pageid, or oldid.
- Specify content explicitly, using text, title, and contentmodel.
- Specify only a summary to parse. prop should be given an empty value.
- title
-
Title of page the text belongs to. If omitted, contentmodel must be specified, and API will be used as the title.
- text
-
Text to parse. Use title or contentmodel to control the content model.
- summary
-
Summary to parse.
- page
-
Parse the content of this page. Cannot be used together with text and title.
- pageid
-
Parse the content of this page. Overrides page.
- Type: integer
- redirects
-
If page or pageid is set to a redirect, resolve it.
- Type: boolean (details)
- oldid
-
Parse the content of this revision. Overrides page and pageid.
- Type: integer
- prop
-
Which pieces of information to get:
- text
- Gives the parsed text of the wikitext.
- langlinks
- Gives the language links in the parsed wikitext.
- categories
- Gives the categories in the parsed wikitext.
- categorieshtml
- Gives the HTML version of the categories.
- 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.
- revid
- Adds the revision ID of the parsed page.
- displaytitle
- Adds the title of the parsed wikitext.
- headitems
- Deprecated. Gives items to put in the
<head>
of the page. - headhtml
- Gives parsed
<head>
of the page. - modules
- Gives the ResourceLoader modules used on the page. To load, use
mw.loader.using()
. Either jsconfigvars or encodedjsconfigvars must be requested jointly with modules. - jsconfigvars
- Gives the JavaScript configuration variables specific to the page. To apply, use
mw.config.set()
. - encodedjsconfigvars
- Gives the JavaScript configuration variables specific to the page as a JSON string.
- indicators
- Gives the HTML of page status indicators used on the page.
- iwlinks
- Gives interwiki links in the parsed wikitext.
- wikitext
- Gives the original wikitext that was parsed.
- properties
- Gives various properties defined in the parsed wikitext.
- limitreportdata
- Gives the limit report in a structured way. Gives no data, when disablelimitreport is set.
- limitreporthtml
- Gives the HTML version of the limit report. Gives no data, when disablelimitreport is set.
- parsetree
- The XML parse tree of revision content (requires content model
wikitext
)
- Values (separate with | or alternative): text, langlinks, categories, categorieshtml, links, templates, images, externallinks, sections, revid, displaytitle, headitems, headhtml, modules, jsconfigvars, encodedjsconfigvars, indicators, iwlinks, wikitext, properties, limitreportdata, limitreporthtml, parsetree
- Default: text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle|iwlinks|properties
- pst
-
Do a pre-save transform on the input before parsing it. Only valid when used with text.
- Type: boolean (details)
- onlypst
-
Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used with text.
- Type: boolean (details)
- effectivelanglinks
-
Includes language links supplied by extensions (for use with prop=langlinks).
- Type: boolean (details)
- section
-
Only parse the content of this section number.
When new, parse text and sectiontitle as if adding a new section to the page.
new is allowed only when specifying text.
- sectiontitle
-
New section title when section is new.
Unlike page editing, this does not fall back to summary when omitted or empty.
- disablepp
- Deprecated.
-
Use disablelimitreport instead.
- Type: boolean (details)
- disablelimitreport
-
Omit the limit report ("NewPP limit report") from the parser output.
- Type: boolean (details)
- disableeditsection
-
Omit edit section links from the parser output.
- Type: boolean (details)
- disabletidy
-
Do not run HTML cleanup (e.g. tidy) on the parser output.
- Type: boolean (details)
- generatexml
- Deprecated.
-
Generate XML parse tree (requires content model
wikitext
; replaced by prop=parsetree). - Type: boolean (details)
- preview
-
Parse in preview mode.
- Type: boolean (details)
- sectionpreview
-
Parse in section preview mode (enables preview mode too).
- Type: boolean (details)
- disabletoc
-
Omit table of contents in output.
- Type: boolean (details)
- contentformat
-
Content serialization format used for the input text. Only valid when used with text.
- One of the following values: application/json, text/x-wiki, text/javascript, text/css, text/plain
- contentmodel
-
Content model of the input text. If omitted, title must be specified, and default will be the model of the specified title. Only valid when used with text.
- One of the following values: GadgetDefinition, SecurePoll, MassMessageListContent, flow-board, JsonSchema, wikitext, javascript, json, css, text, Scribunto
- mobileformat
-
Return parse output in a format suitable for mobile devices.
- Type: boolean (details)
- noimages
-
Disable images in mobile output.
- Type: boolean (details)
- mainpage
-
Apply mobile main page transformations.
- Type: boolean (details)
- templatesandboxprefix
-
Template sandbox prefix, as with Special:TemplateSandbox.
- Separate values with | or alternative. Maximum number of values is 50 (500 for bots).
- templatesandboxtitle
-
Parse the page using templatesandboxtext in place of the contents of the page named here.
- templatesandboxtext
-
Parse the page using this page content in place of the page named by templatesandboxtitle.
- templatesandboxcontentmodel
-
Content model of templatesandboxtext.
- One of the following values: GadgetDefinition, SecurePoll, MassMessageListContent, flow-board, JsonSchema, wikitext, javascript, json, css, text, Scribunto
- templatesandboxcontentformat
-
Content format of templatesandboxtext.
- One of the following values: application/json, text/x-wiki, text/javascript, text/css, text/plain
- Parse a page.
- api.php?action=parse&page=Project:Sandbox [open in sandbox]
- Parse wikitext.
- api.php?action=parse&text={{Project:Sandbox}}&contentmodel=wikitext [open in sandbox]
- Parse wikitext, specifying the page title.
- api.php?action=parse&text={{PAGENAME}}&title=Test [open in sandbox]
- Parse a summary.
- api.php?action=parse&summary=Some+[[link]]&prop= [open in sandbox]