API:Parsing wikitext/ja
From MediaWiki.org
| このページは MediaWiki 操作 API の説明文書の一部です。 |
MediaWiki 操作 API
- 導入とすばやいスタート
- よくある質問
- Tutorial
- フォーマット
- エラーの報告
- 使用制限
- クロスサイト リクエスト
- 認証
- クエリ
- 検索 (ページ名、内容、座標などで)
- ウィキテキストの構文解析とテンプレートの展開
- ページのキャッシュの破棄
- パラメーター情報
- ウィキ コンテンツの変更
- Watchlist feed
- ウィキデータ
- Extensions
- MediaWiki および拡張機能内での API の使用
- その他
- 実装
- Client code
- アサート
以下のAPIモジュールによって再処理とレンダリングのためにパーサーを呼び出すことができます。
Retrieving just the raw source wikitext can be done through prop=revisions.
expandtemplates[edit | edit source]
| MediaWiki バージョン: | 1.12 |
Further information: API:Expandtemplates
前処理したウィキテキスト (コメントを削除、テンプレートを展開、など) を返す
パラメーター[edit | edit source]
text: 前処理するウィキテキストtitle: 指定したページ上のウィキテキストであるかのように振る舞う (既定値:API)- This only really matters when parsing links to the page itself or links to subpages, or when using マジックワード like
{{PAGENAME}}.
- This only really matters when parsing links to the page itself or links to subpages, or when using マジックワード like
例[edit | edit source]
{{Project:Sandbox}} ウィキテキストを拡張する
| 結果 |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<expandtemplates>
{|style="background:transparent;border:1px dotted #000000;padding:2px;margin:2px;"
|-
|
''Welcome to the '''Wikipedia Sandbox'''! This page allows you to carry out experiments. To edit, click
<span class="plainlinks">'''[http://en.wikipedia.org/w/index.php?title=API&action=edit here]'''</span>
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''
<font style="font-size: 12px;">
[[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]]</font>
for experimental purposes.<br />
''Try other sandboxes:'' <span style="font-size: 12px;">
[[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]]</span><br />
''For a sandbox of your own, [[Wikipedia:User page#How do I create a user subpage?|create a user subpage]].''
|
{|style="background:transparent;"
|-
|
<table class="noprint Template-Shortcut"
style="float:right;margin:.5em 0;border:1px solid #999;background:#fff;padding:3px;">
<th class="noprint" align="center" valign="top">
<small>[[Wikipedia:Shortcut|Shortcuts]]:<br />
[[WP:SB]]<br />
[[WP:SAND]]<br />
[[WP:SANDBOX]]<br />
[[WP:TEST]]</small>
</th>
</table>
|-
|
<div style="background:#eeeeee;border:1px solid black;padding:5px;font-size:small;text-align:center;white-space:nowrap;">
More info:<br>
[[Wikipedia:Introduction|Introduction to Wikipedia]]<br>
[[Wikipedia:About the Sandbox|About the Sandbox]]<br>
[[Wikipedia:Tutorial|Editing tutorial]]
</div>
|}
|}
</sub>
This is a test</expandtemplates>
</api>
|
起こり得るエラー[edit | edit source]
なし。
構文解析[edit | edit source]
| MediaWiki バージョン: | 1.12 |
構文解析されたウィキテキストを返します。Extension:TextExtracts が追加的な API を提供します。
パラメーター[edit | edit source]
disablepp– Disable the PP Report from the parser output. Type: boololdid– Parse the content of this revision. Overridespageandpageid. Type: stringonlypst– 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,pageidoroldidis used. Type: bool
- Returns the same wikitext, after a PST has been applied. Ignored if
page– Parse the content of this page. Cannot be used together withtextandtitle. Type: stringpageid– Parse the content of this page. Overridespage. Type: stringprop– 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– Ifpagewas 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
sectionsis 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 ifpage,pageidoroldidis used. Type: boolredirects– If thepageparameter is set to a redirect, resolve it. Type: boolsection– Only retrieve the content of this section number. Type: stringsections– Retrieve the page's TOC (if any exists). Type: stringsummary– Summary to parse. Type: stringtext– Wikitext to parse. Type: stringtitle– 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 マジックワード like
{{PAGENAME}}.
- This only really matters when parsing links to the page itself or subpages, or when using マジックワード like
uselang– 構文解析すべきテキストまたはページの言語の言語コード (英語は "en"、フランス語は "fr"、など)。型: 文字列- 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.
- This is useful for language-dependent content, such as generated by the {{LangSwitch}} template at the Commons, or generally by things dependent on
contentmodel– 入力テキストのコンテンツ モデル。既定値は指定した title のモデルであり、title を指定しなかった場合はwikitextです。text とともに使用した場合のみ有効です。以下の値のいずれかです: wikitext, javascript, css, text, JsonZeroConfig, Scribunto, JsonSchemageneratexml– XML の構文解析木を生成する (contentmodel=wikitext が必須)。 型: 真偽値
例[edit | edit source]
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 [ApiSandbox で試用する]
| 結果 |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<parse>
<text><p><a href="/wiki/Foo" title="Foo">foo</a> <a href="/w/index.php?title=API:Query&amp;action=edit&amp;redlink=1" class="new" title="API:Query (page does not exist)">bar</a> <a href="http://www.example.com/" class="external text" title="http://www.example.com/" rel="nofollow">baz</a>
</p></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 | 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 |
注: 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.

