Jump to content

API:REST API/参考情報

From mediawiki.org
This page is a translated version of the page API:REST API/Reference and the translation is 53% complete.
Outdated translations are marked like this.

REST API拡張機能を使うと、MediaWikiに一位のURLのHTTPリクエストを送って作業ができます。このAPIを用いてアプリやスクリプトを構築してウィキページの検索やページ変更履歴の探索ができます。

説明文書

検索

MediaWiki バージョン:
1.35

検索結果のオブジェクト

検索結果オブジェクトはリクエストした検索と一致した特定のウィキページを示します。

{
  "id": 38930,
  "key": "Jupiter",
  "title": "Jupiter",
  "excerpt": "<span class=\"searchmatch\">Jupiter</span> is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half",
  "matched_title": null,
  "description": "fifth planet from the Sun and largest planet in the Solar System",
  "thumbnail": {
    "mimetype": "image/jpeg",
    "size": null,
    "width": 200,
    "height": 200,
    "duration": null,
    "url": "//upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Jupiter_and_its_shrunken_Great_Red_Spot.jpg/200px-Jupiter_and_its_shrunken_Great_Red_Spot.jpg"
  }
}


スキーマ

id

required | integer

ページ識別子


key

required | string

URL に適した形式でページ題名を表示


title

required | string


excerpt

required | string


matched_title

optional | string


description

required | string


thumbnail

required | object



Search pages

Path /search/page?q=search terms Method GET
Content type application/json Returns 一連の検索結果が載ったpages オブジェクト


Searches wiki page titles and contents for the provided search terms, and returns matching pages.

注 注:

curl

# Search English Wikipedia for up to 20 pages containing information about Jupiter
$ curl "https://en.wikipedia.org/w/rest.php/v1/search/page?q=jupiter&limit=20"


Python

# Search English Wikipedia for up to 20 pages containing information about Jupiter
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/search/page'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
    'q': 'jupiter',
    'limit': '20'
}

response = requests.get(url, headers=headers, params=params)
data = response.json()

print(data)


PHP

