Help:Export

From Wikipedia, the free encyclopedia

This is a copy of the master help page at Meta. Do not edit this copy.
Edits will be lost in the next update from the master page. See below for more information.


Editing
Start new pages
Page name

Referencing
Links
Piped links
Interwiki linking
Footnotes (References)

Formatting
Wikitext
Lists & Tables
Image & file uploads
Formulae

Organising
Sections
Categories
Redirects (forward)
Namespaces
Moving a page
Page size

Fixing mistakes
Reverting edits
Show preview

Saving effort
Editing shortcuts
Edit toolbar
Magic words
Templates
Variables
Calculation

Communicating
Edit summary
Talk page
Edit conflict
Minor edit

Other
Characters
Sandbox


Wiki pages can be exported in a special XML format to import into another MediaWiki installation or use it elsewise for instance for analysing the content. See also m:Syndication feeds for exporting other information but pages and Help:Import on importing pages.


Contents

How to export

There are at least four ways to export pages:

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.

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.

1. Get the names of pages to export

  • Go to Special:Allpages and choose the desired namespace.
  • Copy the list of page names to a text editor
  • Put all page names on separate lines
  • Prefix the namespace to the page names (e.g. 'Help:Contents'), unless the selected namespace is the main namespace.

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.

Exporting the full history

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 MW: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 http://www.mediawiki.org/xml/export-0.3.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). You only get the wikitext 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 [[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 [[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 "http://www.mediawiki.org/xml/export-0.3/"
  xmlns:xsi CDATA #FIXED "http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation CDATA #FIXED
    "http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd"
>
<!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

There are undoubtedly many tools which 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 just 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 prefixed defined in

/mediawiki/siteinfo/namespaces/namespace

  • Possible restrictions are
    • sysop (protected pages)

See also

  • Help:How to move a wiki to another server


edit

Wikipedia-specific help


Note: exporting the full history of pages has been disabled until further notice due to performance reasons, in the meantime you can get the full page history of pages from the database dumps — Wikimedia server administrators.


This page is a copy of the master help page at Meta (for general help information all Wikimedia projects can use), with two Wikipedia-specific templates inserted. To update the main text, edit the master help page for all projects at m:Help:Export. For Wikipedia-specific issues, use Template:Ph:Export (the extra text at the bottom of this page) or Template:Phh:Export for a Wikipedia-specific lead (text appears at the top of this page). You are welcome to copy the exact wikitext from the master page at Meta and paste it into this page at any time. To view this page in other languages see the master page at Meta.