r22511 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22510‎ | r22511 | r22512 >
Date:19:15, 28 May 2007
Author:raymond
Status:old
Tags:
Comment:
After revert of r22435 and talk with Brion on IRC previously introduced and newly function parameters merged to an array.

Introducing 'frameless' keyword to [[Image:]] syntax which respects the user preferences for image width like 'thumb' but without a frame.
Now we can use frameless images without the need to nailing its size by a constant pixel parameter. Scaling by different user preference/anon view will always keep the proportions.

Usage: [[Image:name.jpg|frameless|right]]
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Linker.php
@@ -427,9 +427,20 @@
428428 return $s;
429429 }
430430
431 - /** @todo document */
 431+ /** Creates the HTML source for images
 432+ * @param object $nt
 433+ * @param string $label label text
 434+ * @param string $alt alt text
 435+ * @param string $align horizontal alignment: none, left, center, right)
 436+ * @param array $params some format keywords: width, height, page, upright, upright_factor, frameless, border
 437+ * @param boolean $framed shows image in original size in a frame
 438+ * @param boolean $thumb shows image as thumbnail in a frame
 439+ * @param string $manual_thumb image name for the manual thumbnail
 440+ * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
 441+ * @return string
 442+ */
432443 function makeImageLinkObj( $nt, $label, $alt, $align = '', $params = array(), $framed = false,
433 - $thumb = false, $manual_thumb = '', $valign = '', $upright = false, $upright_factor = 0, $border = false )
 444+ $thumb = false, $manual_thumb = '', $valign = '' )
434445 {
435446 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
436447
@@ -448,10 +459,9 @@
449460 $postfix = '</div>';
450461 $align = 'none';
451462 }
452 -
453463 if ( !isset( $params['width'] ) ) {
454464 $params['width'] = $img->getWidth( $page );
455 - if( $thumb || $framed ) {
 465+ if( $thumb || $framed || isset( $params['frameless'] ) ) {
456466 $wopt = $wgUser->getOption( 'thumbsize' );
457467
458468 if( !isset( $wgThumbLimits[$wopt] ) ) {
@@ -459,12 +469,12 @@
460470 }
461471
462472 // Reduce width for upright images when parameter 'upright' is used
463 - if ( $upright_factor == 0 ) {
464 - $upright_factor = $wgThumbUpright;
 473+ if ( !isset( $params['upright_factor'] ) || $params['upright_factor'] == 0 ) {
 474+ $params['upright_factor'] = $wgThumbUpright;
465475 }
466476 // Use width which is smaller: real image width or user preference width
467477 // 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
468 - $params['width'] = min( $params['width'], $upright ? round( $wgThumbLimits[$wopt] * $upright_factor, -1 ) : $wgThumbLimits[$wopt] );
 478+ $params['width'] = min( $params['width'], isset( $params['upright'] ) ? round( $wgThumbLimits[$wopt] * $params['upright_factor'], -1 ) : $wgThumbLimits[$wopt] );
469479 }
470480 }
471481
@@ -480,7 +490,7 @@
481491 if ( $align == '' ) {
482492 $align = $wgContLang->isRTL() ? 'left' : 'right';
483493 }
484 - return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $params, $framed, $manual_thumb, $upright ).$postfix;
 494+ return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $params, $framed, $manual_thumb ).$postfix;
