User:Bryan/Bug 2581/patch

From mediawiki.org
Index: includes/ImagePage.php
===================================================================
--- includes/ImagePage.php	(revision 83785)
+++ includes/ImagePage.php	(working copy)
@@ -360,16 +360,25 @@
 						# because of rounding.
 					}
 					$msgbig  = wfMsgHtml( 'show-big-image' );
-					$msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
-						$wgLang->formatNum( $width ),
-						$wgLang->formatNum( $height )
-					);
+					$otherSizes = array();
+					foreach ( $wgImageLimits as $size ) {
+						if ( $size[0] < $width_orig && $size[1] < $height_orig &&
+								$size[0] != $width && $size[1] != $height ) {
+							$otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );							
+						}
+					}
+					$msgsmall = wfMessage( 'show-big-image-preview' )->
+						rawParams( $this->makeSizeLink( $params, $width, $height ) )->
+						parse() . ' ' . 
+						wfMessage( 'show-big-image-other' )->
+						rawParams( $wgLang->semicolonList( $otherSizes ) )->parse();
 				} else {
 					# Image is small enough to show full size on image page
 					$msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
 				}
 
 				$params['width'] = $width;
+				$params['height'] = $height;
 				$thumbnail = $this->displayImg->transform( $params );
 
 				$showLink = true;
@@ -515,6 +524,30 @@
 			}
 		}
 	}
+	
+	/**
+	 * Creates an thumbnail of specified size and returns an HTML link to it  
+	 * @param array $params Scaler parameters
+	 * @param int $width
+	 * @param int $height
+	 */
+	private function makeSizeLink( $params, $width, $height ) {
+		global $wgLang;
+		
+		$params['width'] = $width;
+		$params['height'] = $height;
+		$thumbnail = $this->displayImg->transform( $params );
+		if ( $thumbnail && !$thumbnail->isError() ) {
+			return Html::rawElement( 'a', array(
+				'href' => $thumbnail->getUrl(),
+				'class' => 'mw-thumbnail-link'
+				), wfMessage( 'show-big-image-size' )->numParams(
+					$thumbnail->getWidth(), $thumbnail->getHeight() 
+				)->parse() );
+		} else {
+			return '';
+		}
+	}
 
 	/**
 	 * Show a notice that the file is from a shared repository
Index: languages/messages/MessagesEn.php
===================================================================
--- languages/messages/MessagesEn.php	(revision 83785)
+++ languages/messages/MessagesEn.php	(working copy)
@@ -3641,7 +3641,9 @@
 'file-nohires'         => '<small>No higher resolution available.</small>',
 'svg-long-desc'        => 'SVG file, nominally $1 × $2 pixels, file size: $3',
 'show-big-image'       => 'Full resolution',
-'show-big-image-thumb' => '<small>Size of this preview: $1× $2 pixels</small>',
+'show-big-image-preview' => '<small> Size of this preview: $1.</small>',
+'show-big-image-other' => '<small>Other resolutions: $1.</small>',
+'show-big-image-size' => '$1 × $2 pixels',
 'file-info-gif-looped' => 'looped',
 'file-info-gif-frames' => '$1 {{PLURAL:$1|frame|frames}}',
 'file-info-png-looped' => 'looped',