Manual:thumb_handler.php

From Linux Web Expert

説明

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/ 内に当該のファイルがない場合は、上書きルールを作成し thumb_handler.php を呼び出します。ご利用のウィキが /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;
}

関連項目