<?php
/*
Search English Wikipedia for up to 20 pages containing information about Jupiter
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/search/page";
$params = [ "q" => "jupiter", "limit" => "20" ];
$url = $url . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Search English Wikipedia for up to 20 pages containing information about Jupiter
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/search/page";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  let params = {
    'q': 'jupiter',
    'limit': '20'
  };
  let query = Object.keys(params)
             .map(k => k + '=' + encodeURIComponent(params[k]))
             .join('&');
  url = url + '?' + query;

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

q

required | query | string

検索する句
limit

optional | query | string

返す検索結果の上限は 1 以上 100 以下です。既定値:50

レスポンス

200 成功:検出しました。一連の検索結果を含むpagesオブジェクトを返します。
200 成功:何も見つかりませんでした。一連の空のpagesオブジェクトを返します。
400 クエリのパラメータが未設定です。q パラメータを追加してください。
400 リクエストした範囲が間違っています。limit パラメータの設定は 1 以上 100 以下にします。
500 エラーを検出

Autocomplete page title

Path /search/title?q=search terms Method GET
Content type application/json Returns pages object containing array of search results


Searches wiki page titles, and returns matches between the beginning of a title and the provided search terms. You can use this endpoint for a typeahead search that automatically suggests relevant pages by title.

When using this endpoint on your wiki
このエンドポイントは $wgSearchType 設定に指定した検索エンジンを用いており、結果は $wgNamespacesToBeSearchedDefault に指定の名前空間から検出して返します。 検索結果は設定した検索バックエンドごとに異なる場合があります。 While the default backend only applies basic case folding and prefix matches, more advanced backends may apply more complex variations. In the case of CirrusSearch for instance, matches are based on the Elastic Search completion suggester.

curl

# Search English Wikipedia for up to 5 pages with titles that start with "solar"
$ curl "https://en.wikipedia.org/w/rest.php/v1/search/title?q=solar&limit=5"


Python

# Search English Wikipedia for up to 5 pages with titles that start with "solar"
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/search/title'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
    'q': 'solar',
    'limit': '5'
}

response = requests.get(url, headers=headers, params=params)
data = response.json()

print(data)


PHP

<?php
/*
Search English Wikipedia for up to 5 pages with titles that start with "solar"
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/search/title";
$params = [ "q" => "solar", "limit" => "5" ];
$url = $url . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Search English Wikipedia for up to 5 pages with titles that start with "solar"
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/search/title";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  let params = {
    'q': 'solar',
    'limit': '5'
  };
  let query = Object.keys(params)
             .map(k => k + '=' + encodeURIComponent(params[k]))
             .join('&');
  url = url + '?' + query;

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

q

required | query | string

limit

optional | query | string

返す検索結果の上限は 1 以上 100 以下です。既定値:50

レスポンス

200 成功:検出しました。一連の検索結果を含むpagesオブジェクトを返します。
200 成功:何も見つかりませんでした。一連の空のpagesオブジェクトを返します。
400 クエリのパラメータが未設定です。q パラメータを追加してください。
400 リクエストした範囲が間違っています。limit パラメータの設定は 1 以上 100 以下にします。
500

ページ

MediaWiki バージョン:
1.35

ページのオブジェクト

ページのオブジェクトは特定のウィキページの直近の改訂を示します。

{
  "id": 9228,
  "key": "Earth",
  "title": "Earth",
  "latest": {
    "id": 963613515,
    "timestamp": "2020-06-20T20:05:55Z"
  },
  "content_model": "wikitext",
  "license": {
    "url": "//creativecommons.org/licenses/by-sa/3.0/",
    "title": "Creative Commons Attribution-Share Alike 3.0"
  },
  "html_url": "https://en.wikipedia.org/w/rest.php/v1/page/Earth/html"
}

スキーマ

id

required | integer

ページ識別子


key

required | string

URL に適した形式でページ題名を表示


title

required | string

読み取りやすい形式でページ題名を表示


latest

required | object

直近の改訂に関する情報には以下を含みます。
  • id (integer): 直近の改訂版の識別子
  • timestamp (string): 改訂日時をISO 8601形式記述


content_model

required | string

ページ内のコンテンツの種別。MediaWiki ならびに拡張機能が対応するコンテンツ・ハンドラーの参考情報を参照。


license

required | map of strings

ウィキのライセンス情報には以下を含みます。
  • url (string): $wgRightsUrl 設定を基準に適用される ライセンスの URL
  • title (string): $wgRightsText 設定を基準に適用されるライセンス類


html_url

required | string (Get page only)

API ルートを使い当該のページのコンテンツを HTML 形式で取得


html

required | string (ファイルをオフラインで取得のみ only)


source

required | string (ページのソース取得新規ページを作成ページを更新 pageに限定 only)

ページコンテンツの直近の見た目は content_model プロパティを使って書式設定


ページ言語オブジェクト

ページの言語オブジェクトは特定のウィキページとその使用言語を示し ます。

{
  "code": "pl",
  "name": "polski",
  "key": "Ziemia",
  "title": "Ziemia"
}

スキーマ

code

required | string

言語コード。ウィキメディアのプロジェクト群略号はメタウィキのサイト対照表をご参照ください。


name

required | string


key

required | string


title

required | string


Create page

Path /page Method POST
Accepts application/json Body see schema below
Content type application/json Returns Page object with source property


Creates a wiki page. The response includes a location header containing the API endpoint to fetch the new page.

This endpoint is designed to be used with the OAuth extension authorization process. Callers using cookie-based authentication instead must add a CSRF token to the request body. To get a CSRF token, see the Action API.

curl

# Create a user sandbox page on English Wikipedia
$ curl -X POST https://en.wikipedia.org/w/rest.php/v1/page -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" --data '{"source": "Hello, world!", "title": "User:<my username>/Sandbox", "comment": "Creating a test page with the REST API"}'

Python

# Create a user sandbox page on English Wikipedia
import requests
import json

url = 'https://en.wikipedia.org/w/rest.php/v1/page'

# Substitute your OAuth token
headers = {
    'User-Agent'   : 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)',
    'Content-Type' : 'application/json',
    'Authorization': 'Bearer $TOKEN'
}

# Substitute your username
request_data = {
    "source" : "Hello, world!",
    "title"  : "User:<my username>/Sandbox",
    "comment": "Creating a test page with the REST API"
}

response = requests.post( url, headers=headers, data = json.dumps(request_data) )
output = response.json()

print(output)

PHP

<?php
/*
Create a user sandbox page on English Wikipedia
*/

$url = 'https://en.wikipedia.org/w/rest.php/v1/page';

