MediaWiki Import & Export — XML Export, Page Migration, and Interwiki Import
In this tutorial, you will learn about MediaWiki Import & Export. We cover key concepts, practical examples, and best practices to help you master this topic.
Import and export in MediaWiki enable page migration between wikis using XML dumps that include content, revisions, templates, and metadata — with interwiki import for pulling pages from remote wikis, essential for Wikipedia content reuse and wiki-to-wiki migration.
What You'll Learn
- Exporting pages as XML
- Importing XML files into a wiki
- Using Special:Export and Special:Import
- Handling images and files during migration
- Using interwiki import
- Managing user accounts during import
- Best practices for safe migration
Why It Matters
Wikis grow and change. Content needs to move between wikis — from a staging wiki to production, from an old wiki to a new installation, between different language wikis, or from a third-party wiki to yours. Manual copy-paste loses revision history, dates, and authorship. XML export preserves everything: every revision, every editor, every timestamp. The import process recreates the page with its full history intact.
Real-World Use
A DodaTech team redesigns their wiki infrastructure. The old wiki has 500 documentation pages with 2 years of revision history. Instead of manually recreating each page, they export the XML from the old wiki and import it into the new one. The import takes 10 minutes. All 500 pages appear with their full revision history, correct authorship, and original timestamps. No content is lost.
Learning Path
flowchart LR A["31: Wiki Farms"] --> B["32: Content Translation"] B --> C["33: Import & Export"] C:::current D["34: REST API"] E["35: Database Maintenance"] F["36: Logging & Monitoring"] C --> D --> E --> F classDef current fill#38bdf8,color#0f172a,stroke-width:2px
Step 1: Export Pages as XML
Using Special:Export
- Go to
Special:Exporton the source wiki - Enter the page titles (one per line):
DodaBrowser
DodaBrowser/Installation
DodaBrowser/Configuration
DodaSync
- Choose options:
- Include only the current revision: Include all revisions for full history (uncheck for only the latest)
- Include templates: Also export templates used by these pages
- Save as file: Downloads the XML file
- Click "Export"
Using the Maintenance Script
For bulk exports:
# Export a single page
php maintenance/dumpBackup.php --page="DodaBrowser" > dodaBrowser.xml
# Export multiple pages
php maintenance/dumpBackup.php \
--page="DodaBrowser" \
--page="DodaSync" \
--page="DodaZIP" > products.xml
# Export full wiki (all pages)
php maintenance/dumpBackup.php --full > full-wiki.xml
Export for Migration
For a full wiki migration, export everything:
# Export all pages with full history
php maintenance/dumpBackup.php --full --logs --uploads > full-export.xml
# Export only current revisions (faster, smaller)
php maintenance/dumpBackup.php --current > current-only.xml
Step 2: Understand the XML Format
An exported XML file looks like:
<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.11/">
<page>
<title>DodaBrowser</title>
<ns>0</ns>
<id>1</id>
<revision>
<id>10</id>
<timestamp>2026-06-15T10:30:00Z</timestamp>
<contributor>
<username>Alice</username>
<id>1</id>
</contributor>
<comment>Created product page</comment>
<origin>10</origin>
<model>wikitext</model>
<format>text/x-wiki</format>
<text xml:space="preserve">'''DodaBrowser''' is a web browser.</text>
<sha1>abc123...</sha1>
</revision>
</page>
</mediawiki>
Key elements:
<page>: Contains the page title, namespace, and all revisions<revision>: Individual edit with timestamp, contributor, and content<contributor>: Author of the revision (username or IP)
Step 3: Import XML into a Wiki
Using Special:Import
- Go to
Special:Importon the target wiki - Choose the XML file
- Select import options:
- Import interwiki pages: For importing from other wikis
- Assign edits to users: Map contributors to local accounts
- Interleave revisions: Preserve revision order
- Click "Import"
Using the Maintenance Script
# Import pages from XML
php maintenance/importDump.php < full-export.xml
# Import with progress reporting
php maintenance/importDump.php --report=1000 < full-export.xml
# Import and assign to a specific user
php maintenance/importDump.php --username="Admin" < pages.xml
Importing to a Specific Namespace
# Import pages into the Help namespace
php maintenance/importDump.php --namespaces="12" < help-pages.xml
Step 4: Handle User Accounts During Import
User accounts from the export cannot be automatically created on the target wiki.
Options for User Handling
Option 1: Create matching accounts
Before importing, create accounts on the target wiki with the same usernames. The import will match revisions to these accounts.
Option 2: Assign to a local user
Use the --username flag to assign all imported revisions to a single local account:
php maintenance/importDump.php --username="ImportBot" < export.xml
Option 3: Username prefix
Add a prefix to prevent username collisions:
php maintenance/importDump.php --username-prefix="imported_" < export.xml
Revisions by "Alice" become attributed to "imported_Alice".
Step 5: Import Images and Files
Images require separate handling because they are not included in standard page exports.
Exporting Images
# Export images as XML metadata
php maintenance/dumpUploads.php > images.xml
# Copy image files directly
cp -r images/* /target-wiki/images/
Importing Images
# Import image metadata
php maintenance/importImages.php /path/to/images/ --extensions=jpg,png,gif,svg
Complete Migration with Images
# Step 1: Export pages and images
cd /source-wiki
php maintenance/dumpBackup.php --full > full-export.xml
php maintenance/dumpBackup.php --uploads > uploads-export.xml
tar -czf images.tar.gz images/
# Step 2: Transfer to target
scp full-export.xml uploads-export.xml images.tar.gz user@target-server:/tmp/
# Step 3: Import on target
cd /target-wiki
php maintenance/importDump.php < /tmp/full-export.xml
php maintenance/importDump.php < /tmp/uploads-export.xml
tar -xzf /tmp/images.tar.gz -C images/
php maintenance/rebuildImages.php
Step 6: Interwiki Import
Import pages directly from another wiki without downloading XML files.
Enable Interwiki Import
// Enable interwiki import from trusted sources
$wgImportSources = [
'wikipedia' => [ 'en', 'fr', 'de' ],
'commons' => [ 'commons' ],
'mediawikiwiki' => [ 'mediawikiwiki' ],
];
Using Special:Import with Interwiki
- Go to
Special:Importon your wiki - Select "Import interwiki" tab
- Choose the source wiki (e.g.,
wikipedia) - Enter page title:
MediaWiki - Choose options:
- Include all revisions or just current
- Assign to local users
- Click "Import"
The page is downloaded from the remote wiki and imported into your wiki with full revision history.
Limitations
- Only pages that allow import (not restricted by the source wiki)
- Images are not imported (only text content)
- Templates referenced by the page are not automatically imported
- License Compliance required (attribution must be maintained)
Step 7: Importing Templates
When you import a page that uses templates, those templates may not exist on the target wiki.
Finding Missing Templates
After import, check for red links to templates:
- Go to the imported page
- Look for red links (missing templates)
- Export and import each missing template
Bulk Template Import
# Export all templates
php maintenance/dumpBackup.php --namespaces="10" > templates.xml
# Import templates
php maintenance/importDump.php < templates.xml
Template Migration Strategy
- Export templates first
- Import templates
- Export content pages
- Import content pages
- Verify all templates render correctly
Step 8: Post-Import Tasks
Rebuild Indexes
# Rebuild search index
php maintenance/rebuildrecentchanges.php
# Rebuild category links
php maintenance/refreshLinks.php
# Rebuild image thumbnails
php maintenance/rebuildImages.php
Verify Import
Check:
- Page count matches expected
- Revision history is intact
- Templates render correctly
- Images display properly
- Categories are populated
- Search index is rebuilt
What You Learned
Special:Exportcreates XML files with page content and historymaintenance/dumpBackup.phpprovides command-line exportSpecial:Importandmaintenance/importDump.phphandle import- User accounts require careful handling during import
- Images require separate migration
- Interwiki import pulls pages directly from remote wikis
- Templates must be imported separately
- Post-import tasks include rebuilding indexes and verifying content
In the next lesson, you'll learn about the MediaWiki REST API.
Common Mistakes
| Mistake | Why It Happens | How to Fix |
|---|---|---|
| Import fails with "XML error" | File is not valid XML or was truncated | Validate the XML file before importing. Check for truncation if the file was transferred over a network. Re-export if needed. |
| Imported pages show incorrect authorship | Users not created on target wiki | Create matching user accounts before importing, or use --username to assign all revisions to a local user. |
| Images not visible after import | Image files not copied | Images are not included in standard XML exports. Copy the images/ directory separately and run rebuildImages.php. |
| Templates render as raw wikitext | Templates not imported | Export and import templates from the source wiki. Use --namespaces="10" to include templates in the dump. |
| "Import failed: unknown namespace" | Source wiki has custom namespaces | Before importing, create matching custom namespaces on the target wiki. The namespace IDs must match between wikis. |
Practice Questions
- What information is preserved in an XML export beyond page content?
- How do you handle user account attribution when importing pages into a new wiki?
- What additional steps are required to migrate images and files between wikis?
- Challenge: Perform a complete wiki migration. Set up two MediaWiki instances (source and target). On the source wiki, create 5 pages with 3 revisions each, upload 2 images, and create 2 templates. Export the pages with full history. Export the templates. Copy the image files. On the target wiki, create matching user accounts. Import the pages, templates, and images. Verify that revision history is preserved, images display correctly, and templates render properly. Rebuild the search index and category links. Document the migration process with the exact commands used.
FAQ
Mini Project
Goal: Execute a complete wiki-to-wiki migration.
- Set up two MediaWiki instances (source on localhost/wiki1, target on localhost/wiki2)
- On source, create 5 pages with multiple revisions each
- On source, upload 3 images and create 2 templates
- Export from source:
- Full page dump with all revisions
- Template dump
- Image files (copy the images directory)
- Transfer to target
- On target, create user accounts matching source contributors
- Import pages, templates, and images
- Rebuild indexes and thumbnails
- Verify: page count, revision count, image display, template rendering
- Create a "Migration Report" page documenting the process and any issues encountered
What's Next
Import and export let you move content between wikis. Now let's explore programmatic access with the REST API.
Continue to Lesson 34: REST API — learn how to use the MediaWiki Action API and REST API for programmatic wiki access.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro