| Index: trunk/phase3/includes/Linker.php |
| — | — | @@ -458,7 +458,7 @@ |
| 459 | 459 | function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false, |
| 460 | 460 | $thumb = false, $manual_thumb = '' ) |
| 461 | 461 | { |
| 462 | | - global $wgContLang, $wgUser, $wgThumbLimits; |
| | 462 | + global $wgContLang, $wgUser, $wgThumbLimits, $wgGenerateThumbnailOnParse; |
| 463 | 463 | |
| 464 | 464 | $img = new Image( $nt ); |
| 465 | 465 | if ( !$img->allowInlineDisplay() && $img->exists() ) { |
| — | — | @@ -512,7 +512,7 @@ |
| 513 | 513 | if ( $height == false ) |
| 514 | 514 | $height = -1; |
| 515 | 515 | if ( $manual_thumb == '') { |
| 516 | | - $thumb = $img->getThumbnail( $width, $height ); |
| | 516 | + $thumb = $img->getThumbnail( $width, $height, $wgGenerateThumbnailOnParse ); |
| 517 | 517 | if ( $thumb ) { |
| 518 | 518 | // In most cases, $width = $thumb->width or $height = $thumb->height. |
| 519 | 519 | // If not, we're scaling the image larger than it can be scaled, |
| — | — | @@ -563,7 +563,7 @@ |
| 564 | 564 | * $img is an Image object |
| 565 | 565 | */ |
| 566 | 566 | function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) { |
| 567 | | - global $wgStylePath, $wgContLang; |
| | 567 | + global $wgStylePath, $wgContLang, $wgGenerateThumbnailOnParse; |
| 568 | 568 | $url = $img->getViewURL(); |
| 569 | 569 | $thumbUrl = ''; |
| 570 | 570 | $error = ''; |
| — | — | @@ -588,7 +588,7 @@ |
| 589 | 589 | if ( $boxheight === false ) |
| 590 | 590 | $boxheight = -1; |
| 591 | 591 | if ( '' == $manual_thumb ) { |
| 592 | | - $thumb = $img->getThumbnail( $boxwidth, $boxheight ); |
| | 592 | + $thumb = $img->getThumbnail( $boxwidth, $boxheight, $wgGenerateThumbnailOnParse ); |
| 593 | 593 | if ( $thumb ) { |
| 594 | 594 | $thumbUrl = $thumb->getUrl(); |
| 595 | 595 | $boxwidth = $thumb->width; |
| Index: trunk/phase3/includes/Image.php |
| — | — | @@ -882,10 +882,13 @@ |
| 883 | 883 | * |
| 884 | 884 | * @param integer $width maximum width of the generated thumbnail |
| 885 | 885 | * @param integer $height maximum height of the image (optional) |
| | 886 | + * @param boolean $render True to render the thumbnail if it doesn't exist, |
| | 887 | + * false to just return the URL |
| | 888 | + * |
| 886 | 889 | * @return ThumbnailImage or null on failure |
| 887 | 890 | * @public |
| 888 | 891 | */ |
| 889 | | - function getThumbnail( $width, $height=-1 ) { |
| | 892 | + function getThumbnail( $width, $height=-1, $render = true ) { |
| 890 | 893 | if ($this->canRender()) { |
| 891 | 894 | if ( $height > 0 ) { |
| 892 | 895 | $this->load(); |
| — | — | @@ -893,7 +896,23 @@ |
| 894 | 897 | $width = wfFitBoxWidth( $this->width, $this->height, $height ); |
| 895 | 898 | } |
| 896 | 899 | } |
| 897 | | - return $this->renderThumb( $width ); |
| | 900 | + if ( $render ) { |
| | 901 | + return $this->renderThumb( $width ); |
| | 902 | + } else { |
| | 903 | + // Don't render, just return the URL |
| | 904 | + if ( $this->validateThumbParams( $width, $height ) ) { |
| | 905 | + if ( $width == $this->width && $height == $this->height ) { |
| | 906 | + $url = $this->getURL(); |
| | 907 | + } else { |
| | 908 | + list( $isScriptUrl, $url ) = $this->thumbUrl( $width ); |
| | 909 | + } |
| | 910 | + echo "Thumbnail requested, $url, $width x $height\n"; |
| | 911 | + return new ThumbnailImage( $url, $width, $height ); |
| | 912 | + } else { |
| | 913 | + echo "Bogus thumbnail, returning null"; |
| | 914 | + return null; |
| | 915 | + } |
| | 916 | + } |
| 898 | 917 | } else { |
| 899 | 918 | // not a bitmap or renderable image, don't try. |
| 900 | 919 | return $this->iconThumb(); |
| — | — | @@ -918,38 +937,29 @@ |
| 919 | 938 | } |
| 920 | 939 | |
| 921 | 940 | /** |
| 922 | | - * Create a thumbnail of the image having the specified width. |
| 923 | | - * The thumbnail will not be created if the width is larger than the |
| 924 | | - * image's width. Let the browser do the scaling in this case. |
| 925 | | - * The thumbnail is stored on disk and is only computed if the thumbnail |
| 926 | | - * file does not exist OR if it is older than the image. |
| 927 | | - * Returns an object which can return the pathname, URL, and physical |
| 928 | | - * pixel size of the thumbnail -- or null on failure. |
| | 941 | + * Validate thumbnail parameters and fill in the correct height |
| 929 | 942 | * |
| 930 | | - * @return ThumbnailImage or null on failure |
| 931 | | - * @private |
| | 943 | + * @param integer &$width Specified width (input/output) |
| | 944 | + * @param integer &$height Height (output only) |
| | 945 | + * @return false to indicate that an error should be returned to the user. |
| 932 | 946 | */ |
| 933 | | - function renderThumb( $width, $useScript = true ) { |
| 934 | | - global $wgUseSquid; |
| 935 | | - global $wgSVGMaxSize, $wgMaxImageArea, $wgThumbnailEpoch; |
| | 947 | + function validateThumbParams( &$width, &$height ) { |
| | 948 | + global $wgSVGMaxSize, $wgMaxImageArea; |
| | 949 | + |
| | 950 | + $this->load(); |
| 936 | 951 | |
| 937 | | - wfProfileIn( __METHOD__ ); |
| 938 | | - |
| 939 | | - $width = intval( $width ); |
| 940 | | - |
| 941 | | - $this->load(); |
| 942 | 952 | if ( ! $this->exists() ) |
| 943 | 953 | { |
| 944 | 954 | # If there is no image, there will be no thumbnail |
| 945 | | - wfProfileOut( __METHOD__ ); |
| 946 | | - return null; |
| | 955 | + return false; |
| 947 | 956 | } |
| 948 | | - |
| | 957 | + |
| | 958 | + $width = intval( $width ); |
| | 959 | + |
| 949 | 960 | # Sanity check $width |
| 950 | 961 | if( $width <= 0 || $this->width <= 0) { |
| 951 | 962 | # BZZZT |
| 952 | | - wfProfileOut( __METHOD__ ); |
| 953 | | - return null; |
| | 963 | + return false; |
| 954 | 964 | } |
| 955 | 965 | |
| 956 | 966 | # Don't thumbnail an image so big that it will fill hard drives and send servers into swap |
| — | — | @@ -959,21 +969,53 @@ |
| 960 | 970 | $this->getMimeType() !== 'image/jpeg' && |
| 961 | 971 | $this->width * $this->height > $wgMaxImageArea ) |
| 962 | 972 | { |
| 963 | | - wfProfileOut( __METHOD__ ); |
| 964 | | - return null; |
| | 973 | + return false; |
| 965 | 974 | } |
| 966 | 975 | |
| 967 | 976 | # Don't make an image bigger than the source, or wgMaxSVGSize for SVGs |
| 968 | 977 | if ( $this->mustRender() ) { |
| 969 | 978 | $width = min( $width, $wgSVGMaxSize ); |
| 970 | 979 | } elseif ( $width > $this->width - 1 ) { |
| 971 | | - $thumb = new ThumbnailImage( $this->getURL(), $this->getWidth(), $this->getHeight() ); |
| 972 | | - wfProfileOut( __METHOD__ ); |
| 973 | | - return $thumb; |
| | 980 | + $width = $this->width; |
| | 981 | + $height = $this->height; |
| | 982 | + return true; |
| 974 | 983 | } |
| 975 | 984 | |
| 976 | 985 | $height = round( $this->height * $width / $this->width ); |
| | 986 | + return true; |
| | 987 | + } |
| | 988 | + |
| | 989 | + /** |
| | 990 | + * Create a thumbnail of the image having the specified width. |
| | 991 | + * The thumbnail will not be created if the width is larger than the |
| | 992 | + * image's width. Let the browser do the scaling in this case. |
| | 993 | + * The thumbnail is stored on disk and is only computed if the thumbnail |
| | 994 | + * file does not exist OR if it is older than the image. |
| | 995 | + * Returns an object which can return the pathname, URL, and physical |
| | 996 | + * pixel size of the thumbnail -- or null on failure. |
| | 997 | + * |
| | 998 | + * @return ThumbnailImage or null on failure |
| | 999 | + * @private |
| | 1000 | + */ |
| | 1001 | + function renderThumb( $width, $useScript = true ) { |
| | 1002 | + global $wgUseSquid, $wgThumbnailEpoch; |
| 977 | 1003 | |
| | 1004 | + wfProfileIn( __METHOD__ ); |
| | 1005 | + |
| | 1006 | + $this->load(); |
| | 1007 | + $height = -1; |
| | 1008 | + if ( !$this->validateThumbParams( $width, $height ) ) { |
| | 1009 | + # Validation error |
| | 1010 | + return null; |
| | 1011 | + } |
| | 1012 | + |
| | 1013 | + if ( $width == $this->width && $height == $this->height ) { |
| | 1014 | + # validateThumbParams (or the user) wants us to return the unscaled image |
| | 1015 | + $thumb = new ThumbnailImage( $this->getURL(), $width, $height ); |
| | 1016 | + wfProfileOut( __METHOD__ ); |
| | 1017 | + return $thumb; |
| | 1018 | + } |
| | 1019 | + |
| 978 | 1020 | list( $isScriptUrl, $url ) = $this->thumbUrl( $width ); |
| 979 | 1021 | if ( $isScriptUrl && $useScript ) { |
| 980 | 1022 | // Use thumb.php to render the image |
| Index: trunk/phase3/includes/DefaultSettings.php |
| — | — | @@ -1380,6 +1380,14 @@ |
| 1381 | 1381 | */ |
| 1382 | 1382 | $wgIgnoreImageErrors = false; |
| 1383 | 1383 | |
| | 1384 | +/** |
| | 1385 | + * Allow thumbnail rendering on page view. If this is false, a valid |
| | 1386 | + * thumbnail URL is still output, but no file will be created at |
| | 1387 | + * the target location. This may save some time if you have a |
| | 1388 | + * thumb.php or 404 handler set up which is faster than the regular |
| | 1389 | + * webserver(s). |
| | 1390 | + */ |
| | 1391 | +$wgGenerateThumbnailOnParse = true; |
| 1384 | 1392 | |
| 1385 | 1393 | /** Set $wgCommandLineMode if it's not set already, to avoid notices */ |
| 1386 | 1394 | if( !isset( $wgCommandLineMode ) ) { |