Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting and importing images in MediaWiki

How do I export and import images from and into a MediaWiki?

like image 734
Paradius Avatar asked Jun 16 '09 15:06

Paradius


People also ask

How do I export MediaWiki pages?

Perform the exportEditGo to Special:Export and paste all your page names into the textbox, making sure there are no empty lines. Save the resulting XML to a file using your browser's save facility.

How do I export content from Wikipedia page?

Navigate to the Wiki Page you want to export. Export to PDF in the drop-down menu. The Export to PDF dialog box appears. Select your export options and click Export.

How do you import in Wikipedia?

To import one or more pages from a wiki, go to the special "Import pages" page which is available to administrators on all wikis.


1 Answers

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.

like image 198
5 revs, 2 users 99% Avatar answered Sep 26 '22 02:09

5 revs, 2 users 99%