From f8014e24e5d3292a555fc704b63bd14509e4f774 Mon Sep 17 00:00:00 2001 From: Raimond Spekking Date: Mon, 21 May 2007 18:56:03 +0000 Subject: [PATCH] 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. --- RELEASE-NOTES | 7 +++++++ includes/DefaultSettings.php | 7 +++++++ includes/Linker.php | 19 +++++++++++++------ includes/Parser.php | 9 ++++++++- languages/messages/MessagesEn.php | 1 + 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a3103109e4..1ef30f3c00 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a4ea5903fb..e2074b7da0 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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. diff --git a/includes/Linker.php b/includes/Linker.php index f293a89ad0..bd5b413c26 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 != '' ) { diff --git a/includes/Parser.php b/includes/Parser.php index f2ad137e82..c9f23a17e6 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 ); } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 64818588c6..e7cfa6f321 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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' ), -- 2.20.1