Index: includes/Linker.php =================================================================== --- includes/Linker.php (revision 16089) +++ includes/Linker.php (working copy) @@ -455,7 +455,7 @@ } /** @todo document */ - function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false, + function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $unit="px", $framed = false, $thumb = false, $manual_thumb = '', $page = null ) { global $wgContLang, $wgUser, $wgThumbLimits, $wgGenerateThumbnailOnParse; @@ -473,7 +473,7 @@ $url = $img->getViewURL(); $error = $prefix = $postfix = ''; - wfDebug( "makeImageLinkObj: '$width'x'$height', \"$label\"\n" ); + wfDebug( "makeImageLinkObj: '$width'x'$height$unit', \"$label\"\n" ); if ( 'center' == $align ) { @@ -517,24 +517,38 @@ if ( $height == false ) $height = -1; if ( $manual_thumb == '') { - $thumb = $img->getThumbnail( $width, $height, $wgGenerateThumbnailOnParse ); - if ( $thumb ) { - // In most cases, $width = $thumb->width or $height = $thumb->height. - // If not, we're scaling the image larger than it can be scaled, - // so we send to the browser a smaller thumbnail, and let the client do the scaling. + if( $unit == "px" ) { + $thumb = $img->getThumbnail( $width, $height, $wgGenerateThumbnailOnParse ); + if ( $thumb ) { + // In most cases, $width = $thumb->width or $height = $thumb->height. + // If not, we're scaling the image larger than it can be scaled, + // so we send to the browser a smaller thumbnail, and let the client do the scaling. - if ($height != -1 && $width > $thumb->width * $height / $thumb->height) { - // $height is the limiting factor, not $width - // set $width to the largest it can be, such that the resulting - // scaled height is at most $height - $width = floor($thumb->width * $height / $thumb->height); + if ($height != -1 && $width > $thumb->width * $height / $thumb->height) { + // $height is the limiting factor, not $width + // set $width to the largest it can be, such that the resulting + // scaled height is at most $height + $width = floor($thumb->width * $height / $thumb->height); + } + $height = round($thumb->height * $width / $thumb->width); + + wfDebug( "makeImageLinkObj: client-size set to '$width x $height'\n" ); + $url = $thumb->getUrl(); + } else { + $error = htmlspecialchars( $img->getLastError() ); } - $height = round($thumb->height * $width / $thumb->width); - - wfDebug( "makeImageLinkObj: client-size set to '$width x $height'\n" ); - $url = $thumb->getUrl(); - } else { - $error = htmlspecialchars( $img->getLastError() ); + } elseif( $unit == "ex" || $unit == "em" ) { + if( $height == -1 ) { + $height = ($img->height/$img->width)*$width; + } else { + if( ($width/$img->width) < ($height/$img->height) ) { + $height = ($img->height/$img->width)*$width; + } else { + $width = ($img->width/$img->height)*$height; + } + } + $width = round($width,3); + $height = round($height,3); } } } else { @@ -542,6 +556,7 @@ $height = $img->height; } + wfDebug( "makeImageLinkObj2: '$width'x'$height'\n" ); $u = $nt->escapeLocalURL(); if ( $error ) { @@ -551,11 +566,11 @@ //$s .= "
{$alt}
{$url}
\n"; } else { $s = '' . - ''.$alt.''; + '" longdesc="'.$u.'" />'; } if ( '' != $align ) { $s = "
{$s}
"; Index: includes/Parser.php =================================================================== --- includes/Parser.php (revision 16089) +++ includes/Parser.php (working copy) @@ -4105,7 +4105,7 @@ * Parse image options text and use it to make an image */ function makeImage( &$nt, $options ) { - global $wgUseImageResize; + global $wgUseImageResize, $wgAllowEmExImageSizes; $align = ''; @@ -4126,13 +4126,15 @@ $mwLeft =& MagicWord::get( 'img_left' ); $mwRight =& MagicWord::get( 'img_right' ); $mwNone =& MagicWord::get( 'img_none' ); - $mwWidth =& MagicWord::get( 'img_width' ); + $mwPxWidth =& MagicWord::get( 'img_width_px' ); + $mwEmWidth =& MagicWord::get( 'img_width_em' ); + $mwExWidth =& MagicWord::get( 'img_width_ex' ); $mwCenter =& MagicWord::get( 'img_center' ); $mwFramed =& MagicWord::get( 'img_framed' ); $caption = ''; $width = $height = $framed = $thumb = false; - $manual_thumb = '' ; + $manual_thumb = $unit = '' ; foreach( $part as $key => $val ) { if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) { @@ -4153,8 +4155,8 @@ } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) { # remember to set an alignment, don't render immediately $align = 'none'; - } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) { - wfDebug( "img_width match: $match\n" ); + } elseif ( $wgUseImageResize && ! is_null( $match = $mwPxWidth->matchVariableStartToEnd($val) ) ) { + wfDebug( "img_width_px match: $match\n" ); # $match is the image width in pixels if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) { $width = intval( $m[1] ); @@ -4162,6 +4164,27 @@ } else { $width = intval($match); } + $unit = 'px'; + } elseif ( $wgAllowEmExImageSizes && ! is_null( $match = $mwEmWidth->matchVariableStartToEnd($val) ) ) { + wfDebug( "img_width_em match: $match\n" ); + # $match is the image width in em units + if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) { + $width = intval( $m[1] ); + $height = intval( $m[2] ); + } else { + $width = intval($match); + } + $unit = 'em'; + } elseif ( $wgAllowEmExImageSizes && ! is_null( $match = $mwExWidth->matchVariableStartToEnd($val) ) ) { + wfDebug( "img_width_ex match: $match\n" ); + # $match is the image width in pixels + if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) { + $width = intval( $m[1] ); + $height = intval( $m[2] ); + } else { + $width = intval($match); + } + $unit = 'ex'; } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) { $framed=true; } else { @@ -4179,7 +4202,7 @@ # Linker does the rest $sk =& $this->mOptions->getSkin(); - return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height, $framed, $thumb, $manual_thumb ); + return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height, $unit, $framed, $thumb, $manual_thumb ); } /** Index: languages/MessagesEn.php =================================================================== --- languages/MessagesEn.php (revision 16089) +++ languages/MessagesEn.php (working copy) @@ -240,7 +240,9 @@ 'img_right' => array( 1, 'right' ), 'img_left' => array( 1, 'left' ), 'img_none' => array( 1, 'none' ), - 'img_width' => array( 1, '$1px' ), + 'img_width_px' => array( 1, '$1px' ), + 'img_width_em' => array( 1, '$1em' ), + 'img_width_ex' => array( 1, '$1ex' ), 'img_center' => array( 1, 'center', 'centre' ), 'img_framed' => array( 1, 'framed', 'enframed', 'frame' ), 'int' => array( 0, 'INT:' ),