// Substitute your username
$fields = [
    'source' => 'Hello, world!',
    'title' => 'User:<my username>/Sandbox',
    'comment' => 'Creating a test page with the REST API'
];

$json = json_encode( $fields );

$token = 'YOUR_OAUTH_TOKEN'; // Substitute your OAuth token
$authorization = 'Authorization: Bearer ' . $token;

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' , $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

$output = curl_exec( $ch );
curl_close( $ch );

echo( $output );
?>

JavaScript

/*  
    Create a user sandbox page on English Wikipedia

    Substitute your OAuth token for $TOKEN.
    Substitute your username for <my username>.
*/

async function doFetch() {
  const response = await fetch(
    "https://en.wikipedia.org/w/rest.php/v1/page",
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer $TOKEN'
      },
      body: JSON.stringify({
        "source" : "Hello, world!",
        "title"  : "User:<my username>/Sandbox",
        "comment": "Creating a test page with the REST API"
      }),
      'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
    }
  );
  const data = await response.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

リクエストのスキーマ

source

required | string

Page content in the format specified by the content_model property
title

required | string

Page title. See the manual for information about page titles in MediaWiki.
comment

required | string

Reason for creating the page. To allow the comment to be filled in by the server, use "comment": null.
content_model

optional | string

Type of content on the page. Defaults to wikitext. See the content handlers reference for content models supported by MediaWiki and extensions.
token

optional | string

CSRF token required when using cookie-based authentication. Omit this property when authorizing using OAuth.

レスポンス

201 成功:ページを作成しました。ページ・オブジェクトsource プロパティを添えて返します。
400 Missing token when using cookie-based authentication. Add a CSRF token to the request body, or use an OAuth authorization flow.
400 Bad content model. Include a valid content_model based on available content handlers.
409 Page already exists
415 Unsupported Content-Type. Add the request header Content-Type: application/json.

Update page

経路 /page/{title} Content type application/json
メソッド PUT 戻り値 Page object with source property

Updates or creates a wiki page. This endpoint is designed to be used with the OAuth extension authorization process. Callers using cookie-based authentication instead must add a CSRF token to the request body. To get a CSRF token, see the Action API.

To update a page, you need the page's latest revision ID and the page source. First call the get page source endpoint, and then use the source and latest.id to update the page. If latest.id doesn't match the page's latest revision, the API resolves conflicts automatically when possible. In the event of an edit conflict, the API returns a 409 error.

To create a page, omit latest.id from the request.

curl

# Update the sandbox page on English Wikipedia with "Hello, world!"
$ curl -X PUT https://en.wikipedia.org/w/rest.php/v1/page/Wikipedia:Sandbox -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" --data '{"source": "Hello, world!", "comment": "Testing out the REST API", "latest": { "id": 555555555 }}'

Python

# Update the sandbox page on English Wikipedia with "Hello, world!"
import requests
import json

url = "https://en.wikipedia.org/w/rest.php/v1/page/Wikipedia:Sandbox"

# Substitute your OAuth token
headers = {
    "User-Agent" : "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)",
    "Content-Type" : "application/json",
    "Authorization" : "Bearer $TOKEN"
}

# Use the get page endpoint to get the latest revision ID
request_data = {
    "source" : "Hello, world!",
    "comment": "Testing out the REST API",
    "latest" : { "id": 555555555 }
}

response = requests.put( url, headers=headers, data = json.dumps(request_data) )
output = response.json()

print(output)

PHP

<?php
/*
Update the sandbox page on English Wikipedia with "Hello, world!"
*/

$page = 'Wikipedia:Sandbox';
$endpoint = 'https://en.wikipedia.org/w/rest.php/v1/page/';
$url = $endpoint . $page;

// Use the get page endpoint to get the latest revision ID
$fields = [
    'source' => 'Hello, world!',
    'comment' => 'Testing out the REST API',
    'latest' => [
        'id' => 555555555
    ]
];

$json = json_encode( $fields );

$token = 'YOUR_OAUTH_TOKEN'; // Substitute your OAuth token
$authorization = 'Authorization: Bearer ' . $token;

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 

$output = curl_exec( $ch );
curl_close( $ch );

echo( $output );
?>

JavaScript

/*  
    Update the sandbox page on English Wikipedia with "Hello, world!"

    Substitute your OAuth token for $TOKEN.
    Use the get page endpoint to get the latest revision ID.
*/