485495 }
486496
487497 if ( $params['width'] && $img->exists() ) {
@@ -504,7 +514,7 @@
505515 if ( $valign ) {
506516 $imgAttribs['style'] = "vertical-align: $valign";
507517 }
508 - if ( $border ) {
 518+ if ( isset( $params['border'] ) ) {
509519 $imgAttribs['class'] = "thumbborder";
510520 }
511521 $linkAttribs = array(
@@ -528,14 +538,14 @@
529539 * Make HTML for a thumbnail including image, border and caption
530540 * $img is an Image object
531541 */
532 - function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manual_thumb = "", $upright = false ) {
 542+ function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manual_thumb = "" ) {
533543 global $wgStylePath, $wgContLang;
534544
535545 $page = isset( $params['page'] ) ? $params['page'] : false;
536546
537547 if ( empty( $params['width'] ) ) {
538548 // Reduce width for upright images when parameter 'upright' is used
539 - $params['width'] = $upright ? 130 : 180;
 549+ $params['width'] = isset( $params['upright'] ) ? 130 : 180;
540550 }
541551 $thumb = false;
542552 if ( $manual_thumb != '' ) {
Index: trunk/phase3/includes/Parser.php
@@ -4418,6 +4418,7 @@
44194419 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
44204420 # * center center the image
44214421 # * framed Keep original image size, no magnify-button.
 4422+ # * frameless like 'thumb' but without a frame. Keeps user preferences for width
44224423 # * upright reduce width for upright images, rounded to full __0 px
44234424 # * border draw a 1px border around the image
44244425 # vertical-align values (no % or length right now):
@@ -4442,6 +4443,7 @@
44434444 $mwManualThumb =& MagicWord::get( 'img_manualthumb' );
44444445 $mwWidth =& MagicWord::get( 'img_width' );
44454446 $mwFramed =& MagicWord::get( 'img_framed' );
 4447+ $mwFrameless =& MagicWord::get( 'img_frameless' );
44464448 $mwUpright =& MagicWord::get( 'img_upright' );
44474449 $mwBorder =& MagicWord::get( 'img_border' );
44484450 $mwPage =& MagicWord::get( 'img_page' );
@@ -4449,9 +4451,6 @@
44504452
44514453 $params = array();
44524454 $framed = $thumb = false;
4453 - $upright = false;
4454 - $upright_factor = 0;
4455 - $border = false;
44564455 $manual_thumb = '' ;
44574456 $align = $valign = '';
44584457 $sk = $this->mOptions->getSkin();
@@ -4460,10 +4459,12 @@
44614460 if ( !is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
44624461 $thumb=true;
44634462 } elseif ( !is_null( $match = $mwUpright->matchVariableStartToEnd( $val ) ) ) {
4464 - $upright = true;
4465 - $upright_factor = floatval( $match );
 4463+ $params['upright'] = true;
 4464+ $params['upright_factor'] = floatval( $match );
 4465+ } elseif ( !is_null( $match = $mwFrameless->matchVariableStartToEnd( $val ) ) ) {
 4466+ $params['frameless'] = true;
44664467 } elseif ( !is_null( $mwBorder->matchVariableStartToEnd( $val ) ) ) {
4467 - $border = true;
 4468+ $params['border'] = true;
44684469 } elseif ( ! is_null( $match = $mwManualThumb->matchVariableStartToEnd($val) ) ) {
44694470 # use manually specified thumbnail
44704471 $thumb=true;
@@ -4510,7 +4511,7 @@
45114512 $alt = Sanitizer::stripAllTags( $alt );
45124513
45134514 # Linker does the rest
4514 - return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign, $upright, $upright_factor, $border );
 4515+ return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign );
45154516 }
45164517
45174518 /**
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -281,6 +281,7 @@
282282 'img_width' => array( 1, '$1px' ),
283283 'img_center' => array( 1, 'center', 'centre' ),
284284 'img_framed' => array( 1, 'framed', 'enframed', 'frame' ),
 285+ 'img_frameless' => array( 1, 'frameless' ),
285286 'img_page' => array( 1, 'page=$1', 'page $1' ),
286287 'img_upright' => array( 1, 'upright', 'upright=$1', 'upright $1' ),
287288 'img_border' => array( 1, 'border' ),
Index: trunk/phase3/RELEASE-NOTES
@@ -34,13 +34,15 @@
3535 * (bug 9628) Show warnings about slave lag on Special:Contributions,
3636 Special:Watchlist
3737 * (bug 8818) Expose "wpDestFile" as parameter $1 to "uploaddisabledtext"
38 -* Introducing new image parameter 'upright' and corresponding variable
 38+* Introducing new image keyword 'upright' and corresponding variable
3939 $wgThumbUpright. This allows better proportional view of upright images
4040 related to landscape images on a page without nailing the width of upright
4141 images to a fix value which makes views for anon unproportional and user
4242 preferences useless
43 -* (bug 6072) Add a 'border' keyword to the image syntax
44 -
 43+* (bug 6072) Introducing 'border' keyword to the [[Image:]] syntax
 44+* Introducing 'frameless' keyword to [[Image:]] syntax which respects the
 45+ user preferences for image width like 'thumb' but without a frame.
 46+
4547 == Bugfixes since 1.10 ==
4648
4749 * (bug 9712) Use Arabic comma in date/time formats for Arabic and Farsi

Follow-up revisions

RevisionCommit summaryAuthorDate
r22518Merged revisions 22484-22517 via svnmerge from...david22:22, 28 May 2007

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r22435Reverting r22430 for now; I don't really like this keyword creep, and even if...brion18:02, 25 May 2007