From 7be49919836a3871102cc1375733c35e82e11b19 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Fri, 10 Sep 2004 00:53:31 +0000 Subject: [PATCH] New user option. Provides a setting to limit the image size on image description pages. --- RELEASE-NOTES | 2 ++ includes/Article.php | 2 +- includes/DefaultSettings.php | 15 +++++++++++---- includes/Image.php | 6 ++++++ includes/ImagePage.php | 29 ++++++++++++++++++++++------- includes/SpecialPreferences.php | 17 +++++++++++++++-- languages/Language.php | 5 ++++- 7 files changed, 61 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2ad751b1b6..abecaa9c9c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/Article.php b/includes/Article.php index 474676f74c..6e23fee856 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 55d758ef9b..6dc5caf801 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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(); } diff --git a/includes/Image.php b/includes/Image.php index 692bf15e92..018be4610f 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -91,6 +91,12 @@ class Image return $this->height; } + function getSize() + { + $st = stat( $this->getImagePath() ); + return $st['size']; + } + function getType() { return $this->type; diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 8ccf6640af..2ed1cf3101 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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 = ""; + $anchorclose = "
{$msg}
"; + + $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 = ""; - $anchorclose = ''; - $url=$this->img->createThumb( $wgMaxImageWidth ); - $height = floor( $height * $wgMaxImageWidth / $width ); - $width = $wgMaxImageWidth; + $anchorclose = "
{$msg}"; + + $width = floor( $width * $maxHeight / $height ); + $height = $maxHeight; + $url = $this->img->createThumb( $width ); } - $s = "
" . $anchoropen . + $s = "
" . $anchoropen . "\""getVal( 'image' )."\" />" . $anchorclose . "
"; } else { diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index c06816ec89..2283a44d46 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -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" ) . "
+
+
diff --git a/languages/Language.php b/languages/Language.php index 50f4af191f..6463a3cc2c 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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' => '← Go to previous diff', 'nextdiff' => 'Go to next diff →', +'imagemaxsize' => 'Limit images on image description pages to: ', +'showbigimage' => 'Download high resolution version ($1x$2, $3 KB)', + ); -- 2.20.1