async function doFetch() {
  const response = await fetch(
    "https://en.wikipedia.org/w/rest.php/v1/page/Wikipedia:Sandbox",
    {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer $TOKEN'
      },
      body: JSON.stringify({
        "source": "Hello, world!",
        "comment": "Testing out the REST API",
        "latest": { "id": 555555555 }
      }),
      'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
    }
  );
  const data = await response.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

パラメーター

title

required | path

ウィキページの題名

リクエストのスキーマ

source

required | string

Page content in the format specified by the content_model property
comment

required | string

Summary of the edit. To allow the comment to be filled in by the server, use "comment": null.
latest

optional | object

Object identifying the base revision of the edit. You can fetch this information from the get page source endpoint.
latest.id

optional | integer

Identifier for the revision used as the base for the new source, required for updating an existing page. To create a page, omit this property.
content_model

optional | string

Type of content on the page. Defaults to wikitext for new pages or to the existing page's content model. See the content handlers reference for content models supported by MediaWiki and extensions.
token

optional | string

CSRF token required when using cookie-based authentication. Omit this property when authorizing using OAuth.

レスポンス

200 成功:ページを更新しました。ページ・オブジェクトsource プロパティを添えて返します。
201 Success: Page created. Returns page object with source property.
400 Missing token when using cookie-based authentication. Add a CSRF token to the request body, or use an OAuth authorization flow.
400 Bad content model. Ensure that the content_model property in the request body matches the content_model for the target page.
409 Page already exists. To update the existing page, provide the base revision identifier in latest.id in the request body.
409 Edit conflict. The error response includes the differences between the base revision specified in the request and the latest published revision. See the Wikidiff2 docs for information about the diff format. Requires Wikidiff2 extension 1.10+.
415 Unsupported Content-Type. Add the request header Content-Type: application/json.

Get page

経路 /page/{title}/bare Content type application/json
メソッド GET 戻り値 html_url プロパティを含むページ・オブジェクト

Returns the standard page object for a wiki page, including the API route to fetch the latest content in HTML, the license, and information about the latest revision.

curl

# Get information about the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare"


Python

# Get information about the Jupiter article on English Wikipedia
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get information about the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get information about the Jupiter article on English Wikipedia
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path

ウィキページの題名

レスポンス

200 成功:ページが見つかりました。ページhtml_url プロパティを添えて返します。
301
404

Get page offline

経路 /page/{title}/with_html Content type application/json
メソッド GET 戻り値 Page object with html property

Returns information about a wiki page, including the license, latest revision, and latest content in HTML.

curl

# Get HTML and metadata for the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html"


Python

# Get HTML and metadata for the Jupiter article on English Wikipedia
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get HTML and metadata for the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get HTML and metadata for the Jupiter article on English Wikipedia
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path | string

ウィキページの題名
redirect

optional | query | bool

レスポンス

200
301
307
404

Get page source

経路 /page/{title} Content type application/json
メソッド GET 戻り値 Page object with source property

Returns the content of a wiki page in the format specified by the content_model property, the license, and information about the latest revision.

curl

# Get source and metadata for the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter"


Python

# Get source and metadata for the Jupiter article on English Wikipedia
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get source and metadata for the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get source and metadata for the Jupiter article on English Wikipedia
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path

ウィキページの題名

レスポンス

200
301
404

HTMLの取得

経路 /page/{title}/html コンテンツの種別 text/html
メソッド GET 戻り値 HTML 2.1.0 形式で示すページ HTML

固有のウィキページについて最新のコンテンツをHTMLで返します。

curl

# Get the content of the Jupiter article on English Wikipedia in HTML
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html"


Python

# Get the content of the Jupiter article on English Wikipedia in HTML
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get the content of the Jupiter article on English Wikipedia in HTML
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get the content of the Jupiter article on English Wikipedia in HTML
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path | string

redirect

optional | query | bool

レスポンス

200
301
307
404

言語を取得

経路 /page/{title}/links/language コンテンツの種別 application/json
メソッド GET 戻り値 一連のページ言語

接続済みのウィキを検索して同じ主題を扱う異なる言語版を探します。戻り値は一連のページ言語のオブジェクトのうち言語名、言語コード、翻訳したページ題名を示します。 Returns an array of page language objects that include the name of the language, the language code, and the translated page title.

curl

# Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language"


Python

# Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path

ウィキページの題名

レスポンス

200 成功:他言語が見つかりました。戻り値は一連のページ言語です。
404 題名が見つかりません

ページ内のファイルを取得

経路 /page/{title}/links/media コンテンツの種別 application/json
メソッド GET 戻り値 一連のファイルが載ったfiles オブジェクト

特定のページに載ったメディアファイルの情報を返します。

curl

# Get media files used on the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media"


Python

# Get media files used on the Jupiter article on English Wikipedia
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get media files used on the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get media files used on the Jupiter article on English Wikipedia
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path

ウィキページの題名

レスポンス

200 成功:メディアファイルがありました。一連のファイルを含むfilesオブジェクトを返します。
200 成功:メディアファイルは見つかりませんでした。空のfilesオブジェクトを返します。
404 題名が見つかりません
400 ページに100件以上のメディアファイルがあります

Transform

MediaWiki バージョン:
1.41

The transform endpoint provides on-the-fly round-trip conversion between wikitext and HTML.

This documentation does not yet cover all available features of the transform endpoint. See the documentation for the older RESTBase endpoint for additional information: https://en.wikipedia.org/api/rest_v1/#/Transforms

Convert Wikitext to HTML

Route /transform/wikitext/to/html/{title} Content type application/json
Method POST Payload Transform request body with source
Returns an HTML document.

Converts wikitext to HTML.

Examples

curl

# Render wikitext in the context of the Jupiter page on English Wikipedia, without modifying the page:
$ curl -X POST -H "Content-Type: application/json" --data '{ "wikitext": "== Hello Jupiter ==" }' 'https://en.wikipedia.org/w/rest.php/v1/transform/wikitext/to/html/Jupiter'

Parameters

title

required | path

Wiki page title, used for context

Responses

200 Success: the response body contains the rendered HTML.

Convert HTML to Wikitext

Route /transform/html/to/wikitext/{title} Content type application/json
Method POST Payload Transform request body with HTML
Returns a wikitext document.

Converts wikitext to HTML.

curl

# Generate wikitext from HTML, in the context of the Jupiter page on English Wikipedia:
$ curl -X POST -H "Content-Type: application/json" --data '{ "html": "<h2> hello World </h2>" }' 'https://en.wikipedia.org/w/rest.php/v1/transform/html/to/wikitext/Jupiter'

パラメーター

title

required | path

Wiki page title, used for context

レスポンス

200 Success: the response body contains the wikitext.

Transform request body

Payload structure for transform requests.

Example

For converting wikitext to HTML:

{
  "wikitext": "Hello World"
}

For converting HTML to Wikitext:

{
  "html": "<h2>Hello World</h2>"
}

メディアファイル

MediaWiki バージョン:
1.35

ファイルのオブジェクト

ファイルオブジェクトは特定のウィキにアップロードされた特定のファイルを示します。

{
  "title": "The Blue Marble.jpg",
  "file_description_url": "//commons.wikimedia.org/wiki/File:The_Blue_Marble.jpg",
  "latest": {
    "timestamp": "2011-12-07T05:11:41Z",
    "user": {
      "id": 811185,
      "name": "Ultimate Roadgeek"
    }
  },
  "preferred": {
    "mediatype": "BITMAP",
    "size": null,
    "width": 599,
    "height": 599,
    "duration": null,
    "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/The_Blue_Marble.jpg/599px-The_Blue_Marble.jpg"
  },
  "original": {
    "mediatype": "BITMAP",
    "size": 7011595,
    "width": 3000,
    "height": 3002,
    "duration": null,
    "url": "https://upload.wikimedia.org/wikipedia/commons/7/78/The_Blue_Marble.jpg"
  },
  "thumbnail": {
    "mediatype": "BITMAP",
    "size": null,
    "width": 1023,
    "height": 1024,
    "duration": null,
    "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/The_Blue_Marble.jpg/1023px-The_Blue_Marble.jpg"
  }
}

スキーマ

title

required | string

ファイル名
file_description_url

required | string

ファイルを説明するURLには、ライセンス情報その他のメタデータが含まれます
latest

required | object

当該のファイルの最新の改訂版に関する情報を含むオブジェクトとして以下が対応します。
  • timestamp (string): ISO 8601 形式で最新の改訂時のタイムスタンプを表示
  • user (object): 当該のファイルをアップロードした利用者に関する情報を含むオブジェクト
    • id (integer): 利用者の識別子
    • name (string): 利用者名
