MediaWiki  1.34.0
thumb.php File Reference

PHP script to stream out an image thumbnail. More...

Go to the source code of this file.

Functions

 wfExtractThumbParams ( $file, $params)
 Convert a thumbnail name (122px-foo.png) to parameters, using file handler. More...
 
 wfExtractThumbRequestInfo ( $thumbRel)
 Convert pathinfo type parameter, into normal request parameters. More...
 
 wfGenerateThumbnail (File $file, array $params, $thumbName, $thumbPath)
 Actually try to generate a new thumbnail. More...
 
 wfProxyThumbnailRequest ( $img, $thumbName)
 Proxies thumbnail request to a service that handles thumbnailing. More...
 
 wfStreamThumb (array $params)
 Stream a thumbnail specified by parameters. More...
 
 wfThumbError ( $status, $msgHtml, $msgText=null, $context=[])
 Output a thumbnail generation error message. More...
 
 wfThumbErrorText ( $status, $msgText)
 Output a thumbnail generation error message. More...
 
 wfThumbHandle404 ()
 Handle a thumbnail request via thumbnail file URL. More...
 

Variables

 $mediawiki = new MediaWiki()
 
 $wgTrivialMimeDetection = true
 
if(defined( 'THUMB_HANDLER')) else
 
const MW_ENTRY_POINT 'thumb'
 
const MW_NO_OUTPUT_COMPRESSION 1
 

Detailed Description

PHP script to stream out an image thumbnail.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html

Definition in file thumb.php.

Function Documentation

◆ wfExtractThumbParams()

wfExtractThumbParams (   $file,
  $params 
)

Convert a thumbnail name (122px-foo.png) to parameters, using file handler.

Parameters
File$fileFile object for file in question
array$paramsArray of parameters so far
Returns
array Parameters array with more parameters

Definition at line 578 of file thumb.php.

References $file, and $matches.

Referenced by wfStreamThumb().

◆ wfExtractThumbRequestInfo()

wfExtractThumbRequestInfo (   $thumbRel)

Convert pathinfo type parameter, into normal request parameters.

So for example, if the request was redirected from /w/images/thumb/a/ab/Foo.png/120px-Foo.png. The $thumbRel parameter of this function would be set to "a/ab/Foo.png/120px-Foo.png". This method is responsible for turning that into an array with the following keys:

  • f => the filename (Foo.png)
  • rel404 => the whole thing (a/ab/Foo.png/120px-Foo.png)
  • archived => 1 (If the request is for an archived thumb)
  • temp => 1 (If the file is in the "temporary" zone)
  • thumbName => the thumbnail name, including parameters (120px-Foo.png)

Transform specific parameters are set later via wfExtractThumbParams().

Parameters
string$thumbRelThumbnail path relative to the thumb zone
Returns
array|null Associative params array or null

Definition at line 539 of file thumb.php.

References RepoGroup\singleton().

Referenced by wfThumbHandle404().

◆ wfGenerateThumbnail()

wfGenerateThumbnail ( File  $file,
array  $params,
  $thumbName,
  $thumbPath 
)

Actually try to generate a new thumbnail.

Parameters
File$file
array$params
string$thumbName
string$thumbPath
Returns
array (MediaTransformOutput|bool, string|bool error message HTML)

Definition at line 442 of file thumb.php.

References $cache, $file, $status, $wgAttemptFailureEpoch, PoolCounterWork\execute(), ObjectCache\getLocalClusterInstance(), File\RENDER_NOW, and wfMessage().

Referenced by wfStreamThumb().

◆ wfProxyThumbnailRequest()

wfProxyThumbnailRequest (   $img,
  $thumbName 
)

Proxies thumbnail request to a service that handles thumbnailing.

Parameters
File$img
string$thumbName

Definition at line 400 of file thumb.php.

References $status, MWHttpRequest\factory(), and MediaWiki\HeaderCallback\warnIfHeadersSent().

Referenced by wfStreamThumb().

◆ wfStreamThumb()

wfStreamThumb ( array  $params)

Stream a thumbnail specified by parameters.

Parameters
array$paramsList of thumbnailing parameters. In addition to parameters passed to the MediaHandler, this may also includes the keys: f (for filename), archived (if archived file), temp (if temp file), w (alias for width), p (alias for page), r (ignored; historical), rel404 (path for render on 404 to verify hash path correct), thumbName (thumbnail name to potentially extract more parameters from e.g. 'lossy-page1-120px-Foo.tiff' would add page, lossy and width to the parameters)
Returns
void

Definition at line 93 of file thumb.php.

References $response, $starttime, $status, $title, $wgVaryOnXFP, File\DELETED_FILE, MWException\getHTML(), MessageSpecifier\getKey(), RequestContext\getMain(), HttpStatus\header(), Title\makeTitleSafe(), NS_FILE, PROTO_CURRENT, RepoGroup\singleton(), File\THUMB_FULL_NAME, true, wfExpandUrl(), wfExtractThumbParams(), wfGenerateThumbnail(), wfLocalFile(), wfMessage(), wfProxyThumbnailRequest(), wfThumbError(), wfThumbErrorText(), wfThumbIsStandard(), and wfTimestamp().

Referenced by wfThumbHandle404().

◆ wfThumbError()

wfThumbError (   $status,
  $msgHtml,
  $msgText = null,
  $context = [] 
)

Output a thumbnail generation error message.

Parameters
int$status
string$msgHtmlHTML
string | null$msgTextShort error description, for internal logging. Defaults to $msgHtml. Only used for HTTP 500 errors.
array$contextError context, for internal logging. Only used for HTTP 500 errors.
Returns
void

Definition at line 641 of file thumb.php.

References $content, $context, $debug, $status, $wgShowHostnames, HttpStatus\header(), MediaWiki\HeaderCallback\warnIfHeadersSent(), and wfHostname().

Referenced by wfStreamThumb(), wfThumbErrorText(), and wfThumbHandle404().

◆ wfThumbErrorText()

wfThumbErrorText (   $status,
  $msgText 
)

Output a thumbnail generation error message.

Parameters
int$status
string$msgTextPlain text (will be html escaped)
Returns
void

Definition at line 627 of file thumb.php.

References $status, and wfThumbError().

Referenced by wfStreamThumb().

◆ wfThumbHandle404()

wfThumbHandle404 ( )

Handle a thumbnail request via thumbnail file URL.

Returns
void

Definition at line 52 of file thumb.php.

References $matches, $wgArticlePath, WebRequest\getPathInfo(), RepoGroup\singleton(), wfExtractThumbRequestInfo(), wfStreamThumb(), and wfThumbError().

Variable Documentation

◆ $mediawiki

$mediawiki = new MediaWiki()

Definition at line 42 of file thumb.php.

◆ $wgTrivialMimeDetection

$wgTrivialMimeDetection = true

Definition at line 32 of file thumb.php.

◆ else

if (defined('THUMB_HANDLER')) else
Initial value:
{
wfStreamThumb( $wgRequest->getQueryValuesOnly() )

Definition at line 37 of file thumb.php.

◆ MW_ENTRY_POINT

const MW_ENTRY_POINT 'thumb'

Definition at line 28 of file thumb.php.

◆ MW_NO_OUTPUT_COMPRESSION

const MW_NO_OUTPUT_COMPRESSION 1

Definition at line 27 of file thumb.php.

$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:752
wfStreamThumb
wfStreamThumb(array $params)
Stream a thumbnail specified by parameters.
Definition: thumb.php:93