Manual:thumb_handler.php
From Linux Web Expert
MediaWiki-fájl: thumb_handler.php | |
---|---|
Könyvtár: | / |
Forráskód: | master • 1.41.1 • 1.40.3 • 1.39.7 |
Osztályok: | Kód keresése • Dokumentáció keresése |
Description
thumb_handler.php is a script to be used to automatically resize images from a 404 handler. For example, when a browser requests a thumbnail that has not been created before.
To use it, follow the steps below, then set $wgGenerateThumbnailOnParse
to false. If you have $wgLocalFileRepo
defined in LocalSettings.php, then you need to also set:
$wgLocalFileRepo['transformVia404'] = true;
Server configuration
The configuration below assumes you don't have custom file repos (at least $wgLocalFileRepo ) configured manually. In that case, you will need to adjust the path of rewrite rules according to
$wgLocalFileRepo['hashLevels']
and $wgLocalFileRepo['deletedHashLevels']
.Apache
Create a rewrite rule to call thumb_handler.php when a file in $wgUploadPath /thumb/
doesn't exist. If your wiki is in the /w directory, something like this should work for Apache:
If $wgHashedUploadDirectory is set to true
:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /w/thumb_handler.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /w/thumb_handler.php [L,QSA]
If $wgHashedUploadDirectory is set to false
:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?w/images/thumb/[^/]+/[^/]+$ /w/thumb_handler.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?w/images/thumb/archive/[^/]+/[^/]+$ /w/thumb_handler.php [L,QSA]
nginx
location /w/images {
# Separate location for images/ so .php execution won't apply
location ~ ^/w/images/thumb/(archive/)?[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/[^/]*([0-9]+)px-.*$ {
# Thumbnail handler for MediaWiki
# This location only matches on a thumbnail's url
# Ha a fájl nem létezik, a @thumbot használjuk a thumb.php szkript futtatásához
try_files $uri $uri/ @thumb;
}
}
# Bélyegkép-404-kezelő, csak akkor hívja a try_files, ha nem létezik a bélyegkép
location @thumb {
# Do a rewrite here so that thumb.php gets the correct arguments
rewrite ^/w/images/thumb/([0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/[^/]*([0-9]+)px-.*)$ /w/thumb_handler.php/$1;
rewrite ^/w/images/thumb/(archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/[^/]*([0-9]+)px-.*)$ /w/thumb_handler.php/$1;
}