Manual:importImages.php

From mediawiki.org
This page is a translated version of the page Manual:ImportImages.php and the translation is 30% complete.

importImages.php は、MediaWiki ウィキが構成されている同じコンピューターから、MediaWiki に画像をアップロードする スクリプト です。 $wgForeignFileRepos が正しく設定されている場合、もしくはそれを正しく設定する拡張機能、例えば AWS (S3) を使用している場合、リモートアップロードが行われます。

ファイル ページにファイルの説明も取り込む場合、importImages.php を実行する前に行ってください。 そうしないと、ファイルの説明はページの履歴の取り込みの下に埋もれてしまいます。 間違えた場合は、FixFileDescriptionPagesBot.php のようなボット スクリプトで修正できます。

既定のコメント「Importing file」と既定の利用者「Maintenance script」でアップロードします:

php maintenance/importImages.php /path/to/images/directory

Upload with custom comment "Importing files from local file repository" and default user "Maintenance script":

php maintenance/importImages.php /path/to/images/directory --comment="Importing files from local file repository"

Upload with custom comment "Importing files from local file repository" and custom user "Upload admin" (which must already exist, or an error will occur):

php maintenance/importImages.php /path/to/images/directory --comment="Importing files from local file repository" --user="アップロード管理者"

importImages.php will not search and upload images in sub-directories (directory recursion) by default. Therefore upload with custom comment "Importing files from local file repository", custom user "Upload admin": and recursively search for files in subdirectories:

php maintenance/importImages.php /path/to/images/directory --comment="Importing files from local file repository" --user="アップロード管理者" --search-recursively
警告 警告: If this script is being used to import files from a MediaWiki installation's file directory with the --search-recursively option, be careful to skip any subdirectories other than \0\9 and \a\f (in particular, any \archive or \deleted subdirectories will be for deleted files, and the \thumb subdirectory has generated thumbnails).

importImages.php will not overwrite images if an image with the same name already exists on the wiki. Therefore upload with custom comment "Importing files from local file repository", custom user "Upload admin" and overwrite existing images:

php maintenance/importImages.php /path/to/images/directory --comment="Importing files from local file repository" --user="アップロード管理者" --overwrite

The same as above but only overwriting the given image types, e.g. pdf:

php maintenance/importImages.php /path/to/images/directory --comment="Importing files from local file repository" --user="アップロード管理者" --overwrite --extensions=pdf

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

Import Images

Importing Foo.jpg...done.

Found: 1

Added: 1

root@f345:/home/t/public_html/mywikisite/public/w/maintenance#

It is probably a good idea to run this script as the apache user (Commonly either apache or 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 バージョン:
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
オプション 説明 既定 必須かどうか
--dir Path to the directory containing images to be imported 省略可能
--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=<name> 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. The 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 'Maintenance script' 省略可能
--check-userblock Check if the user got blocked during import 省略可能
--comment=<text> Set file description 'Importing file' 省略可能
--comment-file=<file> Set description to the content of this file 省略可能
--comment-ext=<ext> Causes the description for each file to be loaded from a file with the same name, but the extension provided. If a global description is also given, it is appended. 省略可能
--summary=<sumary> Upload summary, description will be used if not provided 省略可能
--license Use an optional license template 省略可能
--timestamp=<timestamp> Override upload time/date, all MediaWiki timestamp formats are accepted false 省略可能
--protect=<protect> Specify the protect value (autoconfirmed, sysop) 省略可能
--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/w/ 省略可能
--dry Dry run, don't import anything 省略可能
--comment-ext defines a file extension like .meta that contains the file comment, i.e. the content of the wiki-metadata-page associated with each imported file. This supports per-file metadata, whereas the --comment option supports only per-import metadata. The value of --comment-ext works with or without a leading dot (.meta as well as meta), the value may be quoted or not. The associated file is searched both as appended and substituted extension. Thus, importing x.jpg and setting "--comment-ext meta" or "--comment-ext=meta" either of x.meta or x.jpg.meta will be used to set the initial metadata page (i.e. the page shown for File:x.jpg).
The "canonical database form" required by "--from" is obtained from the file name by capitalizing the first letter, replacing all spaces with underscores, and then replacing multiple consecutive underscores with one underscore. For example, to start with the file someFile with __weird_ spaces.png, the correct argument would be --from=SomeFile_with_weird_spaces.png

Troubleshooting

Could not open lock file

Try 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 upload

Example where the script does not 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 error

login as: ideakwty
ideakwty@164.413.451.184's password:
[ideakwty@server98 ~]$ cd public_html/youareapuppet.com/mw/maintenance
[ideakwty@server98 maintenance]$ php importImages.php /public_html/TO svg png jpg jpeg gif bmp SVG PNG JPG JPEG GIF BMP
Import Images

No suitable files could be found for import.
[ideakwty@server98 maintenance]$

"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:

  1. Directory permissions needs to be changed, and/or
  2. user does not have the privileges to upload the pictures

Problem 1: Directory permissions needs to be changed

Solution: Change directory's mode
changing chmod in winSCP
  1. chmod four folders to 777:
    1. images,
    2. images/temp,
    3. images/thumb and
    4. images/archive
  2. 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

Solution: switch users or change user upload privileges.

関連項目