Expand all

GuessedThumbnailInfo

This provider is similar to ThumbnailInfo, but instead of making an API call to get the thumbnail URL, it tries to guess it. There are two failure modes:

  • known failure: in the given situation it does not seem possible or safe to guess the URL. It is up to the caller to obtain it by falling back to the normal provider.
  • unexpected failure: we guess an URL but it does not work. The current implementation is conservative so at least on WMF wikis this probably won't happen, but should be reckoned with anyway. On other wikis (especially ones which do not generate thumbnails on demand via the 404 handler) this could be more frequent. Again, it is the caller's responsibility to handle this by detecting image loading errors and falling back to the normal provider.

Constructor

new GuessedThumbnailInfo() #

Properties

displayableExtensions #

File extensions which can be displayed in the browser. Other file types need to be thumbnailed even if the size of the original file would be right.

Source:
File extensions which can be displayed in the browser.

vectorExtensions #

File extensions which are vector types (as opposed to bitmap). Thumbnails of vector types can be larger than the original file.

Source:
File extensions which are vector types (as opposed to bitmap).

Methods

canBeDisplayedInBrowser(file) → {boolean}protected #

True if the file type can be displayed in most browsers, false if it needs thumbnailing

Parameters:

Name Type Description
file mw.Title

Returns:

Type
boolean
Source:
True if the file type can be displayed in most browsers, false if it needs thumbnailing

canHaveLargerThumbnailThanOriginal(file) → {boolean}protected #

True if the file is of a type for which the thumbnail can be scaled beyond the original size.

Parameters:

Name Type Description
file mw.Title

Returns:

Type
boolean
Source:
True if the file is of a type for which the thumbnail can be scaled beyond the original size.

get(file, sampleUrl, width, originalWidth, originalHeight) → {jQuery.Promise.<Thumbnail>} #

Try to guess the thumbnailinfo for a thumbnail without doing an API request. An existing thumbnail URL is required.

There is no guarantee this function will be successful - in some cases, it is impossible to guess how the URL would look. If that's the case, the promise just rejects.

Parameters:

Name Type Description
file mw.Title
sampleUrl string

a thumbnail URL for the same file (but with different size).

width number

thumbnail width in pixels

originalWidth number

width of original image in pixels

originalHeight number

height of original image in pixels

Returns:

Type
jQuery.Promise.<Thumbnail>
Source:
Try to guess the thumbnailinfo for a thumbnail without doing an API request.

getUrl(file, sampleUrl, width, originalWidth) → {string|undefined} #

Try to guess the URL of a thumbnail without doing an API request. See #get().

Parameters:

Name Type Description
file mw.Title
sampleUrl string

a thumbnail URL for the same file (but with different size)

width number

thumbnail width in pixels

originalWidth number

width of original image in pixels

Returns:

a thumbnail URL or nothing

Type
string | undefined
Source:
Try to guess the URL of a thumbnail without doing an API request.

guessFullUrl(file, thumbnailUrl) → {string}protected #

Try to guess the original URL to the file, from a thumb URL.

Parameters:

Name Type Description
file mw.Title
thumbnailUrl string

Returns:

URL of the original file

Type
string
Source:
Try to guess the original URL to the file, from a thumb URL.

guessHeight(file, width, originalWidth, originalHeight) → {number}protected #

Guess what will be the height of the thumbnail, given its width.

Parameters:

Name Type Description
file mw.Title
width number

thumbnail width in pixels

originalWidth number

width of original image in pixels

originalHeight number

height of original image in pixels

Returns:

guessed height

Type
number
Source:
Guess what will be the height of the thumbnail, given its width.

guessThumbUrl(file, originalUrl, width) → {string|undefined}protected #

Hardest version: try to guess thumbnail URL from original

Parameters:

Name Type Description
file mw.Title
originalUrl string

URL for the original file

width number

thumbnail width in pixels

Returns:

thumbnail URL

Type
string | undefined
Source:
Hardest version: try to guess thumbnail URL from original

guessWidth(file, width, originalWidth) → {number}protected #

Guess what will be the width of the thumbnail. (Thumbnails for most file formats cannot be larger than the original file so this might be smaller than the requested width.)

Parameters:

Name Type Description
file mw.Title
width number

thumbnail width in pixels

originalWidth number

width of original image in pixels

Returns:

guessed width

Type
number
Source:
Guess what will be the width of the thumbnail.

isFullSizeUrl(url, file) → {boolean}protected #

Checks if a given thumbnail URL is full-size (the original image) or scaled

Parameters:

Name Type Description
url string

a thumbnail URL

file mw.Title

Returns:

Type
boolean
Source:
Checks if a given thumbnail URL is full-size (the original image) or scaled

needsOriginal(file, width, originalWidth) → {boolean}protected #

True if the original image needs to be used as a thumbnail.

Parameters:

Name Type Description
file mw.Title
width number

thumbnail width in pixels

originalWidth number

width of original image in pixels

Returns:

Type
boolean
Source:
True if the original image needs to be used as a thumbnail.

obscureFilename(url, file) → {string}protected #

Removes the filename in a reversible way. This is useful because the filename can be nearly anything and could cause false positives when looking for patterns.

Parameters:

Name Type Description
url string

a thumbnail URL

file mw.Title

Returns:

thumbnail URL with occurrences of the filename replaced by <filename>

Type
string
Source:
Removes the filename in a reversible way.

replaceSize(file, sampleUrl, width) → {string|undefined}protected #

Given a thumbnail URL with a wrong size, returns one with the right size.

Parameters:

Name Type Description
file mw.Title
sampleUrl string

a thumbnail URL for the same file (but with different size)

width number

thumbnail width in pixels

Returns:

thumbnail URL with the correct size

Type
string | undefined
Source:
Given a thumbnail URL with a wrong size, returns one with the right size.

restoreFilename(url, file) → {string}protected #

Undoes #obscureFilename().

Parameters:

Name Type Description
url string

a thumbnail URL (with obscured filename)

file mw.Title

Returns:

original thumbnail URL

Type
string
Source:
Undoes #obscureFilename().