Jump to content

手册:thumb_handler.php

From mediawiki.org
This page is a translated version of the page Manual:Thumb handler.php and the translation is 33% complete.
Outdated translations are marked like this.

描述

thumb_handler.php是一个404处理脚本,用于自动调整图片大小。例如,当浏览器请求未曾创建的缩略图时。

要使用它,请按照如下步骤,然后将$wgGenerateThumbnailOnParse 设定为false。如果您在LocalSettings.php中设置了$2,那么您同样需要设置: If you have $wgLocalFileRepo defined in LocalSettings.php, then you need to also set:

$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位于/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/[^/]+/[^/]+$ /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
		# 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;
}

参见