Příručka:ImportImages.php
Soubor MediaWiki: importImages.php | |
---|---|
Lokalita: | maintenance/ |
Zdrojový kód: | master • 1.41.1 • 1.40.3 • 1.39.7 |
Třídy: | ImportImages |
importImages.php je script, který nahrává obrázky do MediaWiki ze stejného počítače, kde je konfigurována wiki. Pokud je konfigurační parametr $wgForeignFileRepos správně nakonfigurován, nebo pokud používáte rozšíření, které jej správně konfiguruje, jako je rozšíření AWS (S3) , provede vzdálené nahrávání.
Příklady
Nahrajte s výchozím komentářem "Importing file" a výchozím uživatelem "Maintenance script":
php maintenance/importImages.php /path/to/images/directory
Nahrajte s vlastním komentářem "Import souborů z místního úložiště souborů" a výchozím uživatelem "Maintenance script":
php maintenance/importImages.php /path/to/images/directory --comment="Import souborů z místního úložiště souborů"
Nahrajte s vlastním komentářem "Import souborů z místního úložiště souborů" a vlastním uživatelem "Nahraný admin" (který již musí existovat, jinak dojde k chybě):
php maintenance/importImages.php /path/to/images/directory --comment="Import souborů z místního úložiště souborů" --user="Nahraný admin"
importImages.php
nebude ve výchozím nastavení vyhledávat a nahrávat obrázky v podadresářích (rekurze adresáře).
Proto nahrajte s vlastním komentářem "Import souborů z místního úložiště souborů", vlastní uživatel "Nahraný admin": a rekurzivně vyhledejte soubory v podadresářích:
php maintenance/importImages.php /path/to/images/directory --comment="Import souborů z místního úložiště souborů" --user="Nahraný admin" --search-recursively
importImages.php nepřepíše obrázky, pokud obrázek se stejným názvem již na wiki existuje. Proto nahrajte s vlastním komentářem "$1", vlastním uživatelem "$2" a přepište existující obrázky:
php maintenance/importImages.php /path/to/images/directory --comment="Importing files from local file repository" --user="Upload admin" --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="Upload admin" --overwrite --extensions=pdf
Příklad, jak vypadá úspěšný import jednoho obrázku (Foo.jpg):
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# |
apache
(běžně buď apache
nebo www-data
). V opačném případě budou nahrané soubory ve vlastnictví osoby, která skript spustila, což může později zabránit MediaWiki v možnosti přesunovat, mazat nebo jinak manipulovat se soubory.
Argumenty
Verze 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
Option | Description | Default | Required? |
---|---|---|---|
--dir | Path to the directory containing images to be imported | Volitelné | |
--extensions=<exts> | Comma-separated list of allowable extensions, defaults to $wgFileExtensions | Volitelné | |
--overwrite | Overwrite existing images with the same name (default is to skip them) | Volitelné | |
--limit=<name> | Limit the number of images to process. Ignored or skipped images are not counted | Volitelné | |
--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. | Volitelné | |
--skip-dupes | Skip images that were already uploaded under a different name (check SHA1) | Volitelné | |
--search-recursively | Search recursively for files in subdirectories | Volitelné | |
--sleep=<sec> | Sleep between files. Useful mostly for debugging | Volitelné | |
--user=<username> | Set username of uploader | 'Maintenance script' |
Volitelné |
--check-userblock | Check if the user got blocked during import | Volitelné | |
--comment=<text> | Set file description | 'Importing file' |
Volitelné |
--comment-file=<file> | Set description to the content of this file | Volitelné | |
--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. | Volitelné | |
--summary=<sumary> | Upload summary, description will be used if not provided | Volitelné | |
--license | Use an optional license template | Volitelné | |
--timestamp=<timestamp> | Override upload time/date, all MediaWiki timestamp formats are accepted | false |
Volitelné |
--protect=<protect> | Specify the protect value (autoconfirmed, sysop) | Volitelné | |
--unprotect | Unprotects all uploaded images | Volitelné | |
--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/
|
Volitelné | |
--dry | Dry run, don't import anything | Volitelné |
--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).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 |
"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,
- images/temp,
- images/thumb and
- images/archive
- 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
Související odkazy
- importDump.php - pro import stránek
- dumpBackup.php - pro export stránek