| MediaWiki file: thumb_handler.php | |
|---|---|
| Location: | / | 
| Source code: | master • 1.40.0 • 1.39.4 • 1.35.11 | 
| Classes: | Find code • Find documentation | 
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;
Server configuration
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 for 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/[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]/[^/]+/[^/]+$ /w/thumb_handler.php [L,QSA]
nginx
location /wiki/images {
	# <translate nowrap><!--T:9--> Separate location for images/ so .php execution won't apply</translate>
	location ~ ^/w/images/thumb/(archive/)?[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/[^/]*([0-9]+)px-.*$ {
		# <translate nowrap><!--T:10--> Thumbnail handler for MediaWiki</translate>
		# <translate nowrap><!--T:11--> This location only matches on a thumbnail's url</translate>
		# <translate nowrap><!--T:12--> If the file does not exist we use <tvar|1>@thumb</> to run the <tvar|2>thumb.php</> script</translate>
		try_files $uri $uri/ @thumb;
	}
}
# <translate nowrap><!--T:13--> Thumbnail 404 handler, only called by <tvar|1>try_files</> when a thumbnail does not exist</translate>
location @thumb {
	 # <translate nowrap><!--T:14--> Do a rewrite here so that <tvar|1>thumb.php</> gets the correct arguments</translate>
	 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;
}
See also
- Manual:Thumb.php
    This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.