|MediaWiki file: importImages.php|
|Source code:||master • 1.33.1 • 1.32.5 • 1.31.5|
importImages.php is a script which uploads images to MediaWiki from the same computer where the wiki is configured. It doesn't do a remote upload.
Upload with default comment "Importing file"
php maintenance/importImages.php /path/to/images/directory
Upload with comment "[[Category:Sunflowers in full bloom]]"
php maintenance/importImages.php /path/to/images/directory --comment="[[Category:Sunflowers_in_full_bloom]]"
Importimages.php will not search and upload images in sub-directories (directory recursion) by default
An example of what a successful import of one image (Foo.jpg) looks like:
|root@f345:/home/t/public_html/mywikisite/public/w/maintenance# php importImages.php /home/t/public_html/import --extensions=svg,png,jpg,jpeg,gif,bmp,SVG,PNG,JPG,JPEG,GIF,BMP
apacheuser (Commonly either
www-data). Otherwise the uploaded files will be owned by the person who ran the script, which may prevent MediaWiki from being able to move, delete, or otherwise manipulate the files later on.
|MediaWiki version:||≥ 1.21|
$ php importImages.php Import Images Imports images and other media files into the wiki USAGE: php importImages.php [options] <dir> <dir> : Path to the directory containing images to be imported Options: --extensions=<exts> Comma-separated list of allowable extensions, defaults to $wgFileExtensions. --overwrite Overwrite existing images with the same name (default is to skip them). --limit=<num> Limit the number of images to process. Ignored or skipped images are not counted. --from=<name> Ignore all files until the one with the given name. Useful for resuming aborted imports. <name> should be the file's canonical database form. --skip-dupes Skip images that were already uploaded under a different name (check SHA1) --search-recursively Search recursively for files in subdirectories. --sleep=<sec> Sleep between files. Useful mostly for debugging. --user=<username> Set username of uploader, default 'Maintenance script'. --check-userblock Check if the user got blocked during import. --comment=<text> Set file description, default 'Importing file'. --comment-file=<file> Set description to the content of <file>. --comment-ext=<ext> Causes the description for each file to be loaded from a file with the same name, but the extension <ext>. If a global description is also given, it is appended. --license=<code> Use an optional license template. --dry Dry run, don't import anything. --protect=<protect> Specify the protect value (autoconfirmed,sysop). --summary=<summary> Upload summary, description will be used if not provided. --timestamp=<timestamp> Override upload time/date, all MediaWiki timestamp formats are accepted. --unprotect Unprotects all uploaded images. --source-wiki-url If specified, take User and Comment data for each imported file from this URL. For example, --source-wiki-url="https://en.wikipedia.org/."
someFile with __weird_ spaces.png, the correct argument would be
Common error messagesEdit
Could not open lock fileEdit
chmod -R 777 images (even if it was already set to 755, sometimes it needs to be set to 777)
Does not find the picture to uploadEdit
Example where the script doesn't find any picture to upload:
vi-notebook:/var/lib/mediawiki1.7# php maintenance/importImages.php /store/wiki/absurd_pic jpg Import Images Warning: Invalid argument supplied for foreach() in /usr/share/mediawiki1.7/maintenance/importImages.php on line 34
Incorrect folder path
t@f66677:~/public_html/dead.com/public/w/maintenance$ php importImages.php /m gif bmp PNG JPG GIF BMP Import Images No suitable files could be found for import.
Usually this is because the path to the folder is incorrect.
Upload failed errorEdit
login as: ideakwty
|"No suitable files could be found for import." error when user does not have the privileges to upload the pictures|
The following error can be caused by two issues:
- Directory permissions needs to be changed, and/or
- user does not have the privileges to upload the pictures
Problem 1: Directory permissions needs to be changed
- Solution: Change directory's mode
- chmod four folders to 777:
- images/thumb and
- If it hasn't already been done, in LocalSettings.php, uncomment the line
$wgHashedUploadDirectory = false;by removing the # in front of the line.
Problem 2: user does not have the privileges to upload the pictures
Skipping existing picturesEdit
By default, ImportImages.php will not overwrite pictures. If a picture with the same name already exists on the wiki, you will get this error:
php importImages.php /home gif bmp PNG JPG GIF BMP Import Images Dadtest.jpg exists, skipping Found: 1 Skipped: 1
To overwrite any images type:
php importImages.php /home gif bmp PNG JPG GIF BMP --overwrite
The result will be:
Import Images Dadtest.jpg exists, overwriting...done. Found: 1 Overwritten: 1