Help:書き出し
![]() |
注意: このページを編集すると、編集内容が CC0 のもとで公開されることに同意したと見なされます。詳細はパブリック・ドメインのヘルプ ページを参照してください。 このページの古い版の一部は、CC BY-SA ライセンスのもとで取り込まれました。 新しい編集のみがパブリックドメインと見なされます。 |
![]() |
ウィキページは、別に設置した MediaWiki に取り込むために、あるいはコンテンツを分析するといった別のことに利用するために、特別な XML 形式で書き出すことができます。 ページ以外をエクスポートするにはm:Syndication feedsを、ページのインポートにはHelp:Import をご参照ください。(訳注:フィードも参照。)
書き出しの方法
ページを書き出す方法が少なくとも 4 つあります:
- 記事の名前を特別:ページの書き出し内の枠に貼り付けるか、//www.mediawiki.org/wiki/Special:Export/FULLPAGENAME を使用します。
- バックアップスクリプト
dumpBackup.php
は、すべてのウィキページを XML ファイルにダンプします。dumpBackup.php
は MediaWiki 1.5 以降でのみ動作します。 このスクリプトを実行するには、サーバに直接アクセスする必要があります。 https://dumps.wikimedia.org/ でウィキメディアのプロジェクト群のダンプを定期的に提供します。- 注記:AdminSettings.php の設定によりdumpBackup.php が正しく走る場合があります。 詳細情報は m:MediaWiki を参照してください。
- OAI-PMH-インターフェースでは、特定の時点以降に改変された複数ページを定期的に取り込みます。 ただしウィキメディアのプロジェクト群で、このインターフェースを公的に採用していないものもあります。Wikimedia update feed service をご参照ください (訳注:[:m:Wikimedia_update_feed_service 転送先])。 OAI-PMH には書き出した記事の実体を包むラッパー書式があります。
- ここでは説明しませんが、Python Wikipedia Robot Framework を使用。
既定では特定のページの最新の特定版のみ含みます。 オプションとして、日付、時刻、利用者名や編集要約欄の記述とともに全ての版を入手できます。 オプションとして全テンプレートの最新版 (直接もしくは間接的に呼ぶ) も、書き出します。
さらに SQL データベースの複写も可能です。 これはMediaWiki 1.5 以前の情報で、ここでは詳細を扱いませんが、データベースのダンプの過去の入手方法です。
「特別:ページの書き出し」の使用
以下の例のように特定の名前空間の全ページを書き出す場合。
1. 書き出すページの名前を取得する
以下の説明が非常に不明瞭であるため、例の方がわかりやすいと思います。
- 特別:全ページに行き、希望する記事/ファイルを選びます。
- ページ名の一覧をテキストエディタにコピーします。
- すべてのページ名を別々の行に配置します。
- You can achieve that relatively quickly if you copy the part of the rendered page with the desired names, and paste this into say MS Word - use paste special as unformatted text - then open the replace function (CTRL+h), entering ^t in Find what, entering ^p in Replace with and then hitting Replace All button.
(This relies on tabs between the page names; these are typically the result of the fact that the page names are inside td-tags in the html-source.)
- The text editor Vim also allows for a quick way to fix line breaks: after pasting the whole list, run the command :1,$s/\t/\r/g to replace all tabs by carriage returns and then :1,$s/^\n//g to remove every line containing only a newline character.
- Another approach is to copy the formatted text into any editor exposing the html.
Remove all <tr> and </tr> tags and replace all <td> tags to <tr><td> and </td> tags to </td></tr> the html will then be parsed into the needed format.
- If you have shell and mysql access to your server, you can use this script:
# mysql -umike -pmikespassword -hlocalhost wikidbname select page_title from wiki_page where page_namespace=0 EOF
Note, replace mike and mikespassword with your own. Also, this example shows tables with the prefix wiki_
- Prefix the namespace to the page names (e.g. 'Help:Contents'), unless the selected namespace is the main namespace.
- Repeat the steps above for other namespaces (e.g. Category:, Template:, etc.)
A similar script for PostgreSQL databases looks like this:
$ psql -At -U wikiuser -h localhost wikidb -c "select page_title from mediawiki.page"
Note, replace wikiuser with your own, the database will prompt you for a password. This example shows tables without the prefix wiki_ and with the namespace specified as part of the table name.
Alternatively, a quick approach for those with access to a machine with Python installed:
- Go to Special:Allpages and choose the desired namespace.
- Save the entire webpage as index.php.htm.
Some wikis may have more pages than will fit on one screen of AllPages; you will need to save each of those pages.
- Run export_all_helper.py in the same directory as the saved file.
You may wish to pipe the output to a file; e.g. python export_all_helper.py > main
to send it to a file named "main".
- Save the page names output by the script.
2. Perform the export
- Go to Special:Export and paste all your page names into the textbox, making sure there are no empty lines.
- Click 'Submit query'
- Save the resulting XML to a file using your browser's save facility.
and finally...
- Open the XML file in a text editor.
Scroll to the bottom to check for error messages.
Now you can use this XML file to perform an import.
完全な履歴の書き出し
A checkbox in the Special:Export interface selects whether to export the full history (all versions of an article) or the most recent version of articles.
A maximum of 100 revisions are returned; other revisions can be requested as detailed in Parameters to Special:Export .
書き出しの形式
XML ファイルとして入手する形式はあらゆる点で統一がされいます。 https://www.mediawiki.org/xml/export-0.10.xsd にスキーマ言語 としてコードが公開されています。 この形式は、ウェブブラウザで表示することを前提にしていません。 ブラウザの中には、「+」や「-」のリンクを用意し、きちんと整った体裁で XML を表示するものがあります。 あるいはまた XML-ソースの内容を閲覧する代替の方法として、ウェブブラウザの「ソースを見る」機能を使うか、あるいはプログラムを選んでローカルに XML ファイルを保存して以降、表示させます。 もし直接 XML を読める場合は、実際に当該するウィキ文を探し出すのも難しくはありません。 If you don't use a special XML editor "<" and ">" appear as < and >, to avoid a conflict with XML tags; to avoid ambiguity, "&" is coded as "&".
In the current version the export format does not contain an XML replacement of wiki markup (see Wikipedia DTD for an older proposal). 記事を編集するときと同じようにウィキテキストを取得します。
例
<mediawiki xml:lang="en">
<page>
<title>Page title</title>
<restrictions>edit=sysop:move=sysop</restrictions>
<revision>
<timestamp>2001-01-15T13:15:00Z</timestamp>
<contributor><username>Foobar</username></contributor>
<comment>I have just one thing to say!</comment>
<text>A bunch of [[Special:MyLanguage/text|text]] here.</text>
<minor />
</revision>
<revision>
<timestamp>2001-01-15T13:10:27Z</timestamp>
<contributor><ip>10.0.0.2</ip></contributor>
<comment>new!</comment>
<text>An earlier [[Special:MyLanguage/revision|revision]].</text>
</revision>
</page>
<page>
<title>Talk:Page title</title>
<revision>
<timestamp>2001-01-15T14:03:00Z</timestamp>
<contributor><ip>10.0.0.2</ip></contributor>
<comment>hey</comment>
<text>WHYD YOU LOCK PAGE??!!! i was editing that jerk</text>
</revision>
</page>
</mediawiki>
DTD
非公式ではありますが、書式を短くまとめた文書型定義 Document Type Definition をご紹介します。 もし DTD が何かわからなくても読み飛ばしてください。
<!ELEMENT mediawiki (siteinfo,page*)>
<!-- version contains the version number of the format (currently 0.3) -->
<!ATTLIST mediawiki
version CDATA #REQUIRED
xmlns CDATA #FIXED "https://www.mediawiki.org/xml/export-0.3/"
xmlns:xsi CDATA #FIXED "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation CDATA #FIXED
"https://www.mediawiki.org/xml/export-0.3/ https://www.mediawiki.org/xml/export-0.3.xsd"
xml:lang CDATA #IMPLIED
>
<!ELEMENT siteinfo (sitename,base,generator,case,namespaces)>
<!ELEMENT sitename (#PCDATA)> <!-- name of the wiki -->
<!ELEMENT base (#PCDATA)> <!-- url of the main page -->
<!ELEMENT generator (#PCDATA)> <!-- MediaWiki version string -->
<!ELEMENT case (#PCDATA)> <!-- how cases in page names are handled -->
<!-- possible values: 'first-letter' | 'case-sensitive'
'case-insensitive' option is reserved for future -->
<!ELEMENT namespaces (namespace+)> <!-- list of namespaces and prefixes -->
<!ELEMENT namespace (#PCDATA)> <!-- contains namespace prefix -->
<!ATTLIST namespace key CDATA #REQUIRED> <!-- internal namespace number -->
<!ELEMENT page (title,id?,restrictions?,(revision|upload)*)>
<!ELEMENT title (#PCDATA)> <!-- Title with namespace prefix -->
<!ELEMENT id (#PCDATA)>
<!ELEMENT restrictions (#PCDATA)> <!-- optional page restrictions -->
<!ELEMENT revision (id?,timestamp,contributor,minor?,comment?,text)>
<!ELEMENT timestamp (#PCDATA)> <!-- according to ISO8601 -->
<!ELEMENT minor EMPTY> <!-- minor flag -->
<!ELEMENT comment (#PCDATA)>
<!ELEMENT text (#PCDATA)> <!-- Wikisyntax -->
<!ATTLIST text xml:space CDATA #FIXED "preserve">
<!ELEMENT contributor ((username,id) | ip)>
<!ELEMENT username (#PCDATA)>
<!ELEMENT ip (#PCDATA)>
<!ELEMENT upload (timestamp,contributor,comment?,filename,src,size)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT src (#PCDATA)>
<!ELEMENT size (#PCDATA)>
XML 出力の手順
XML 出力を扱えるツールは多いです。 大量のページ (例えばダンプを丸ごと) の処理をしたくてもメインメモリに文書を取り込めないと、対策としてSAX ベースのパーサを使うか、イベント固有の方法に頼るしかないかもしれません。
正規表現で直接、XML コードの当該部分を処理することもできます。 他の方法より時間は節約できても、管理が困難で非推奨です。
ここに XML 書き出しに使える方法とツールを追記してください。
- XML ダンプを処理する Rust のクレート Parse Mediawiki Dump (crates.io)。 ウィキ文を樹形要素に処理する Rust のクレート Parse Wiki Text (crates.io)。
- Perlのモジュールで XML ダンプファイルを処理するには、Parse::MediaWikiDump。
- Stream ベースの XML 変換 - m:Processing MediaWiki XML with STX
- 軽い export-historyflow-expand.py というPython プログラムを当てておき、m:IBM History flow project で読み込む。
- Manual:MWDumper
詳細と実用のヒント
- 名前空間名に接頭辞が必要かどうか調べるには、
/mediawiki/siteinfo/namespaces/namespace
をご参照ください - 次の制限条件が予測されます。
sysop
- 保護されたページ
書き出しをする理由
単純に動的データベースのダウンロードを使えば済むのでは?
ある時点でのウィキペディアからの情報を表示するソフトウェアを構築しているとします。 あなたのプログラムで、異なる方法でライブバージョンの情報を表示する場合には、完成したhtmlではなく、入力に使用されるウィキコードが必要になる可能性があります。
また、すべてのデータを取得したい場合は、可能な限り最も効率的な方法でデータを移す必要があります。 ウィキメディアサーバーは、ウィキコードをHTMLに変換するためにかなりの作業を行う必要があります。 これはあなたにとってもウィキメディアサーバーにとっても時間がかかるので、単にすべてのページをスパイダーするだけではうまくいきません。
XML 形式で随時、記事を1件ずつ開くには以下にリンクします。
Special:Export/Title_of_the_article