From: Tim Starling Date: Wed, 5 Jul 2006 05:04:06 +0000 (+0000) Subject: Created $wgGenerateThumbnailOnParse, set to false to allow NFS stat calls to be suppr... X-Git-Tag: 1.31.0-rc.0~56403 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=179733a3f06ad145da6d788a9970796187c797c5;p=lhc%2Fweb%2Fwiklou.git Created $wgGenerateThumbnailOnParse, set to false to allow NFS stat calls to be suppressed. --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 41073bf4df..c869d7fd07 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1380,6 +1380,14 @@ $wgThumbnailEpoch = '20030516000000'; */ $wgIgnoreImageErrors = false; +/** + * Allow thumbnail rendering on page view. If this is false, a valid + * thumbnail URL is still output, but no file will be created at + * the target location. This may save some time if you have a + * thumb.php or 404 handler set up which is faster than the regular + * webserver(s). + */ +$wgGenerateThumbnailOnParse = true; /** Set $wgCommandLineMode if it's not set already, to avoid notices */ if( !isset( $wgCommandLineMode ) ) { diff --git a/includes/Image.php b/includes/Image.php index f9fee3d14f..cc6a0554d5 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -882,10 +882,13 @@ class Image * * @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(); @@ -893,7 +896,23 @@ class Image $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(); @@ -918,38 +937,29 @@ class Image } /** - * 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 @@ -959,21 +969,53 @@ class Image $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 diff --git a/includes/Linker.php b/includes/Linker.php index 86b1ec64e9..4a0eafbdc7 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -458,7 +458,7 @@ class Linker { 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() ) { @@ -512,7 +512,7 @@ class Linker { 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, @@ -563,7 +563,7 @@ class Linker { * $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 = ''; @@ -588,7 +588,7 @@ class Linker { 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;