preferred

required | object

ファイルに適したプレビューの形式、オリジナルの形式、サムネールの形式に関する情報として以下を含みます。
  • mediatype (string): ファイル種別は次のいずれかです:BITMAP、DRAWING、AUDIO、VIDEO、MULTIMEDIA, UNKNOWN、OFFICE、TEXT、EXECUTABLE、ARCHIVEまたは3D
  • size (integer): ファイルサイズをバイトもしくは適合しない場合はnullで表示
  • width (integer): 画像の推奨される最大幅をピクセルもしくは適用できない場合はnullで表示
  • height (integer): 画像の推奨される最大高さをピクセルもしくは適用できない場合はnullで表示
  • duration (integer): 録画、録音もしくはマルチメディアファイルの長さもしくはその他のメディアファイルの場合はnullを表示
  • url (string): ファイルのダウンロードURL
original

required | object

ファイルの取得のみ

thumbnail

required | object

ファイルを取得

経路 /file/{title} コンテンツの種別 application/json
メソッド GET 戻り値 ファイル

戻り値は特定のファイルに関する情報で、そのファイルのサムネールをダウンロードまたはプレビューするリンク、オリジナルのファイルのリンクを含みます。

Examples

curl

# Get File:The_Blue_Marble.jpg on Wikimedia Commons
$ curl "https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg"


Python

# Get File:The_Blue_Marble.jpg on Wikimedia Commons
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get File:The_Blue_Marble.jpg on Wikimedia Commons
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get File:The_Blue_Marble.jpg on Wikimedia Commons
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

Parameters

パラメーター 説明
title

required | path

ファイル名

Responses

200 成功:ファイルが見つかりました。ファイルを返します。
404 題名が見つかりません

経緯

MediaWiki バージョン:
1.35

リビジョンのオブジェクト

リビジョンのオブジェクトは特定のウィキページの変更を示します。

{
  "id": 931281281,
  "page": {
    "id": 38930,
    "title": "Jupiter"
  },
  "size": 126009,
  "minor": false,
  "timestamp": "2019-12-18T01:39:24Z",
  "user": {
    "id": 27015025,
    "name": "InternetArchiveBot"
  },
  "comment": "Bluelinking 2 books for [[WP:V|verifiability]].) #IABot (v2.1alpha3",
  "delta": 231
}

スキーマ

id

required | integer

改訂の識別子
取得するのはファイルの改版のみ

page

required | object

当該のページの情報を含むオブジェクトとして以下が対応します。
  • page_id (integer): ページの識別子
  • title (string): 読み取りやすい形式で頁題名を表示
user

required | object

当該のファイルを編集した利用者に関する情報を含むオブジェクトとして以下が対応します。
  • name (string): 利用者名
  • id (integer): 利用者の識別子

匿名利用者の場合は、nameは発信元のIPアドレスを示し、nullidです。

timestamp

required | string

編集日時のISO 8601形式記述
comment

required | string

利用者が書いたコメントもしくは編集要約。コメントのない改版はAPIはnullまたは""を返します。
size

required | integer

改版のサイズをバイトで表示
delta

required | integer

特定の版とその直前の版を比べた変更のバイト数、プラスもマイナスもあり(例:1)。直前の版画ない場合は、APIの戻り値はnull
minor

required | boolean

mとマークがついた編集の場合は真
html_url

required | string (Get revision only)


html

required | string (Get revision with HTML only)


source

required | string (Get revision source only)


ページの変更履歴を取得

経路 /page/{title}/history コンテンツの種別 application/json
メソッド GET 戻り値 ページの変更履歴の断片

Returns information about the latest revisions to a wiki page, in segments of 20 revisions, starting with the latest revision. The response includes API routes for the next oldest, next newest, and latest revision segments, letting you scroll through page history.

curl

# Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history?filter=bot&older_than=939967546"


Python

# Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
    'filter': 'bot',
    'older_than': '939967546'
}

response = requests.get(url, headers=headers, params=params)
data = response.json()

print(data)


PHP

