New user option. Provides a setting to limit the image size on image description...
authorJens Frank <jeluf@users.mediawiki.org>
Fri, 10 Sep 2004 00:53:31 +0000 (00:53 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Fri, 10 Sep 2004 00:53:31 +0000 (00:53 +0000)
RELEASE-NOTES
includes/Article.php
includes/DefaultSettings.php
includes/Image.php
includes/ImagePage.php
includes/SpecialPreferences.php
languages/Language.php

index 2ad751b..abecaa9 100644 (file)
@@ -18,6 +18,8 @@ Major changes from 1.3.x:
 * More scary link caching modes
 * Old manually maintained log pages replaced with searchable Special:Log
 * Skins system more modular: templates and CSS are now in /skins/
+* New user preference for limitting the image size for images on image description
+  pages 
 * ... and more!
 
 === Caveats ===
index 474676f..6e23fee 100644 (file)
@@ -392,7 +392,7 @@ class Article {
         * Load the revision (including cur_text) into this object
        */
        function loadContent( $noredir = false ) {
-               global $wgOut, $wgMwRedir, $wgRequest;
+               global $wgOut, $wgRequest;
 
                $dbr =& $this->getDB();
                # Query variables :P
index 55d758e..6dc5caf 100644 (file)
@@ -527,10 +527,6 @@ $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.
@@ -694,6 +690,17 @@ $wgExtraNamespaces = NULL;
 # If unsure, set to false.
 $wgEnableSOAP = false;
 
+# Limit images on image description pages to a user-selectable limit. In order to
+# reduce disk usage, limits can only be selected from a list. This is the list of
+# settings the user can choose from:
+$wgImageLimits = array (
+       array(320,240),
+       array(640,480),
+       array(800,600),
+       array(1024,768),
+       array(1280,1024),
+       array(10000,10000) );
+
 } else {
        die();
 }
index 692bf15..018be46 100644 (file)
@@ -91,6 +91,12 @@ class Image
                return $this->height;
        }
 
+       function getSize()
+       {
+               $st = stat( $this->getImagePath() );
+               return $st['size'];
+       }
+
        function getType()
        {
                return $this->type;
index 8ccf664..2ed1cf3 100644 (file)
@@ -37,11 +37,16 @@ class ImagePage extends Article {
 
        function openShowImage()
        {
-               global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
+               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
                $this->img  = Image::newFromTitle( $this->mTitle );
                $url  = $this->img->getUrl();
                $anchoropen = '';
                $anchorclose = '';
+               if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
+                       $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ];
+                       $maxWidth = $max[0];
+                       $maxHeight = $max[1];
+               }
 
 
                if ( $this->img->exists() ) {
@@ -52,14 +57,24 @@ class ImagePage extends Article {
                                # image
                                $width = $this->img->getWidth();
                                $height = $this->img->getHeight();
-                               if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
+                               if ( $width > $maxWidth && $wgUseImageResize ) {
+                                       $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
+                                       $anchoropen  = "<a href=\"{$url}\">";
+                                       $anchorclose = "<br>{$msg}</a>";
+
+                                       $url = $this->img->createThumb( $maxWidth );
+                                       $height = floor( $height * $maxWidth / $width );
+                                       $width  = $maxWidth;
+                               } elseif ( $height > $maxHeight && $wgUseImageResize ) {
+                                       $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
                                        $anchoropen  = "<a href=\"{$url}\">";
-                                       $anchorclose = '</a>';
-                                       $url=$this->img->createThumb( $wgMaxImageWidth );
-                                       $height = floor( $height * $wgMaxImageWidth / $width );
-                                       $width  = $wgMaxImageWidth;
+                                       $anchorclose = "<br>{$msg}</a>";
+
+                                       $width = floor( $width * $maxHeight / $height );
+                                       $height = $maxHeight;
+                                       $url = $this->img->createThumb( $width );
                                }
-                               $s = "<div class=\"fullImage\">" . $anchoropen .
+                               $s = "<div class=\"fullImageLink\">" . $anchoropen .
                                     "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
                                     $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
                        } else {
index c06816e..2283a44 100644 (file)
@@ -26,7 +26,7 @@ class PreferencesForm {
        var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
        var $mUserLanguage;
        var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
-       var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName;
+       var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
 
        /**
         * Constructor
@@ -55,6 +55,8 @@ class PreferencesForm {
                $this->mHourDiff = $request->getVal( 'wpHourDiff' );
                $this->mSearchLines = $request->getVal( 'wpSearchLines' );
                $this->mSearchChars = $request->getVal( 'wpSearchChars' );
+               $this->mImageSize = $request->getVal( 'wpImageSize' );
+
                $this->mAction = $request->getVal( 'action' );
                $this->mReset = $request->getCheck( 'wpReset' );
                $this->mPosted = $request->wasPosted();
@@ -186,6 +188,7 @@ class PreferencesForm {
                $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
                $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
                $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
+               $wgUser->setOption( 'imagesize', $this->mImageSize );
 
                # Set search namespace options
                foreach( $this->mSearchNs as $i => $value ) {
@@ -231,6 +234,7 @@ class PreferencesForm {
                $this->mSearch = $wgUser->getOption( 'searchlimit' );
                $this->mSearchLines = $wgUser->getOption( 'contextlines' );
                $this->mSearchChars = $wgUser->getOption( 'contextchars' );
+               $this->mImageSize = $wgUser->getOption( 'imagesize' );
                $this->mRecent = $wgUser->getOption( 'rclimit' );
 
                $togs = $wgLang->getUserToggles();
@@ -301,7 +305,7 @@ class PreferencesForm {
         */
        function mainPrefsForm( $err ) {
                global $wgUser, $wgOut, $wgLang, $wgUseDynamicDates, $wgValidSkinNames;
-               global $wgAllowRealName;
+               global $wgAllowRealName, $wgImageLimits;
            
                $wgOut->setPageTitle( wfMsg( 'preferences' ) );
                $wgOut->setArticleRelated( false );
@@ -490,6 +494,15 @@ class PreferencesForm {
                " . $this->getToggle( "hideminor" ) .
                $this->getToggle( "usenewrc" ) . "
                <div><label>$stt: <input type='text' name=\"wpStubs\" value=\"$this->mStubs\" size='6' /></label></div>
+                <div><label>".wfMsg('imagemaxsize')."<select name=\"wpImageSize\">");
+               
+               $imageLimitOptions='';
+               foreach ( $wgImageLimits as $index => $limits ) {
+                       $selected = ($index == $this->mImageSize) ? ' selected ': '';
+                       $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}x{$limits[1]}</option>\n";
+               }
+               $wgOut->addHTML( "{$imageLimitOptions}</select></label></div>
+
        </fieldset>
        
        <fieldset>
index 50f4af1..6463a3c 100644 (file)
@@ -58,7 +58,7 @@ if(isset($wgExtraNamespaces)) {
        'highlightbroken' => 1, 'stubthreshold' => 0,
        'previewontop' => 1, 'editsection'=>1,'editsectiononrightclick'=>0, 'showtoc'=>1,
        'showtoolbar' =>1,
-       'date' => 0
+       'date' => 0, 'imagesize' => 2
 );
 
 /* private */ $wgQuickbarSettingsEn = array(
@@ -1536,6 +1536,9 @@ ta[\'ca-nstab-category\'] = new Array(\'c\',\'View the category page\');
 'previousdiff' => '&larr; Go to previous diff',
 'nextdiff' => 'Go to next diff &rarr;',
 
+'imagemaxsize' => 'Limit images on image description pages to: ',
+'showbigimage' => 'Download high resolution version ($1x$2, $3 KB)',
+
 
 );