Introducing new image parameter 'upright' and corresponding variable $wgThumbUpright.
authorRaimond Spekking <raymond@users.mediawiki.org>
Mon, 21 May 2007 18:56:03 +0000 (18:56 +0000)
committerRaimond Spekking <raymond@users.mediawiki.org>
Mon, 21 May 2007 18:56:03 +0000 (18:56 +0000)
This allows better proportional view of upright images related to landscape images on a page without nailing the width of upright images to a fix value which makes views for anon unproportional and user preferences useless
Usage:
* [[Image:pix.jpg|thumb|upright|caption]] = Upright image will be scaled down by $wgThumbUpright (default 0.75, seems to me the best value)
* [[Image:pix.jpg|thumb|upright=0.6|caption]] = Upright image will be scaled down by 0.6
Size of thumb is always rounded to full __0 px to avoid odd thumbsizes and spare the cache

If used in combination with a width, upright will be ignored.

RELEASE-NOTES
includes/DefaultSettings.php
includes/Linker.php
includes/Parser.php
languages/messages/MessagesEn.php

index a310310..1ef30f3 100644 (file)
@@ -19,6 +19,8 @@ Those wishing to use the latest code instead of a branch release can obtain
 it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 
 == Configuration changes since 1.10 ==
+* $wgThumbUpright - Adjust width of upright images when parameter 'upright' is
+  used
 
 == New features since 1.10 ==
 
@@ -32,6 +34,11 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 9628) Show warnings about slave lag on Special:Contributions,
   Special:Watchlist
 * (bug 8818) Expose "wpDestFile" as parameter $1 to "uploaddisabledtext"
+* Introducing new image parameter 'upright' and corresponding variable
+  $wgThumbUpright. This allows better proportional view of upright images
+  related to landscape images on a page without nailing the width of upright
+  images to a fix value which makes views for anon unproportional and user
+  preferences useless
   
 == Bugfixes since 1.10 ==
 
index a4ea590..e2074b7 100644 (file)
@@ -1959,6 +1959,13 @@ $wgThumbLimits = array(
        300
 );
 
+/**
+ * Adjust width of upright images when parameter 'upright' is used
+ * This allows a nicer look for upright images without the need to fix the width
+ * by hardcoded px in wiki sourcecode.
+ */
+$wgThumbUpright = 0.75;
+
 /**
  *  On  category pages, show thumbnail gallery for images belonging to that
  * category instead of listing them as articles.
index f293a89..bd5b413 100644 (file)
@@ -414,9 +414,9 @@ class Linker {
 
        /** @todo document */
        function makeImageLinkObj( $nt, $label, $alt, $align = '', $params = array(), $framed = false,
-         $thumb = false, $manual_thumb = '', $valign = '' )
+         $thumb = false, $manual_thumb = '', $valign = '', $upright = false, $upright_factor = 0 )
        {
-               global $wgContLang, $wgUser, $wgThumbLimits;
+               global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
 
                $img   = new Image( $nt );
 
@@ -443,7 +443,13 @@ class Linker {
                                         $wopt = User::getDefaultOption( 'thumbsize' );
                                }
 
-                               $params['width'] = min( $params['width'], $wgThumbLimits[$wopt] );
+                               // Reduce width for upright images when parameter 'upright' is used
+                               if ( $upright_factor == 0 ) {
+                                       $upright_factor = $wgThumbUpright;
+                               }
+                               // Use width which is smaller: real image width or user preference width
+                               // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
+                               $params['width'] = min( $params['width'], $upright ? round( $wgThumbLimits[$wopt] * $upright_factor, -1 ) : $wgThumbLimits[$wopt] );
                        }
                }
 
@@ -459,7 +465,7 @@ class Linker {
                        if ( $align == '' ) {
                                $align = $wgContLang->isRTL() ? 'left' : 'right';
                        }
-                       return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $params, $framed, $manual_thumb ).$postfix;
+                       return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $params, $framed, $manual_thumb, $upright ).$postfix;
                }
 
                if ( $params['width'] && $img->exists() ) {
@@ -503,13 +509,14 @@ class Linker {
         * Make HTML for a thumbnail including image, border and caption
         * $img is an Image object
         */
-       function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manual_thumb = "" ) {
+       function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manual_thumb = "", $upright = false ) {
                global $wgStylePath, $wgContLang;
 
                $page = isset( $params['page'] ) ? $params['page'] : false;
 
                if ( empty( $params['width'] ) ) {
-                       $params['width'] = 180;
+                       // Reduce width for upright images when parameter 'upright' is used 
+                       $params['width'] = $upright ? 130 : 180;
                }
                $thumb = false;
                if ( $manual_thumb != '' ) {
index f2ad137..c9f23a1 100644 (file)
@@ -4412,6 +4412,7 @@ class Parser
                #  * ___px              scale to ___ pixels width, no aligning. e.g. use in taxobox
                #  * center             center the image
                #  * framed             Keep original image size, no magnify-button.
+               #  * upright            reduce width for upright images, rounded to full __0 px
                # vertical-align values (no % or length right now):
                #  * baseline
                #  * sub
@@ -4434,11 +4435,14 @@ class Parser
                $mwManualThumb =& MagicWord::get( 'img_manualthumb' );
                $mwWidth  =& MagicWord::get( 'img_width' );
                $mwFramed =& MagicWord::get( 'img_framed' );
+               $mwUpright =& MagicWord::get( 'img_upright' );
                $mwPage   =& MagicWord::get( 'img_page' );
                $caption = '';
 
                $params = array();
                $framed = $thumb = false;
+               $upright = false;
+               $upright_factor = 0;
                $manual_thumb = '' ;
                $align = $valign = '';
                $sk = $this->mOptions->getSkin();
@@ -4446,6 +4450,9 @@ class Parser
                foreach( $part as $val ) {
                        if ( !is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
                                $thumb=true;
+                       } elseif ( !is_null( $match = $mwUpright->matchVariableStartToEnd( $val ) ) ) {
+                               $upright = true;
+                               $upright_factor = floatval( $match );
                        } elseif ( ! is_null( $match = $mwManualThumb->matchVariableStartToEnd($val) ) ) {
                                # use manually specified thumbnail
                                $thumb=true;
@@ -4492,7 +4499,7 @@ class Parser
                $alt = Sanitizer::stripAllTags( $alt );
 
                # Linker does the rest
-               return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign );
+               return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign, $upright, $upright_factor );
        }
 
        /**
index 6481858..e7cfa6f 100644 (file)
@@ -282,6 +282,7 @@ $magicWords = array(
        'img_center'             => array( 1,    'center', 'centre'       ),
        'img_framed'             => array( 1,    'framed', 'enframed', 'frame' ),
        'img_page'               => array( 1,    'page=$1', 'page $1'     ),
+       'img_upright'            => array( 1,    'upright', 'upright=$1', 'upright $1'  ),
        'img_baseline'           => array( 1,    'baseline'               ),
        'img_sub'                => array( 1,    'sub'                    ),
        'img_super'              => array( 1,    'super', 'sup'           ),