On image pages, limit image width to $wgMaxImageWidth.
authorJens Frank <jeluf@users.mediawiki.org>
Tue, 17 Aug 2004 21:07:14 +0000 (21:07 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Tue, 17 Aug 2004 21:07:14 +0000 (21:07 +0000)
If $wgUseImageResize is set, the image will be resized to fit this limit.
The resized image links to the big image.
Default for $wgMaxImageWidth is 800 pixels. Set to really big values (like 9999999) to disable.

includes/DefaultSettings.php
includes/ImagePage.php

index 1375c74..91b5cb2 100644 (file)
@@ -392,6 +392,10 @@ $wgSiteNotice = "";
 # 
 $wgUseImageResize              = false;
 
+## Set maximum width of images on image description pages.
+## Images bigger than this will be rendered down.
+$wgMaxImageWidth = 800;
+
 ## Resizing can be done using PHP's internal image libraries
 ## or using ImageMagick. The later supports more file formats
 ## than PHP, which only supports PNG, GIF, JPG, XBM and WBMP.
index 0d7215c..9f0eab9 100644 (file)
@@ -31,9 +31,12 @@ class ImagePage extends Article {
 
        function openShowImage()
        {
-               global $wgOut, $wgUser,$wgRequest;
+               global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
                $this->img  = Image::newFromTitle( $this->mTitle );
                $url  = $this->img->getUrl();
+               $anchoropen = "";
+               $anchorclose = "";
+
 
                if ( $this->img->exists() ) {
 
@@ -41,9 +44,18 @@ class ImagePage extends Article {
                        
                        if ( $this->img->getType() != "" ) {
                                # image
-                               $s = "<div class=\"fullImage\">" .
-                                    "<img src=\"{$url}\" width=\"" . $this->img->getWidth() . "\" height=\"" . $this->img->getHeight() .
-                                    "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
+                               $width = $this->img->getWidth();
+                               $height = $this->img->getHeight();
+                               if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
+                                       $anchoropen  = "<a href=\"{$url}\">";
+                                       $anchorclose = '</a>';
+                                       $url=$this->img->createThumb( $wgMaxImageWidth );
+                                       $height = floor( $height * $wgMaxImageWidth / $width );
+                                       $width  = $wgMaxImageWidth;
+                               }
+                               $s = "<div class=\"fullImage\">" . $anchoropen .
+                                    "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
+                                    $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
                        } else {
                                $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
                        }