MediaWiki r22305 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r22304‎ | r22305 (on ViewVC)‎ | r22306 >
Date:18:56, 21 May 2007
Author:raymond
Status:old
Tags:
Comment:
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
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.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Linker.php
===================================================================
--- trunk/phase3/includes/Linker.php	(revision 22304)
+++ trunk/phase3/includes/Linker.php	(revision 22305)
@@ -414,9 +414,9 @@
 
 	/** @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 @@
 					 $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 @@
 			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 @@
 	 * 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: trunk/phase3/includes/Parser.php
===================================================================
--- trunk/phase3/includes/Parser.php	(revision 22304)
+++ trunk/phase3/includes/Parser.php	(revision 22305)
@@ -4412,6 +4412,7 @@
 		#  * ___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 @@
 		$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 @@
 		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 @@
 		$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: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 22304)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 22305)
@@ -1960,6 +1960,13 @@
 );
 
 /**
+ * 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: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 22304)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 22305)
@@ -282,6 +282,7 @@
 	'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'           ),
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 22304)
+++ trunk/phase3/RELEASE-NOTES	(revision 22305)
@@ -19,6 +19,8 @@
 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 @@
 * (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 ==
 
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox