مساعدة: تصدير

This page is a translated version of the page Help:Export and the translation is 14% complete.
Outdated translations are marked like this.
PD ملاحظة: بتعديلك هذه الصفحة فإنك توافق على وضع مساهمتك في الملكية العامة وفق CC0. راجع صفحات مساعدة الملكية العامة للمزيد من المعلومات.
تم استيراد بعض النسخ القديمة لهذه الصفحة تحت ترخيص CC BY-SA. الإسهامات الجديدة فقط هم PD.
PD

يمكن تصدير صفحات ويكي بتنسيق XML خاص لـ التحميل للاستيراد إلى تثبيت آخر لـ MediaWiki (إذا كانت هذه الوظيفة مفعلة في ويكي الوجهة وكان المستخدم مسؤولًا هناك)، أو استخدامها لأغراض أخرى مثل تحليل المحتوى. راجع أيضًا خلاصات الاستنساخ لتصدير معلومات أخرى غير الصفحات وHelp:Import لاستيراد الصفحات.

كيفية التصدير

هناك على الأقل أربع طرق لتصدير الصفحات:

  • الصق اسم المقالات في المربع في Special:Export أو استخدم //www.mediawiki.org/wiki/Special:Export/FULLPAGENAME.
  • سكربت النسخ الاحتياطي dumpBackup.php يقوم بتفريغ جميع صفحات الويكي في ملف XML. dumpBackup.php يعمل فقط على MediaWiki 1.5 أو الإصدارات الأحدث. يجب أن يكون لديك وصول مباشر إلى الخادم لتشغيل هذا السكربت. يتم بشكل دوري توفير نسخ من مشاريع ويكيميديا على الرابط https://dumps.wikimedia.org/.
  • هناك واجهة تُعرف باسم OAI-PMH لجلب الصفحات التي تم تعديلها منذ وقت بالنسبة لمشاريع ويكيميديا، هذه الواجهة غير متاحة للعامة; راجع Wikimedia update feed service . يحتوي OAI-PMH على تنسيق مغلف حول المقالات المصدرة الفعلية.
  • استخدم إطار عمل Pywikibot. لن يتم شرح ذلك هنا.

By default only the current version of a page is included. Optionally you can get all versions with date, time, user name and edit summary. Optionally the latest version of all templates called directly or indirectly are also exported. If you import a dump that doesn't include templates, then the resulting pages will probably render incorrectly if the templates they need do not exist on the destination wiki.

Additionally you can copy the SQL database. This is how dumps of the database were made available before MediaWiki 1.5 and it won't be explained here further.

Using 'Special:Export'

To export all pages of a namespace, for example.

Get the names of pages to export

I feel an example is better because the description below feels quite unclear.

  1. Go to Special:Allpages and choose the desired article/file.
  2. * نسخ قائمة أسماء الصفحات إلى محرر نص
  3. Put all page names on separate lines
    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.)
    2. 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.
    3. 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.
    4. 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_

  1. Prefix the namespace to the page names (e.g. 'Help:Contents'), unless the selected namespace is the main namespace.
  2. 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.

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.

Exporting the full history

Exporting the revision history may be desirable to retain authorship information and attribution. 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 .

Export format

The format of the XML file you receive is the same in all ways. It is codified in XML Schema at https://www.mediawiki.org/xml/export-0.11.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 wiki text. 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). You only get the wiki text as you get when editing the article.

Example

  <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)>

Processing XML export

Many tools can process the exported 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
  • Possible restrictions are
    • sysop - Protected pages

Why to export

Why not just use a dynamic database download?

Suppose you are building a piece of software that at certain points displays information that came from Wikipedia. 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.

To access any article in XML, one at a time, go to Special:Export/Title_of_the_article

See also