手册:thumb_handler.php
MediaWiki文件: thumb_handler.php | |
---|---|
位置: | / |
源代码: | master • 1.39.3 • 1.38.6 • 1.35.10 |
类: | 查找代码 • 查找文档 |
描述
thumb_handler.php是一个404处理脚本,用于自动调整图片大小。例如,当浏览器请求未曾创建的缩略图时。
要使用它,请按照如下步骤,然后将$wgGenerateThumbnailOnParse
设定为false。如果您在LocalSettings.php中设置了$wgLocalFileRepo
,那么您同样需要设置:
$wgLocalFileRepo['transformVia404'] = true;
服务器配置
Apache
当“$wgUploadPath /thumb/”中的文件不存在时,创建一个重写(rewrite)规则来调用thumb_handler.php。如果您的wiki位于“/w”目录中,以下内容适用于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/[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]/[^/]+/[^/]+$ /w/thumb_handler.php [L,QSA]
nginx
location /wiki/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
# If the file does not exist we use @thumb to run the thumb.php script
try_files $uri $uri/ @thumb;
}
}
# Thumbnail 404 handler, only called by try_files when a thumbnail does not exist
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;
}