(Redirected from Thumb.php)
Jump to: navigation, search
Translate this page; This page contains changes which are not marked for translation.

Other languages:
català • ‎Deutsch • ‎Ελληνικά • ‎English • ‎español • ‎suomi • ‎français • ‎italiano • ‎日本語 • ‎Bahasa Melayu • ‎Nederlands • ‎polski • ‎português • ‎português do Brasil • ‎中文


Script used to resize images if it is configured to be done when the web browser requests the image and not when generating the page.

To use it, set $wgThumbnailScriptPathManual:$wgThumbnailScriptPath to the path of this file.

Parameters are f for file name, w for width, p for page in multipaged files (if available).


404 Handler[edit]

This script can also be used as a 404 handler to generate image thumbs when they don't exist. To use it, follow the steps below, then set $wgGenerateThumbnailOnParseManual:$wgGenerateThumbnailOnParse to false. If you have $wgLocalFileRepoManual:$wgLocalFileRepo defined in LocalSettings.php, then you need to also set:

$wgLocalFileRepo['transformVia404'] = true;

See also thumb_handler.phpManual:thumb_handler.php.


Create a rewrite rule to call this script when a file in $wgUploadPathManual:$wgUploadPath/thumb/ doesn't exist. If your wiki is in the /wiki directory, something like this should work on apache:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb.php?f=$1&width=$2 [L,QSA,B]
# If your $wgHashedUploadDirectory is false, remove the first two steps after thumb/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
# If your $wgHashedUploadDirectory is false, remove the first two steps after thumb/archive/


location /wiki/images {
	# Separate location for images/ so .php execution won't apply
	location ~ ^/wiki/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 ^/wiki/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /wiki/thumb.php?f=$1&width=$2;
	rewrite ^/wiki/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /wiki/thumb.php?f=$1&width=$2&archived=1;
	# Run the thumb.php script
	include /etc/nginx/fastcgi_params;
	fastcgi_param SCRIPT_FILENAME	$document_root/wiki/thumb.php;
	fastcgi_pass unix:/var/run/php5-fpm-$username.sock;

Scripted transform[edit]

Just add the following code to the bottom of LocalSettings.phpManual:LocalSettings.php.

$wgThumbnailScriptPath = "{$wgScriptPath}/thumb{$wgScriptExtension}";

No apache config changes needed. This will cause thumb.php to either return the file if its already been rendered, or render the file on demand if needed.

See also[edit]