Exporting and importing images in MediaWiki

- Export ALL:

You can get all pages and all images from a MediaWiki web using [API], even you are not the owner of the web (of course when the owner hasn't disable this function):

Step 1: Using API to get all pages title and all images url. You can write some code to do it automatically.

Step 2: Next you use [Special:Export] to export all pages with the titles you got, and use wget to get all images you had links (like this wget -i img-list.txt).

- Import ALL:

Step 1: Import pages using [Special:Import]

Step 2: Import images using [Manual:ImportImages.php].


Terminal solutions

MediaWiki administrator, at server's terminal, can perform maintenance tasks using the Maintenance scripts framework. New Mediawiki versions run all standard scripts in the tasks described below, but old versions have some bugs or not have all moderns scripts: check the version number by grep wgVersion includes/DefaultSettings.php.

Note: all cited (below) scripts have also --help option, for instance
php maintenance/importImages.php --help

Original image folder

Users upload files through the Special:Upload page; administrators can configure the allowed file types through an extension whitelist. Once uploaded, files are stored in a folder on the file system, and thumbnails in a dedicated thumb directory.

The Mediawiki's images folder can be zipped with zip -r ~/Mediafiles.zip images command, but this zip is not so good:

  • there are a lot of expurious files: "deleted files" and "old files" (not the current) with filenames as 20160627184943!MyFig.png, and thumbnails as MyFig.png/120px-MyFig.jpg.

  • for data-interchange or long-term preservation porpurses, it is invalid... The ugly images/?/??/* folder format is not suitable, as usual "all image files in only one folder".

Images export/import

For "Exporting and Importing" all current images in one folder at MediaWiki server's terminal, there are a step-by-step single procedure.

Step-1: generate the image dumps using dumpUploads (with --local or --shared options when preservation need), that creates a txt list of all image filenames in use.

mkdir /tmp/workingBackupMediaFiles
php maintenance/dumpUploads.php \
   | sed 's~mwstore://local-backend/local-public~./images~' \
   | xargs cp -t /tmp/workingBackupMediaFiles
zip -r ~/Mediafiles.zip /tmp/workingBackupMediaFiles
rm -r /tmp/workingBackupMediaFiles

The command results in a standard zip file of your image backup folder, Mediafiles.zip at yor user root directory (~/).

NOTE: if you are not worried about the ugly folder strutcture, a more direct way is

 php maintenance/dumpUploads.php \
   | sed 's~mwstore://local-backend/local-public~./images~' \
   | zip ~/Mediafiles.zip -@

according Mediawiki version the --base=./ option will work fine and you can remove the sed command of the pipe.

Step-2: need a backup? installing a copy of the images? ... you need only Mediafiles.zip, and the Mediawiki installed, with no contents... If the Wiki have contents, check problems with filename conflicks (!). Another problem is configuration of file formats and permissions, that must be the same or broader in the new Wiki, see Manual:Configuring file uploads.

Step-3: restore the dumps (to the new Wiki), with the maintenance tools. Supposing that you used step-1 to export and preserve in a zip file,

 unzip ~/Mediafiles.zip -d /tmp/workingBackupMediaFiles
 php maintenance/importImages.php  /tmp/workingBackupMediaFiles
 rm -r /tmp/workingBackupMediaFiles 
 php maintenance/update.php
 php maintenance/rebuildall.php

That is all. Check, navegating in your new Wiki's Special:NewFiles.


The full export or preservation

For exporting "ALL images and ALL articles" of your old MediaWiki, for full backup or content preservation. Add some procedures at each step:

Step-1: ... see above step-1... and, to generate the text-content dumps from the old Wiki

php maintenance/dumpBackup.php --full | gzip > ~/dumpContent.xml.gz

Note: instead of --full you can use the --current option.

Step-2: ... you need dumpContent.xml.zip and Mediafiles.zip... from the old Wiki. Suppose both zip files at your ~ folder.

Step-3: run in your new Wiki

 unzip ~/Mediafiles.zip -d /tmp/workingBackupMediaFiles
 gunzip -c  ~/dumpContent.xml.gz 
   | php maintenance/importDump.php  --no-updates \
   --image-base-path=/tmp/workingBackupMediaFiles
 rm -r /tmp/workingBackupMediaFiles 
 php maintenance/update.php
 php maintenance/rebuildall.php

That is all. Check also Special:AllPages of the new Wiki.


There is no automatic way to export images like you export pages, you have to right click on them, and choose "save image". To get the history of the Image page, use the Special:Export page.

To import images use the Special:Upload page on your wiki. If you have lots of them, you can use the Import Images script. Note: you generally have to be in the sysop group to upload images.