手册:thumb_handler.php
Appearance
Outdated translations are marked like this.
| MediaWiki文件: thumb_handler.php | |
|---|---|
| 位置: | / |
| 源代码: | master • 1.45.1 • 1.44.3 • 1.43.6 |
| 类: | 查找代码 • 查找帮助文档 |
描述
thumb_handler.php是一个404处理脚本,用于自动调整图片大小。例如,当浏览器请求未曾创建的缩略图时。
要使用此脚本,请按照如下步骤,然后将$wgGenerateThumbnailOnParse设置为false。
如果您在LocalSettings.php中定义了$wgLocalFileRepo,则您还需要设置:
$wgLocalFileRepo['transformVia404'] = true;
服务器配置
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
当$wgUploadPath/thumb/中的文件不存在时,创建一个重写(rewrite)规则来调用thumb_handler.php。如果您的wiki位于$3目录中,以下内容适用于Apache:
If your wiki is in the /w directory, something like this should work for Apache:
如果$wgHashedUploadDirectory设定为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]
如果$wgHashedUploadDirectory设定为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
# 如果文件不存在,我们用@thumb执行脚本thumb.php:
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;
}
Caddy
# Create a named matcher that matches on non-existing files.
@thumb404 {
path /w/images/thumb/*
not file
}
# Thumbnail 404 handler, only called by when a thumbnail does not exist.
rewrite @thumb404 /w/thumb_handler.php