Index: wp-includes/post-template.php
===================================================================
--- wp-includes/post-template.php	(revision 7162)
+++ wp-includes/post-template.php	(working copy)
@@ -381,7 +381,7 @@
 
 	$post_title = attribute_escape($_post->post_title);
 
-	$link_text = wp_get_attachment_image($attachment_id, $size);
+	$link_text = wp_get_attachment_image($id, $size);
 	if ( !$link_text )
 		$link_text = $_post->post_title;
 
Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 7162)
+++ wp-includes/post.php	(working copy)
@@ -471,6 +471,7 @@
 	$query .= empty( $post_parent ) ? '' : $wpdb->prepare("AND $wpdb->posts.post_parent = %d ", $post_parent);
 	// expected_slashed ($meta_key, $meta_value) -- Also, this looks really funky, doesn't seem like it works
 	$query .= empty( $meta_key ) | empty($meta_value)  ? '' : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )";
+	$query .= empty( $post_mime_type ) ? '' : wp_post_mime_type_where($post_mime_type);
 	$query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;
 	if ( 0 < $numberposts )
 		$query .= $wpdb->prepare(" LIMIT %d,%d", $offset, $numberposts);
Index: wp-includes/js/swfupload/handlers.js
===================================================================
--- wp-includes/js/swfupload/handlers.js	(revision 7162)
+++ wp-includes/js/swfupload/handlers.js	(working copy)
@@ -20,7 +20,7 @@
 	jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + post_id + '"><div class="filename original">' + fileObj.name + '</div><div class="progress"><div class="bar"></div></div></div>');
 
 	// Disable the submit button
-	jQuery('#insert-media').attr('disabled', 'disabled');
+	jQuery('#insert-gallery').attr('disabled', 'disabled');
 }
 
 function uploadStart(fileObj) { return true; }
@@ -107,7 +107,7 @@
 function uploadComplete(fileObj) {
 	// If no more uploads queued, enable the submit button
 	if ( swfu.getStats().files_queued == 0 )
-		jQuery('#insert-media').attr('disabled', '');
+		jQuery('#insert-gallery').attr('disabled', '');
 }
 
 
Index: wp-includes/shortcodes.php
===================================================================
--- wp-includes/shortcodes.php	(revision 7162)
+++ wp-includes/shortcodes.php	(working copy)
@@ -128,64 +128,6 @@
 	return $out;
 }
 
-add_shortcode('gallery', 'gallery_shortcode');
-
-function gallery_shortcode($attr) {
-	global $post;
-
-	// Allow plugins/themes to override the default gallery template.
-	$output = apply_filters('post_gallery', '', $attr);
-	if ( $output != '' )
-		return $output;
-
-	$attachments = get_children("post_parent=$post->ID&post_type=attachment&orderby=\"menu_order ASC, ID ASC\"");
-/*
-	foreach ( $attachments as $id => $attachment ) {
-		$meta = get_post_custom($id);
-		if ( $meta ) foreach ( $meta as $k => $v )
-			$attachments[$id]->$k = $v;
-		if ( isset($attachments[$id]->_wp_attachment_metadata[0]) )
-			$attachments[$id]->meta = unserialize($attachments[$id]->_wp_attachment_metadata[0]);
-	}
-*/
-
-	$output = "
-		<style type='text/css'>
-			.gallery {
-				margin: auto;
-			}
-			.gallery div {
-				float: left;
-				margin-top: 10px;
-				text-align: center;
-				width: 33%;			}
-			.gallery img {
-				border: 2px solid #cfcfcf;
-			}
-		</style>
-		<div class='gallery'>
-";
-
-	if ( !empty($attachments) ) foreach ( $attachments as $id => $attachment ) {
-		$src = wp_get_attachment_thumb_url($id);
-		$href = get_attachment_link($id);
-		$output .= "
-			<div>
-				<a href='$href'><img src='$src' alt='$attachment->post_title' /></a>
-			</div>
-";
-		if ( ++$i % 3 == 0 )
-			$output .= '<br style="clear: both" />';
-	}
-
-	$output .= "
-			<br style='clear: both;' >
-		</div>
-";
-
-	return $output;
-}
-
 add_filter('the_content', 'do_shortcode');
 
 ?>
Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 7162)
+++ wp-includes/media.php	(working copy)
@@ -290,4 +290,53 @@
 	return $html;
 }
 
