Help:导出

From mediawiki.org
This page is a translated version of the page Help:Export and the translation is 62% complete.
Outdated translations are marked like this.
PD 注意:當您編輯本頁面時,即同意以CC0協議授權您的貢獻。您可以在公有領域帮助页面找到更多信息。
此頁面的部分舊修訂版本是在知识共享署名-相同方式共享(CC BY-SA)許可下导入的。 只有新的貢獻採用公有領域授權。
PD

Wiki 页面可以被导出到一种特别的XML格式。导出的XML可以被导入到另一个MediaWiki实例(条件是导入功能在该实例上被启用,且用户是该实例的系统管理员),或被用于其他用途,例如对内容进行分析。 要了解导出页面其他信息,而不是页面本身,请参见m:Syndication feeds ;要了解导入页面,请参见Help:Import

如何导出

有至少4种导出页面的方式:

  • Special:Export的框中粘贴文章的名称或使用//www.mediawiki.org/wiki/Special:Export/FULLPAGENAME。

dumpBackup.php仅适用于MediaWiki 1.5或更高版本。 您需要直接访问服务器才能运行此脚本。 维基媒体项目的转储定期以https://dumps.wikimedia.org/的形式提供。

    • 注意:您可能需要配置AdminSettings.php才能成功运行dumpBackup.php。 参见m:MediaWiki以获取更多信息。
  • OAI-PMH用于定期获取自特定时间以来已修改的页面的界面。 对于维基媒体项目,此界面不公开,参见Wikimedia update feed service 。 OAI-PMH包含围绕实际导出文章的包装格式。
  • 使用Pywikibot框架。这里不会解释。

默认情况下,仅包含页面的当前版本。 您可以选择使用日期,时间,用户名和编辑摘要获取所有版本。 可选地,还可以导出直接或间接调用的所有模板的最新版本。

此外,您可以复制SQL数据库。 这是在MediaWiki 1.5之前使数据库的转储可用的方式,这里不再对其进行解释。

使用“Special:Export”

例如,要导出命名空间的所有页面。

1 获取要导出的页面的名称

我觉得一个例子更好,因为下面的描述感觉很不清楚。

  1. 转到Special:Allpages并选择所需的文章/文件。
  2. 将页面名称列表复制到文本编辑器
  3. 将所有页面名称放在单独的行上
    1. 如果你使用所需的名称复制渲染页面的部分,你可以相对快速地实现这一点,并将其粘贴到Word中 - 使用paste special作为无格式文本,然后打开替换函数(CTRL+H),输入^t找到什么,在替换为^p然后点击全部替换按钮。 (这取决于页面名称之间的选项卡,这些通常是由于页面名称位于html-source中的td-tags内部而导致的。)
    2. 文本编辑器Vim还允许快速修复换行符:在粘贴整个列表后,运行命令:1,$s/\t/\r/g以通过回车替换所有选项卡然后:1,$s/^\n//g到删除仅包含换行符的每一行。
    3. 另一种方法是将格式化文本复制到任何暴露html的编辑器中。 删除所有‎<tr>‎</tr>标签并将所有‎<td>标签替换为<tr><td>,并将‎<td>标签替换为</td></tr>,然后将html解析为所需格式。
    4. 如果您具有对服务器的shell和mysql访问权限,则可以使用此脚本:
#
mysql -umike -pmikespassword -hlocalhost wikidbname 
select page_title from wiki_page where page_namespace=0
EOF

注意,将mike和mikespassword替换为您自己的。此外,此示例显示带有前缀wiki_的表

  1. 将命名空间添加到页面名称(例如帮助:内容),除非所选命名空间是主命名空间。
  2. 对其他命名空间重复上述步骤(例如分类和模板)

PostgreSQL数据库的类似脚本如下所示:

$ psql -At -U wikiuser -h localhost wikidb -c "select page_title from mediawiki.page"

注意,替换你自己Wiki用户,数据库会提示你输入密码。 此示例显示没有前缀wiki_的表,并且将命名空间指定为表名的一部分。

或者,对于可以访问安装了Python的计算机的人来说,这是一种快速方法:

  1. 转到Special:Allpages并选择所需的文章/文件。
  2. 将整个网页保存为“index.php.htm”。 有些wiki可能拥有的页数超过AllPages的一个屏幕; 您需要保存每个页面。
  3. 在与保存文件相同的目录中运行export_all_helper.py。 您可能希望将输出传递给文件; 例如 python export_all_helper.py > main将其发送到名为“main”的文件。
  4. 保存脚本输出的页面名称。

2.执行导出

  • 转到Special:Export并将所有页面名称粘贴到文本框中,确保没有空行。
  • 点击“提交请求”
  • 使用浏览器的保存工具将生成的XML保存到文件中。

并且最后……

  • 在文本编辑器中打开XML文件。 滚动到底部以检查错误消息

现在您可以将此XML文件用于执行导入

完整导出历史

Exporting the revision history may be desirable to retain authorship information and attribution. Special:Export界面中的复选框选择是导出完整历史记录(文章的所有版本)还是最新版本的文章。 最多返回100个修订版,其他修订可以按Parameters to Special:Export 的要求详细说明。


导出格式

您收到的XML文件的格式在所有方面都是相同的。 It is codified in XML Schema at https://www.mediawiki.org/xml/export-0.10.xsd This format is not intended for viewing in a web browser. Some browsers show you pretty-printed XML with "+" and "-" links to view or hide selected parts. Alternatively the XML-source can be viewed using the "view source" feature of the browser, or after saving the XML file locally, with a program of choice. If you directly read the XML source it won't be difficult to find the actual wikitext. If you don't use a special XML editor "<" and ">" appear as &lt; and &gt;, to avoid a conflict with XML tags; to avoid ambiguity, "&" is coded as "&amp;".

In the current version the export format does not contain an XML replacement of wiki markup (see Wikipedia DTD for an older proposal). 你只得到你当编辑wikitext的第。

  <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

Here is an unofficial, short Document Type Definition version of the format. If you don't know what a DTD is just ignore it.

<!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。 If you process a large number of pages (for instance a whole dump) you probably won't be able to get the document in main memory so you will need a parser based on SAX or other event-driven methods.

You can also use regular expressions to directly process parts of the XML code. This may be faster than other methods but not recommended because it's difficult to maintain.

Please list methods and tools for processing XML export here:


Details and practical advice

  • To determine the namespace of a page you have to match its title to the prefixes defined in

/mediawiki/siteinfo/namespaces/namespace

  • 可能的限制
    • sysop - 保护页面

为什么要导出

为什么不只是使用动态数据库下载呢?

假设您正在构建一个软件,在某些点上显示来自维基百科的信息。 If you want your program to display the information in a different way than can be seen in the live version, you'll probably need the wikicode that is used to enter it, instead of the finished html.

Also if you want to get all of the data, you'll probably want to transfer it in the most efficient way that's possible. The Wikimedia servers need to do quite a bit of work to convert the wikicode into html. That's time consuming both for you and for the Wikimedia servers, so simply spidering all pages is not the way to go.

要访问XML中的任何文章,一次一个,链接到:

Special:Export/Title_of_the_article

参阅