Manuel: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 57% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎polski • ‎português • ‎português do Brasil • ‎中文 • ‎日本語

Description

thumb_handler.php is a script to be used to automatically resize images from a 404 handler. For example, when a browser requests a thumbnail that has not been created before.

To use it, follow the steps below, then set $wgGenerateThumbnailOnParse to false. If you have $wgLocalFileRepo defined in LocalSettings.php, then you need to also set:

$wgLocalFileRepo['transformVia404'] = true;

Configuration du serveur

Apache

Create a rewrite rule to call thumb_handler.php when a file in $wgUploadPath /thumb/ doesn't exist. If your wiki is in the /w directory, something like this should work on 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?f=$1&width=$2;
	rewrite ^/w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb_handler.php?f=$1&width=$2&archived=1;
	
	# Run the thumb.php script
	include /etc/nginx/fastcgi_params;
	fastcgi_param SCRIPT_FILENAME	$document_root/w/thumb_handler.php;
	#fastcgi_pass 127.0.0.1:9000;
	fastcgi_pass unix:/var/run/php5-fpm-$username.sock;
}

Voir aussi