手册:thumb_handler.php

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Thumb handler.php and the translation is 47% complete.
Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎polski • ‎português do Brasil • ‎中文 • ‎日本語

描述

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

要使用它,请按照如下步骤,然后将$wgGenerateThumbnailOnParse 设定为false。如果您在LocalSettings.php中设置了$wgLocalFileRepo ,那么您同样需要设置:

$wgLocalFileRepo['transformVia404'] = true;

服务器配置

Apache

当“$wgUploadPath /thumb/”中的文件不存在时,创建一个重写(rewrite)规则来调用thumb_handler.php。如果您的wiki位于“/w”目录中,以下内容适用于apache:

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]
# If your $wgHashedUploadDirectory is false, remove the first two steps after thumb/

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 your $wgHashedUploadDirectory is false, remove the first two steps after thumb/archive/

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;
}

参见