How to transfer pages in MediaWiki

If you want to transfer pages from one MediaWiki site to another, you can easily do that using one of the available methods. As you know the pages on a MediaWiki site are grouped into namespaces. The main articles/pages belong to the Main namespace, the discussion pages for the articles belong to the Talk namespace, the personal pages of users to the User namespace etc. You can transfer the pages from any or from all of the namespaces.

There are different ways you can do this. In this article we'll briefly go over how to do it with the built-in frontend tools and also how to do it via SSH. For some more details and screenshots you can also read the tutorial on how to export and import pages in MediaWiki.

Export Pages with the Built-In Export Feature

MediaWiki has a built-in tool for exporting pages. By default all users are allowed to use it. Depending on how big the pages are this tool is not suitable for exporting more than a few hundred pages at a time. If you have more pages to export, you can either export them in portions or you can use another method.

In order for you to export pages you need the exact names of the pages that you want to export. So if there are more than a few pages to export, first you should make a list of the pages. To view the titles of all the available pages, go to Tools menu on the left>Special pages button>List of pages section on the next page>All pages button. This will automatically show the titles of the pages from the Main namespace. You can use the options at the top to view the pages from the other namespaces. From that page you can copy the titles and paste them into a text editor.

To open the Export tool, go to Tools menu on the left>Special pages button>Page tools section>Export pages button. On the following page there's a text area in which you have to put the list with the page titles. Make sure that there's one title per line. By marking/unmarking the checkbox Include only the current revision, not the full history that's under the text area you can select whether to export only the current edit of each page or all the revisions of each page. Then click on the Export button. The pages are exported into an XML file that you have to download on your local computer. A window will pop out with which you can do that. If needed, you can edit the XML file before you import it. However if you're not sure what you're doing this could potentially mess things up.

Import Pages with the Built-in Import Feature

The frontend also has an Import tool with which pages can be imported. By default it can be used only by administrators/sysops. With that tool you can import the XML file with the pages that you previously exported. To open the tool, go to Tools menu on the left>Special pages button>Page tools section>Import pages button. On the page that opens click on the Browse button and use the window that pops out to find on your local computer the XML file with the pages. After that click on the Upload file button at the bottom. When you do this a list will be shown with the imported pages and the number of imported revisions per page. As with the tool for exporting, the Import tool is not suitable for importing a very large number of pages per import (e.g. more than a few hundred).

If the pages have images and you want them to be displayed on the new site you have to transfer them as well. After you import the pages it's a good idea to optimize the database and optionally to regenerate the Recent changes list (this is done via SSH by executing the script rebuildrecentchanges.php).

Disable The Export Tool and Change Permissions for the Import Tool

By default the frontend Export tool can be used by anybody. If you want to disable it, you can do it by putting the following code at the end of the LocalSettings.php file of your MediaWiki:

function removeExportSpecial(&$aSpecialPages)
        return true;
$wgHooks['SpecialPage_initList'][] = 'removeExportSpecial';

By default, only administrators/sysops can use the Import tool. To disable it for them, and thus for the whole site, add the following lines on a new line in LocalSettings.php:

$wgGroupPermissions['sysop']['import'] = false;

$wgGroupPermissions['sysop']['importupload'] = false;

If instead of disabling the Import tool you want users from other user groups to be able to use it, replace sysop with the name of the user group and instead of false put true. If the name is of a group that doesn't exist, a new group with the right to import pages will be create; in case the name of that new group contains more than one word, separate them with underscores or hyphens. You can assign users to that group from Tools menu on the left>Special pages button>Users and rights section>User rights management button.

Export Pages via SSH

Another method to export pages is via SSH. This is a method that will perhaps be a little confusing to the average user who hasn't used SSH, but it's in fact quite a convenient and easy to use method. All HostKnox customers have free SSH access.

After you log in to your account via SSH change the current working directory to the maintenance folder of your MediaWiki. If the application is installed directly in the public_html directory you can do that with the command cd public_html/maintenance. Then you can export all the pages (from every namespace) with all the revisions with the command:

php dumpBackup.php --full > pages.xml

This will create an XML file called pages.xml which will contain the pages. You can use another name for the file. There are some options that you can use with the command with which you can configure exactly what is exported (e.g. the pages only from a particular namespace). To see the available options, execute the command php dumpBackup.php.

Import Pages via SSH

To import pages via SSH, upload on the MediaWiki hosting account the XML file with the pages. Then to import the file and respectively the pages execute the following command:

php importDump.php < pages.xml

With the above example command it's assumed that you have changed the current working directory to the maintenance directory of the particular MediaWiki installation; that's where the importDump.php file is. It's also assumed that the XML file with the exported pages is also in that directory. The name pages.xml in the above command is just an example. Replace it with the actual name of the file. To view the available options that you can use with the command, execute just php importDump.php.

You may also find useful our other tutorials related to pages (or their respective shorter article versions):

Was this answer helpful?

 Print this Article

Also Read