Exporting and importing images in MediaWiki

后端 未结 6 1876
梦如初夏
梦如初夏 2020-12-31 10:41

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

相关标签:
6条回答
  • 2020-12-31 10:51

    Hope this helps a bit: http://www.mediawiki.org/wiki/Manual:ImportImages.php

    0 讨论(0)
  • 2020-12-31 10:52

    - 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].

    0 讨论(0)
  • 2020-12-31 10:59

    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.

    0 讨论(0)
  • 2020-12-31 11:07

    There are a few mass upload tools available.

    Commonist - www.djini.de/software/commonist/

    Both run on the desktop and can be configured to upload to your local wiki (they are configured for Wikipedia and Wikimedia commons by default). If you are afraid to edit the content of a .jar file, I suggest you start with Commonplace.

    Another useful extension exists for Mediawiki itself.

    MultiUpload - http://www.mediawiki.org/wiki/Extension:MultiUpload

    This extension allows you to drop images in a folder and load them all at once. It supports annotations for each file if necessary and cleans up the folder once it is done. On the downside, it requires opening a shared folder on the server side.

    Commonplace - commons.wikimedia.org/wiki/Commons:Tools/Commonplace

    used to be available, but it was deprecated as of Jan. 13, 2010.

    0 讨论(0)
  • 2020-12-31 11:08

    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.

    0 讨论(0)
  • 2020-12-31 11:12

    As a committer of MediaWiki-Japi I'd like to point out:

    For the usecase to push pages including images from one wiki to another MediaWiki-Japi now has a command line mode see Issue 49 - Enable commandline interface with page transfer option

    Otherwise you can use MediaWiki-Api with the language of your choice and use the functions as you find in PushPages.java

    e.g.

    • download
    • upload
    0 讨论(0)
提交回复
热议问题