+
+add_shortcode('gallery', 'gallery_shortcode');
+
+function gallery_shortcode($attr) {
+	global $post;
+
+	// Allow plugins/themes to override the default gallery template.
+	$output = apply_filters('post_gallery', '', $attr);
+	if ( $output != '' )
+		return $output;
+
+	$attachments = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&orderby=\"menu_order ASC, ID ASC\"");
+
+	if ( empty($attachments) )
+		return '';
+
+	$output = apply_filters('gallery_style', "
+		<style type='text/css'>
+			.gallery {
+				margin: auto;
+			}
+			.gallery div {
+				float: left;
+				margin-top: 10px;
+				text-align: center;
+				width: 33%;			}
+			.gallery img {
+				border: 2px solid #cfcfcf;
+			}
+		</style>
+		<div class='gallery'>");
+
+	foreach ( $attachments as $id => $attachment ) {
+		$link = get_the_attachment_link($id, false, array(128, 96), true);
+		$output .= "
+			<div>
+				$link
+			</div>";
+		if ( ++$i % 3 == 0 )
+			$output .= '<br style="clear: both" />';
+	}
+
+	$output .= "
+			<br style='clear: both;' >
+		</div>\n";
+
+	return $output;
+}
+
 ?>
Index: wp-includes/script-loader.php
===================================================================
--- wp-includes/script-loader.php	(revision 7162)
+++ wp-includes/script-loader.php	(working copy)
@@ -98,8 +98,8 @@
 		$this->localize( 'swfupload-handlers', 'swfuploadL10n', array(
 				'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
 				'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), ini_get('upload_max_filesize')),
-				'zero_byte_file' => __('The file you selected is empty. Please select another file.'),
-				'invalid_filetype' => __('The file you choose is not an allowed file type.'),
+				'zero_byte_file' => __('This file is empty. Please try another.'),
+				'invalid_filetype' => __('This file type is not allowed. Please try another.'),
 				'default_error' => __('An error occurred in the upload. Please try again later.'),
 				'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
 				'upload_limit_exceeded' => __('You may only upload 1 file.'),
Index: wp-admin/includes/media.php
===================================================================
--- wp-admin/includes/media.php	(revision 7162)
+++ wp-admin/includes/media.php	(working copy)
@@ -53,10 +53,9 @@
 	$html = get_image_tag($id, $alt, $title, $align, $rel, $size);
 
 	$rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
+
 	if ( $url )
 		$html = "<a href='".attribute_escape($url)."'$rel>$html</a>";
-	elseif ( $size == 'thumbnail' || $size == 'medium' )
-		$html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>';
 
 	$html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
 
@@ -238,14 +237,17 @@
 				wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
 	}
 
-	if ( isset($_POST['insert-media']) )
+	if ( isset($_POST['insert-gallery']) )
 		return media_send_to_editor('[gallery]');
 
 	if ( isset($_POST['send']) ) {
 		$keys = array_keys($_POST['send']);
 		$send_id = (int) array_shift($keys);
 		$attachment = $_POST['attachments'][$send_id];
-		$html = apply_filters('media_send_to_editor', get_the_attachment_link($send_id, 0, array(125,125), !empty($attachment['post_content'])), $send_id, $attachment);
+		$html = $attachment['post_title'];
+		if ( !empty($attachment['url']) )
+			$html = "<a href='{$attachment['url']}'>$html</a>";
+		$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
 		return media_send_to_editor($html);
 	}
 
@@ -881,7 +883,7 @@
 <?php echo get_media_items($post_id, $errors); ?>
 </div>
 <p class="submit">
-	<input type="submit" class="submit insert-gallery" name="insert-media" value="<?php _e('Insert gallery into post'); ?>" />
+	<input type="submit" class="submit insert-gallery" name="insert-gallery" value="<?php _e('Insert gallery into post'); ?>" />
 </p>
 <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
 </form>
Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 7162)
+++ wp-admin/includes/file.php	(working copy)
@@ -159,6 +159,9 @@
 
 		if ( !$ext )
 			$ext = ltrim(strrchr($file['name'], '.'), '.');
+
+		if ( !$type )
+			$type = $file['type'];
 	}
 
 	// A writable uploads dir will pass this test. Again, there's no point overriding this one.
Index: wp-admin/js/media-upload.js
===================================================================
--- wp-admin/js/media-upload.js	(revision 7162)
+++ wp-admin/js/media-upload.js	(working copy)
@@ -4,7 +4,7 @@
 	if ( !win )
 		win = top;
 	tinyMCE = win.tinyMCE;
-	if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
+	if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.getInstanceById('content') ) && !ed.isHidden() ) {
 		tinyMCE.selectedInstance.getWin().focus();
 		tinyMCE.execCommand('mceInsertContent', false, h);
 	} else
