Parsoid
|
Parsoid
双方向のランタイム ウィキテキスト パーサー。 RDFa を用いて、ウィキテキストと HTML/XML DOM を相互変換します。
|

Parsoid はウィキテキストとHTMLを交互に変換するPHPライブラリで、MediaWiki (バージョン1.35以降) に同梱されています。 2012年から開発中です。もともとはJavaScriptで書かれたもので、VisualEditorに対応するために構築されました。 Parsoidはバージョン1.35以降のMediaWikiに同梱されています。 バージョン1.47のMediaWikiでは、Parsoidはparser unificationとして知られるプロジェクトによって、native parserを置き換える形でMediaWikiのデフォルトのパーサーになる予定です。
技術的な詳細
Parsoid は、MediaWiki のウィキテキスト構文と同等の HTML/RDFa 文書モデルを相互に変換できるアプリケーションです。この変換には、自動処理や豊富な編集機能の向上をサポートする機能が含まれています。
これは2012年からウィキメディア財団のチームによって開発が続けられています。 現在、VisualEditor、コンテンツ翻訳、他のアプリケーションで広く使われています。
Parsoidは完全な変換、つまり情報の損失を防ぎ、「汚い差分」を無くす事を目的としています。
ウィキメディアのウィキでは現在、いくつかのアプリケーションのためにRESTBaseのHTML変換をバックエンドで行っています。 予想されるところでは、RESTBase はより緊密に MediaWiki に統合されたキャッシュに最終的に置き換えられるでしょう。
プロジェクト全体の詳細については、2013年3月のブログの投稿を参照してください。 使用されているHTMLモデルについては、 MediaWiki DOM specを参照してください。
Parsoidは元々JavaScriptで書かれ、Node.jsを使用するWebサービスとして作られました。
2019年2月のテクニカルトーク (スライド)とブログ投稿ではPHPへ移植する工程を説明しています。
Parsoid拡張APIは現在開発中で、2020年8月のテクニカルトークでこの活動について説明しています。
GitHub リポジトリ: https://github.com/wikimedia/parsoid
使用法
- Parsoid/Releases – Parsoidリリースノート
- Parsoid/API – web API向け
- MediaWiki DOM spec – 将来の保存フォーマットとして役立つように設計されたAPIから得られるHTMLを理解する
- Parsoid/LanguageConverter – ParsoidのLanguageConverterの実装に関するメモ
- Parsoid/コア パーサーの出力との既知の違い
インストール
Parsoidは、Mediawikiにバージョン1.35から含まれています。 有効にするための設定は必要ありません。
Parsoidは、従来RESTBaseによって使用されておりWMF内部クラスターの外部からはアクセスできなかった内部 REST APIを公開しています。 これはビジュアルエディターやコアの閲覧画面にはもはや必要ないため、内部APIは非推奨となっており、MW1.43で削除される予定です。
Parsoidは、形式上はmediawikiコアで使用されるComposerライブラリです。
もし未だに何かしらの理由で内部APIが必要な場合は、Parsoidを「拡張」として以下をLocalSettings.phpに追加することで明示的にロードできます。
wfLoadExtension( 'Parsoid', "$IP/vendor/wikimedia/parsoid/extension.json" );
内部Parsoid APIの残りのサードパーティー利用者は、同等の機能を提供するコアREST HTMLページエンドポイントに移行するように強く推奨されています。
開発
開発はParsoid Git repositoryで行われます。 コードレビューはGerritで行われます。 アカウントのセットアップはGerrit/はじめにを参照してください。
仮想マシンでMediaWiki-Vagrant開発環境を使用する場合は、ロールvisualeditorをそれに追加するだけでExtension:VisualEditorと共に動作するParsoidがセットアップされます。
以下の手順は、MediaWiki 1.35 以降向けのものです。 1.34以前のJavaScriptで記述されているParsoidについては、Parsoid/JSを参照してください。
開発用にチェックアウトしたParsoidをリンクする
MediaWiki の標準的なインストールでは、Parsoid は MediaWiki のwikimedia/parsoidというcomposer ライブラリに含まれています。
開発目的では通常、MediaWikiコアにcomposerライブラリとしてバンドルされたバージョンではなく、gitからチェックアウトしたバージョンを使用します。 The following lines added to LocalSettings.php allow use of a git checkout of Parsoid (optionally), load the Parsoid REST API with wfLoadExtension (rather than using the version bundled in VisualEditor) and manually do the Parsoid configuration which is usually done by VisualEditor:
$parsoidInstallDir = 'vendor/wikimedia/parsoid'; # 同梱されたコピー
#$parsoidInstallDir = '/my/path/to/git/checkout/of/Parsoid';
// 開発者向け:Parsoidが$parsoidInstallDirから実行されることを確認してください、
// (デフォルトでmediawiki-coreに含まれているバージョンではありません)
// wfLoadExtension()*の前に*存在しなければなりません
if ( $parsoidInstallDir !== 'vendor/wikimedia/parsoid' ) {
function wfInterceptParsoidLoading( $className ) {
// Parsoid名前空間のクラスのみをフックしてください
if ( preg_match( '/(MW|Wikimedia\\\\)Parsoid\\\\/', $className ) ) {
$fileName = Autoloader::find( $className );
if ( $fileName !== null ) {
require $fileName;
}
}
}
spl_autoload_register( 'wfInterceptParsoidLoading', true, true );
// AutoLoader::registerNamespacesはMW 1.39で追加されました
AutoLoader::registerNamespaces( [
// これを「autoload」節と同期させてください
// $parsoidInstallDir/composer.json
'Wikimedia\\Parsoid\\' => "$parsoidInstallDir/src/",
] );
}
wfLoadExtension( 'Parsoid', "$parsoidInstallDir/extension.json" );
unset( $parsoidInstallDir );
これらのことは、ビジュアルエディターの自動設定とMediaWikiに含まれるParsoidコードを使用できるビジュアルエディターのユーザーのほとんどにとっては必要ではありませんが、ほとんどの開発者にとっては必要となります。
もしあなたがMediaWikiをNginx経由で提供している場合、あなたはサーバーブロックにこのようなものを追加する必要があります(MediaWikiの設定ファイルが/w/にあると仮定します):
location /w/rest.php/ {
try_files $uri $uri/ /w/rest.php?$query_string;
}
もしあなたがDockerでMediaWikiを実行しており、ローカルのParsoidリポジトリをMediaWikiにリンクしている場合、MediaWikiプロジェクトのdocker-compose.override.ymlファイルにおいて、Dockerコンテナに追加のボリュームをマッピングする必要があります。 そうするための最も単純な方法はMediaWikiプロジェクトにdocker-compose.override.ymlファイルを作成し、その中に以下のコードを(パス変更を適宜行って)記述することです。 もしすでにdocker-compose.override.ymlファイルがある場合は、それに従って修正してください。
services:
mediawiki:
volumes:
- ./:/var/www/html/w:cached
- /my/path/to/git/checkout/of/Parsoid:/my/path/to/git/checkout/of/Parsoid
適切な設定をテストするには、{$wgScriptPath}/rest.php/{$domain}/v3/page/html/Main%20Pageにアクセスしてください。ここで$domainは$wgCanonicalServerのホスト名です。
(本番のWMFサーバでは、parsoid REST APIは外部ネットワークに公開されないことに注意してください。)
テストの実行
全てのパーサーテストとMochaテストを実行するために:
$ composer test
パーサーテストには非常にわずかながらphp bin/parserTests.php --helpに列挙できるオプションがあります。
設定されたMediaWikiインストールを指す環境変数MW_INSTALL_DIRがある場合は、以下の追加テストを実行できます:
$ composer phan-integrated
簡単なwikitextへの変換
コマンドラインから、簡単なウィキテキストのスニペットをbin/ディレクトリにあるparse.phpスクリプトで変換できます:
$ echo '[[Foo]]' | php bin/parse.php
パーススクリプトには多くのオプションがあります。
php bin/parse.php --helpオプションはこれについての情報を提供します。
Parsoidのデバック (開発者向け)
See Parsoid/Debugging for debugging tips.
継続的インテグレーション
Parsoid is always available as a library since it is a composer dependency of MediaWiki core. But two pieces are not enabled:
- Parsoid ServiceWiring
- Parsoid's external REST api
The test runner Quibble would enable it if it detects mediawiki/services/parsoid.git has been cloned as part of the build.
In which case it:
- points the autoloader for
Wikimedia\Parsoidto the cloned code (effectively replacing the version installed by composer) - Load the extension
wfLoadExtension( 'Parsoid', '/path/to/cloned/repo' );
The ServiceWiring should be enabled in MediaWiki starting with 1.38.
The REST API would theorically never get merged in MediaWiki: a) it has never been exposed to the public in production, it is an internal API used by RESTBase which is going away; b) it never has been security audited and c) it is redundant with the enterprise MediaWiki API. The solution will be for VisualEditor to invoke Parsoid directly via the VisualEditor Action API which would save a round trip through the REST API.
Loading the extension is thus a hack which enables using interfaces subject to change and which we don't really want people to use yet.
For most purposes, parsoid should thus not be added as a CI dependency, the only exception as of October 2021 is the Disambiguator MediaWiki extension.
Loading parsoid as an extension let us run MediaWiki integration test jobs against mediawiki/services/parsoid.git (such as Quibble, apitesting) and ensure Parsoid and MediaWiki work together.
An extension may be able to write tests with Parsoid even when the repository has not been cloned.
Since it is a composer dependency of MediaWiki core the MediaWiki\Parsoid namespace is available, but the service wiring part is not (it is extension/src in the Parsoid repository and exposed as the \MWParsoid namespace).
The ParsoidTestFileSuite.php code would only run the parser tests if Parsoid has been loaded (which should be the default with MediaWiki 1.38).
For CI, Parsoid is tested against the tip of MediaWiki, whereas MediaWiki is tested with the Composer dependency. In case of a breaking change, the Parsoid change get merged first (which breaks its CI but not MediaWiki one) and MediaWiki get adjusted when Parsoid is updated. It is thus a one way change.
リリースビルド
For MediaWiki release builds, we have an integration of Parsoid ServiceWiring into VisualEditor in order to have VisualEditor work without further configuration (beside a wfLoadExtension( 'VisualEditor' )).
The release build also enables the REST API and hook everything us so that parsoid works out of the box.
This is done by copying a bit of Parsoid code into VisualEditor which is not in the master branch of VisualEditor since that would be obsolete as soon as Parsoid is updated.
Instead the code is maintained in two places.
技術的な説明文書
- Parsoid/Internals – documentation about Parsoid internals with links to other details.
- PHP Porting notes and help-wanted tasks
- Parsoid deployment agenda on Wikimedia cluster (code normally deployed every Monday and Wednesday between 1pm - 1:30pm PST)
- Parsoid/Round-trip testing – The round-trip testing setup we are using to test the wikitext -> HTML DOM -> wikitext round-trip on actual Wikipedia content.
- Parsoid/Visual Diffs Testing – Info about visual diff testing for comparing Parsoid's html rendering with php parser's html rendering + a testreduce setup for doing mass visual diff tests.
- Parsoid/limitations – Limitations in Parsoid, mainly contrived templating (ab)uses that don't matter in practice. Could be extended to be similar to the preprocessor upgrade notes (Might need updating)
- Parsoid/Bibliography – 関連文献の書誌情報
Proton 開発者向けリンク
- デバッグのヒントは Parsoid/Debugging を参照してください。
- Parsoid についてパッケージの更新もしくは追加
- Parsoid のパーサ試験用コピーをコアへ/コアから同期させるにはこちらの指示を参照
- Parsoid ではプログラム面からの呼び出し用のライブラリ用インターフェイスが限定されています。
- 技術トークで Parsoid で有効な拡張機能の対象見直しを採用
- So you want your extension to work with Parsoid
- Parsoid HTML の仕様バージョン
- So you are going to change Parsoid output
Parsoid 導入者向けのリンク類(ウィキメディア・クラスタ対象)
- Parsoid/Deployments
- RT 試験用コミット類(回帰と修正のチェックに便利)
- Parsoidの導入の手順
- Kibana ダッシュボード
- Grafana ダッシュボードは wt2html 指標用
- Grafana ダッシュボードは html2wt 指標用
- Prometheus breakdown for the Parsoid cluster on eqiad
- Prometheus breakdown for the Parsoid cluster on codfw
- jenkins jobsの更新にはJenkins Job Builder docs
History
元々は JavaScript (Node.jsを使用)で記述され、ウィキメディア クラスターで2012年12月に運用開始しました。 2019年、PHPに移植され、12月にウィキメディアクラスターのParsoidもPHPバージョンに置き換えられました。 Parsoid は、MediaWiki コアに統合されており、将来的には MediaWiki の現在のネイティブ パーサーを置き換えることを目指しています。 In early 2024, Parsoid began to be used on some production wikis of the Wikimedia Foundation as the default parser for read views. You can see them in the production config list.
Parsoid(PHP Ver.)は2020年9月のVer.1.35から標準で組み込まれています。 ウィキメディア以外でのParsoid/JSの利用は、2021年9月のMediaWiki 1.31 (LTS)のサポート終了までサポートされていました。
FAQ
- How do I see if a page was rendered with Parsoid?
- The footer will say "Page was rendered with Parsoid".
- How do I set a page to temporarily render with Parsoid?
- Install Extension:ParserMigration
- Add
?useparsoid=1to the URL
- How do I get an entire wiki to render with Parsoid?
- Install Extension:ParserMigration
- Set
$wgParserMigrationEnableParsoidArticlePages = true; - Set
$wgParserMigrationEnableParsoidDiscussionTools = true;
- Which Wikimedia wikis render with Parsoid?
- The list is at parsoidrendered.dblist. As of August 2025, it is approximately 250 of the 1000 wikis. Rollout will continue until all wikis are using Parsoid.
関連項目
- API
- RESTBase – HTML ページのキャッシュ/ストレージ API プロキシを Parsoid で翻訳
- Parser 2011/Parser plan – 初期の設計案と課題(すでにやや陳腐化)
- Special:PrefixIndex/Parsoid/ – このウィキにある Parsoid 関連のページ
- Extension:ParsoidBatchAPI (過去ログ)
- parsoid-jsapi: ウィキテキストの抽出と変換に用いる高次のインタフェースであり、mwparserfromhell API に類似します。
- 代替パーサ
- Parsoid/Parser Unification
外部リンク
- ソースコード(GitHub ミラー)
- JS 説明文書(Parsoid の旧版)
- PHP 説明文書
- ウィキメディア・コモンズにある「Parsoid」
お問い合わせ
ヘルプが知りたい、質問/ご意見ご指摘については、担当に #mediawiki-parsoid 接続 または ウィキ文メーリングリスト wikitext-l mailing list に投稿してください。
どれもうまくいかなかった場合は、担当にメールにてwikimedia.org ドメインのcontent-transform-teamまでご連絡ください。
Parsoid は Content Transform Team によって保守されています。
ヘルプを得る:
|