<?php
/*
Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history";
$params = [ "filter" => "bot", "older_than" => "939967546" ];
$url = $url . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  let params = {
    'filter': 'bot',
    'older_than': '939967546'
  };
  let query = Object.keys(params)
             .map(k => k + '=' + encodeURIComponent(params[k]))
             .join('&');
  url = url + '?' + query;

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path

ウィキページの題名
older_than

optional | query

Accepts a revision ID. Returns the next 20 revisions older than the given revision ID.
newer_than

optional | query

Accepts a revision ID. Returns the next 20 revisions newer than the given revision ID.
filter

optional | query

Filter that returns only revisions with certain tags, one of:
  • reverted: Returns only revisions that revert an earlier edit
  • anonymous: Returns only revisions made by anonymous users
  • bot: Returns only revisions made by bots
  • minor: Returns only revisions marked as minor edits

The API supports one filter per request.

レスポンス

200 成功:改訂が見つかりました。ページ変更履歴の部分を返します。
200 Success: No revisions found. Returns a page history segment with an empty revisions array.
400 Revision identifier must be greater than 0
400 Parameters older_than and newer_than cannot both be specified
400 Invalid parameter
404 Title or revision not found

レスポンスのスキーマ

latest

required | string

API route to get the latest revisions
older

optional | string

If available, API route to get the prior revisions
newer

optional | string

If available, API route to get the following revisions
revisions

required | array

一連の 0-20 改訂オブジェクト

Get page history counts

経路 /page/{title}/history/counts/{type} Content type application/json
メソッド GET 戻り値 変更回数のオブジェクト

Returns data about a page's history.

curl

# Get the number of edits to a page between revisions 384955912 and 406217369
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits?from=384955912&to=406217369"


Python

# Get the number of edits to a page between revisions 384955912 and 406217369
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
    'from': '384955912',
    'to': '406217369'
}

response = requests.get(url, headers=headers, params=params)
data = response.json()

print(data)


PHP

<?php
/*
Get the number of edits to a page between revisions 384955912 and 406217369
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits";
$params = [ "from" => "384955912", "to" => "406217369" ];
$url = $url . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get the number of edits to a page between revisions 384955912 and 406217369
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  let params = {
    'from': '384955912',
    'to': '406217369'
  };
  let query = Object.keys(params)
             .map(k => k + '=' + encodeURIComponent(params[k]))
             .join('&');
  url = url + '?' + query;

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

title

required | path

ウィキページの題名
type

required | path

Type of count, one of:
  • anonymous: Edits made by anonymous users. Limit: 10,000
  • bot: Edits made by bots. Limit: 10,000
  • editors: Users or bots that have edited a page. Limit: 25,000
  • edits: Any change to page content. Limit: 30,000
  • minor: Edits marked as minor. If the minor edit count exceeds 2,000, the API returns a 500 error. Limit: 1,000
  • reverted: Edits that revert an earlier edit. Limit: 30,000
from

optional | query

For edits and editors types only

カウントは改訂版番号 IDにより改訂2版の差分に特定します。クエリパラメータの fromto は必ずペアとして入力します。検出結果は fromto の改訂に該当する編集もしくは編集者を除外します。

to

optional | query

レスポンス

200 成功
400 Invalid parameter or combination of parameters
404 Title or revision not found
500 Minor edit count exceeds 2000

レスポンスのスキーマ

count

required | integer

The value of the data point up to the type's limit. If the value exceeds the limit, the API returns the limit as the value of count and sets the limit property to true.
limit

required | boolean

Returns true if the data point exceeds the type's limit.

Get revision

Path revision/{id}/bare Method GET
Content type application/json Returns Revision


Returns details for an individual revision.

curl

# Get information about revision 764138197
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare"


Python

# Get information about revision 764138197
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get information about revision 764138197
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get information about revision 764138197
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

id

required | path | string

レスポンス

200 成功:改訂が見つかりました。改訂版を返します。
404

Get revision source

Path revision/{id} Method GET
Content type application/json Returns Revision


Returns details for an individual revision.

Examples

curl

# Get the wikitext of revision 764138197
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197"


Python

# Get the wikitext of revision 764138197
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get the wikitext of revision 764138197
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get the wikitext of revision 764138197
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

https://en.wikipedia.org/w/rest.php/v1/revision/764138197

Parameters

id

required | path | string

Responses

200
404

Get revision HTML

Path revision/{id}/html Method GET
Content type text/HTML Returns Revision


Returns HTML for an individual revision.

Examples

curl

# Get HTML of revision 764138197
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html"


Python

# Get HTML of revision 764138197
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get HTML of revision 764138197
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get HTML of revision 764138197
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html

Parameters

id

required | path | string

Responses

200
404

Get revision information with HTML

Path revision/{id}/with_html Method GET
Content type application/json Returns Revision


Returns HTML and meta-data for an individual revision.

Examples

curl

# Get information about revision 764138197 along with rendered HTML
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html"


Python

# Get information about revision 764138197 along with rendered HTML
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Get information about revision 764138197 along with rendered HTML
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Get information about revision 764138197 along with rendered HTML
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html

Parameters

id

required | path | string

Responses

200
404

Compare revisions

経路 revision/{from}/compare/{to} Content type application/json
メソッド GET 戻り値 Wikidiff2 JSON 差分のフォーマット

2つの版を左右に並べて表示し、1行ずつ対比することができます。(サンプル参照。) 比較対象できるのはテキストで書いたウィキページに限定されます。

reminder

curl

# Compare revision 847170467 to 851733941
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941"


Python

# Compare revision 847170467 to 851733941
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)


PHP

<?php
/*
Compare revision 847170467 to 851733941
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941";


$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

/*  
    Compare revision 847170467 to 851733941
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();

試してみる

パラメーター

from

required | path

Revision identifier to use as the base for comparison
to

required | path

Revision identifier to compare to the base

レスポンス

200 成功:改訂が見つかりました
400 Revision IDs are for different pages or for pages that can't be compared
400 Invalid content type
403 Revision not publicly accessible
404 Revision not found
500 Wikidiff2 拡張機能 1.9.0 もしくはそれ以降がインストールされていません

レスポンスのスキーマ

from

required | object

Information about the base revision used in the comparison
to

required | object

Information about the revision being compared to the base revision
from.id

to.id
required | integer

Revision identifier
from.slot_role

to.slot_role
required | string

Area of the page being compared, usually main
from.sections

to.sections
required | array

節見出しを表す一連のオブジェクトには以下を含みます:
  • level (integer): Heading level, 1 through 4
  • heading (string): 見出し行の文字列をウィキ文で記す
  • offset (integer): Location of the heading, in bytes from the beginning of the page
diff

required | array of objects

Each object in the diff array represents a line in a visual, line-by-line comparison between the two revisions.
diff.type

required | integer

The type of change represented by the diff object, either:
  • 0: A line with the same content in both revisions, included to provide context when viewing the diff. The API returns up to two context lines around each change.
  • 1: A line included in the to revision but not in the from revision.
  • 2: A line included in the from revision but not in the to revision.
  • 3: A line containing text that differs between the two revisions. (For changes to paragraph location as well as content, see type 5.)
  • 4: When a paragraph's location differs between the two revisions, a type 4 object represents the location in the from revision.
  • 5: When a paragraph's location differs between the two revisions, a type 5 object represents the location in the to revision. This type can also include word-level differences between the two revisions.
diff.lineNumber

optional | integer

The line number of the change based on the to revision.
diff.text

required | string

The text of the line, including content from both revisions. For a line containing text that differs between the two revisions, you can use highlightRanges to visually indicate added and removed text. For a line containing a new line, the API returns the text as "" (empty string).
diff.highlightRanges

optional | array of objects

An array of objects that indicate where and in what style text should be highlighted to visually represent changes.

Each object includes:

  • start (integer): Where the highlighted text should start, in the number of bytes from the beginning of the line.
  • length (integer): The length of the highlighted section, in bytes.
  • type (integer): The type of highlight:
    • 0 indicates an addition.
    • 1 indicates a deletion.
diff.moveInfo

optional | object

Visual indicators to use when a paragraph's location differs between the two revisions. moveInfo objects occur in pairs within the diff.
  • id (string): The ID of the paragraph described by the diff object.
  • linkId (string): The ID of the corresponding paragraph.
    • For type 4 diff objects, linkId represents the location in the to revision.
    • For type 5 diff objects, linkId represents the location in the from revision.
  • linkDirection (integer): A visual indicator of the relationship between the two locations. You can use this property to display an arrow icon within the diff.
    • 0 indicates that the linkId paragraph is lower on the page than the id paragraph.
    • 1 indicates that the linkId paragraph is higher on the page than the id paragraph.
diff.offset

required | object

The location of the line in bytes from the beginning of the page, including:
  • from (integer): The first byte of the line in the from revision. A null value indicates that the line doesn't exist in the from revision.
  • to (integer): The first byte of the line in the to revision. A null value indicates that the line doesn't exist in the to revision.