*
* @param integer $width maximum width of the generated thumbnail
* @param integer $height maximum height of the image (optional)
+ * @param boolean $render True to render the thumbnail if it doesn't exist,
+ * false to just return the URL
+ *
* @return ThumbnailImage or null on failure
* @public
*/
- function getThumbnail( $width, $height=-1 ) {
+ function getThumbnail( $width, $height=-1, $render = true ) {
if ($this->canRender()) {
if ( $height > 0 ) {
$this->load();
$width = wfFitBoxWidth( $this->width, $this->height, $height );
}
}
- return $this->renderThumb( $width );
+ if ( $render ) {
+ return $this->renderThumb( $width );
+ } else {
+ // Don't render, just return the URL
+ if ( $this->validateThumbParams( $width, $height ) ) {
+ if ( $width == $this->width && $height == $this->height ) {
+ $url = $this->getURL();
+ } else {
+ list( $isScriptUrl, $url ) = $this->thumbUrl( $width );
+ }
+ echo "Thumbnail requested, $url, $width x $height\n";
+ return new ThumbnailImage( $url, $width, $height );
+ } else {
+ echo "Bogus thumbnail, returning null";
+ return null;
+ }
+ }
} else {
// not a bitmap or renderable image, don't try.
return $this->iconThumb();
}
/**
- * Create a thumbnail of the image having the specified width.
- * The thumbnail will not be created if the width is larger than the
- * image's width. Let the browser do the scaling in this case.
- * The thumbnail is stored on disk and is only computed if the thumbnail
- * file does not exist OR if it is older than the image.
- * Returns an object which can return the pathname, URL, and physical
- * pixel size of the thumbnail -- or null on failure.
+ * Validate thumbnail parameters and fill in the correct height
*
- * @return ThumbnailImage or null on failure
- * @private
+ * @param integer &$width Specified width (input/output)
+ * @param integer &$height Height (output only)
+ * @return false to indicate that an error should be returned to the user.
*/
- function renderThumb( $width, $useScript = true ) {
- global $wgUseSquid;
- global $wgSVGMaxSize, $wgMaxImageArea, $wgThumbnailEpoch;
-
- wfProfileIn( __METHOD__ );
-
- $width = intval( $width );
-
+ function validateThumbParams( &$width, &$height ) {
+ global $wgSVGMaxSize, $wgMaxImageArea;
+
$this->load();
+
if ( ! $this->exists() )
{
# If there is no image, there will be no thumbnail
- wfProfileOut( __METHOD__ );
- return null;
+ return false;
}
-
+
+ $width = intval( $width );
+
# Sanity check $width
if( $width <= 0 || $this->width <= 0) {
# BZZZT
- wfProfileOut( __METHOD__ );
- return null;
+ return false;
}
# Don't thumbnail an image so big that it will fill hard drives and send servers into swap
$this->getMimeType() !== 'image/jpeg' &&
$this->width * $this->height > $wgMaxImageArea )
{
- wfProfileOut( __METHOD__ );
- return null;
+ return false;
}
# Don't make an image bigger than the source, or wgMaxSVGSize for SVGs
if ( $this->mustRender() ) {
$width = min( $width, $wgSVGMaxSize );
} elseif ( $width > $this->width - 1 ) {
- $thumb = new ThumbnailImage( $this->getURL(), $this->getWidth(), $this->getHeight() );
- wfProfileOut( __METHOD__ );
- return $thumb;
+ $width = $this->width;
+ $height = $this->height;
+ return true;
}
$height = round( $this->height * $width / $this->width );
+ return true;
+ }
+
+ /**
+ * Create a thumbnail of the image having the specified width.
+ * The thumbnail will not be created if the width is larger than the
+ * image's width. Let the browser do the scaling in this case.
+ * The thumbnail is stored on disk and is only computed if the thumbnail
+ * file does not exist OR if it is older than the image.
+ * Returns an object which can return the pathname, URL, and physical
+ * pixel size of the thumbnail -- or null on failure.
+ *
+ * @return ThumbnailImage or null on failure
+ * @private
+ */
+ function renderThumb( $width, $useScript = true ) {
+ global $wgUseSquid, $wgThumbnailEpoch;
+
+ wfProfileIn( __METHOD__ );
+ $this->load();
+ $height = -1;
+ if ( !$this->validateThumbParams( $width, $height ) ) {
+ # Validation error
+ return null;
+ }
+
+ if ( $width == $this->width && $height == $this->height ) {
+ # validateThumbParams (or the user) wants us to return the unscaled image
+ $thumb = new ThumbnailImage( $this->getURL(), $width, $height );
+ wfProfileOut( __METHOD__ );
+ return $thumb;
+ }
+
list( $isScriptUrl, $url ) = $this->thumbUrl( $width );
if ( $isScriptUrl && $useScript ) {
// Use thumb.php to render the image
function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
$thumb = false, $manual_thumb = '' )
{
- global $wgContLang, $wgUser, $wgThumbLimits;
+ global $wgContLang, $wgUser, $wgThumbLimits, $wgGenerateThumbnailOnParse;
$img = new Image( $nt );
if ( !$img->allowInlineDisplay() && $img->exists() ) {
if ( $height == false )
$height = -1;
if ( $manual_thumb == '') {
- $thumb = $img->getThumbnail( $width, $height );
+ $thumb = $img->getThumbnail( $width, $height, $wgGenerateThumbnailOnParse );
if ( $thumb ) {
// In most cases, $width = $thumb->width or $height = $thumb->height.
// If not, we're scaling the image larger than it can be scaled,
* $img is an Image object
*/
function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
- global $wgStylePath, $wgContLang;
+ global $wgStylePath, $wgContLang, $wgGenerateThumbnailOnParse;
$url = $img->getViewURL();
$thumbUrl = '';
$error = '';
if ( $boxheight === false )
$boxheight = -1;
if ( '' == $manual_thumb ) {
- $thumb = $img->getThumbnail( $boxwidth, $boxheight );
+ $thumb = $img->getThumbnail( $boxwidth, $boxheight, $wgGenerateThumbnailOnParse );
if ( $thumb ) {
$thumbUrl = $thumb->getUrl();
$boxwidth = $thumb->width;