Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 18463)
+++ wp-admin/includes/file.php	(working copy)
@@ -322,12 +322,28 @@
 		return call_user_func($upload_error_handler, $file, $uploads['error'] );
 
 	$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
+	
+	// Temporary file for fixing EXIF rotation and performing scaling (if requested)
+	$tmp_file = wp_tempnam($filename);
 
 	// Move the file to the uploads dir
-	$new_file = $uploads['path'] . "/$filename";
-	if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
+	if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) )
 		return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
 
+	// If a resize was requested, perform the resize.
+	if ($resize) {
+		$old_temp = $tmp_file;
+		$tmp_file = image_resize( $tmp_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), 0, 'resized');
+		if ( ! is_wp_error($tmp_file) ) {
+			unlink($old_temp);
+		}
+	}
+
+	// Copy the temporary file into its destination
+	$new_file = $uploads['path'] . "/$filename";
+	copy( $tmp_file, $new_file );
+	unlink($tmp_file);
+	
 	// Set correct file permissions
 	$stat = stat( dirname( $new_file ));
 	$perms = $stat['mode'] & 0000666;
Index: wp-admin/includes/media.php
===================================================================
--- wp-admin/includes/media.php	(revision 18463)
+++ wp-admin/includes/media.php	(working copy)
@@ -1437,14 +1437,8 @@
 function media_upload_form( $errors = null ) {
 	global $type, $tab, $pagenow;
 
-	$flash_action_url = admin_url('async-upload.php');
+	$upload_action_url = admin_url('async-upload.php');
 
-	// If Mac and mod_security, no Flash. :(
-	$flash = true;
-	if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') )
-		$flash = false;
-
-	$flash = apply_filters('flash_uploader', $flash);
 	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
 
 	$upload_size_unit = $max_upload_size =  wp_max_upload_size();
@@ -1458,15 +1452,6 @@
 		$upload_size_unit = (int) $upload_size_unit;
 	}
 ?>
-<script type="text/javascript">
-//<![CDATA[
-var uploaderMode = 0;
-jQuery(document).ready(function($){
-	uploaderMode = getUserSetting('uploader');
-	$('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
-	$('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
-});
-//]]>
 </script>
 <div id="media-upload-notice">
 <?php if (isset($errors['upload_notice']) ) { ?>
@@ -1487,9 +1472,7 @@
 
 do_action('pre-upload-ui');
 
-if ( $flash ) :
-
-// Set the post params, which SWFUpload will post back with the file, and pass
+// Set the post params, which plupload will post back with the file, and pass
 // them through a filter.
 $post_params = array(
 		"post_id" => $post_id,
@@ -1500,94 +1483,108 @@
 		"tab" => $tab,
 		"short" => "1",
 );
-$post_params = apply_filters( 'swfupload_post_params', $post_params );
+$post_params = apply_filters( 'upload_post_params', $post_params );
 $p = array();
 foreach ( $post_params as $param => $val )
 	$p[] = "\t\t'$param' : '$val'";
 $post_params_str = implode( ", \n", $p );
 
-// #8545. wmode=transparent cannot be used with SWFUpload
-if ( 'media-new.php' == $pagenow ) {
-	$upload_image_path = get_user_option( 'admin_color' );
-	if ( 'classic' != $upload_image_path )
-		$upload_image_path = 'fresh';
-	$upload_image_path = admin_url( 'images/upload-' . $upload_image_path . '.png?ver=20101205' );
-} else {
-	$upload_image_path = includes_url( 'images/upload.png?ver=20100531' );
-}
-
 ?>
 <script type="text/javascript">
 //<![CDATA[
-var swfu;
-SWFUpload.onload = function() {
-	var settings = {
-			button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>',
-			button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }',
-			button_height: "23",
-			button_width: "132",
-			button_text_top_padding: 3,
-			button_image_url: '<?php echo $upload_image_path; ?>',
-			button_placeholder_id: "flash-browse-button",
-			upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
-			flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
-			file_post_name: "async-upload",
-			file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
-			post_params : {
-				<?php echo $post_params_str; ?>
-			},
-			file_size_limit : "<?php echo $max_upload_size; ?>b",
-			file_dialog_start_handler : fileDialogStart,
-			file_queued_handler : fileQueued,
-			upload_start_handler : uploadStart,
-			upload_progress_handler : uploadProgress,
-			upload_error_handler : uploadError,
-			upload_success_handler : <?php echo apply_filters( 'swfupload_success_handler', 'uploadSuccess' ); ?>,
-			upload_complete_handler : uploadComplete,
-			file_queue_error_handler : fileQueueError,
-			file_dialog_complete_handler : fileDialogComplete,
-			swfupload_pre_load_handler: swfuploadPreLoad,
-			swfupload_load_failed_handler: swfuploadLoadFailed,
-			custom_settings : {
-				degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
-				swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
-			},
-			debug: false
-		};
-		swfu = new SWFUpload(settings);
-};
+var resize_mode = false;
+var resize_height = <?php echo get_option('large_size_h'); ?>, 
+	resize_width = <?php echo get_option('large_size_w'); ?>;
+
+jQuery(function($) {
+	window.uploader = new plupload.Uploader({
+		runtimes: '<?php echo apply_filters('plupload_runtimes', 'html5,silverlight,flash,html4'); ?>',
+		browse_button: 'plupload-browse-button',
+		container: 'plupload-upload-ui',
+		drop_element: 'wpwrap',
+		file_data_name: 'async-upload',
+		max_file_size: '<?php echo $max_upload_size / 1024; ?>kb',
+		url: '<?php echo esc_attr( $upload_action_url ); ?>',
+		plupload_swf_url: '<?php echo includes_url('js/plupload/plupload.plupload.swf'); ?>',
+		silverlight_xap_url: '<?php echo includes_url('js/plupload/plupload.silverlight.xap'); ?>',
+		filters: [
+			{title: "Allowed files", extensions: "<?php echo apply_filters('upload_file_glob', '*'); ?>"}
+		],
+		multipart: true,
+		multipart_params : {
+			<?php echo $post_params_str; ?>
+		}
+	});
+	
+	resize_mode = getUserSetting('resize_mode') == 'true';
+	setResize(resize_mode)
+	$('#image_resize').bind('change', function() {
+		setResize($(this).prop('checked'));
+	});
+
+	uploader.init();
+
+	uploader.bind('FilesAdded', function(up, files) {
+		$.each(files, function(i, file) {
+			fileQueued(file);
+		});
+	
+		up.refresh();
+		up.start();
+	});
+
+	uploader.bind('BeforeUpload', function(up, file) {
+		uploadStart(file);
+	});
+	
+	uploader.bind('UploadProgress', function(up, file) {
+		uploadProgress(file, file.loaded, file.size);
+	});
+	
+	uploader.bind('Error', function(up, err) {
+		uploadError(err.file, err.code, err.message);
+	
+		up.refresh();
+	});
+
+	uploader.bind('FileUploaded', function(up, file, response) {
+		<?php echo apply_filters( 'plupload_success_handler', 'uploadSuccess' ); ?>(file, response.response);
+	});
+
+});
 //]]>
 </script>
 
-<div id="flash-upload-ui" class="hide-if-no-js">
-<?php do_action('pre-flash-upload-ui'); ?>
+<div id="plupload-upload-ui" class="hide-if-no-js">
+<?php do_action('pre-plupload-upload-ui'); ?>
 
 	<div>
 	<?php _e( 'Choose files to upload' ); ?>
-	<div id="flash-browse-button"></div>
+	<span id="plupload-browse-button" class="button"><?php _e('Select Files'); ?></span>
 	<span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
 	</div>
-	<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
-<?php do_action('post-flash-upload-ui'); ?>
-	<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
+<?php do_action('post-plupload-upload-ui'); ?>
 </div>
-<?php endif; // $flash ?>
 
-<div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>>
+<?php if ( !IFRAME_REQUEST ): ?>
+<div id="html-upload-ui" class="hide-if-js">
 <?php do_action('pre-html-upload-ui'); ?>
 	<p id="async-upload-wrap">
 		<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
 		<input type="file" name="async-upload" id="async-upload" />
 		<?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>
-		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
+		<a href="<?php echo admin_url('upload.php'); ?>"><?php _e('Cancel'); ?></a>
 	</p>
 	<div class="clear"></div>
-	<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
-	<?php if ( is_lighttpd_before_150() ): ?>
-	<p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please update to lighttpd 1.5.'); ?></p>
-	<?php endif;?>
-<?php do_action('post-html-upload-ui', $flash); ?>
+<?php do_action('post-html-upload-ui', $plupload); ?>
 </div>
+<?php endif; ?>
+
+<input name="image_resize" type="checkbox" id="image_resize" value="1" />
+<label for="image_resize"><?php printf( __( 'Resize images to %d x %d'), get_option('large_size_w'), get_option('large_size_h') ); ?></label>
+<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
+<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
+
 <?php do_action('post-upload-ui'); ?>
 <?php
 }
@@ -2272,69 +2269,17 @@
 /**
  * {@internal Missing Short Description}}
  *
- * Support a GET parameter for disabling the flash uploader.
- *
  * @since 2.6.0
- *
- * @param unknown_type $flash
- * @return unknown
  */
-function media_upload_use_flash($flash) {
-	if ( array_key_exists('flash', $_REQUEST) )
-		$flash = !empty($_REQUEST['flash']);
-	return $flash;
+function media_upload_max_image_resize() {
+?>
+<input name="image_resize" type="checkbox" id="image_resize" value="1" />
+<label for="image_resize"><?php printf( __( 'Resize images to %d x %d'), get_option('large_size_w'), get_option('large_size_h') ); ?></label>
+<?php 
 }
 
-add_filter('flash_uploader', 'media_upload_use_flash');
+add_action('post-upload-ui', 'media_upload_max_image_resize');
 
-/**
- * {@internal Missing Short Description}}
- *
- * @since 2.6.0
- */
-function media_upload_flash_bypass() {
-	echo '<p class="upload-flash-bypass">';
-	printf( __('You are using the Flash uploader.  Problems?  Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
-	echo '</p>';
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since 2.6.0
- */
-function media_upload_html_bypass($flash = true) {
-	echo '<p class="upload-html-bypass hide-if-no-js">';
-	_e('You are using the Browser uploader.');
-	if ( $flash ) {
-		// the user manually selected the browser uploader, so let them switch back to Flash
-		echo ' ';
-		printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
-	}
-	echo "</p>\n";
-}
-
-add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
-add_action('post-html-upload-ui', 'media_upload_html_bypass');
-
-/**
- * {@internal Missing Short Description}}
- *
- * Make sure the GET parameter sticks when we submit a form.
- *
- * @since 2.6.0
- *
- * @param unknown_type $url
- * @return unknown
- */
-function media_upload_bypass_url($url) {
-	if ( array_key_exists('flash', $_REQUEST) )
-		$url = add_query_arg('flash', intval($_REQUEST['flash']));
-	return $url;
-}
-
-add_filter('media_upload_form_url', 'media_upload_bypass_url');
-
 add_filter('async_upload_image', 'get_media_item', 10, 2);
 add_filter('async_upload_audio', 'get_media_item', 10, 2);
 add_filter('async_upload_video', 'get_media_item', 10, 2);
Index: wp-admin/media-upload.php
===================================================================
--- wp-admin/media-upload.php	(revision 18463)
+++ wp-admin/media-upload.php	(working copy)
@@ -18,8 +18,8 @@
 if (!current_user_can('upload_files'))
 	wp_die(__('You do not have permission to upload files.'));
 
-wp_enqueue_script('swfupload-all');
-wp_enqueue_script('swfupload-handlers');
+wp_enqueue_script('plupload-full');
+wp_enqueue_script('plupload-handlers');
 wp_enqueue_script('image-edit');
 wp_enqueue_script('set-post-thumbnail' );
 wp_enqueue_style('imgareaselect');
Index: wp-includes/script-loader.php
===================================================================
--- wp-includes/script-loader.php	(revision 18463)
+++ wp-includes/script-loader.php	(working copy)
@@ -206,30 +206,38 @@
 
 	$scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8-20110113');
 
-	$scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", false, '2.2');
 
-	$scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2201-20110113');
-	$scripts->add( 'swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a');
-	$scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201');
-	$scripts->add( 'swfupload-speed', '/wp-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201');
+	$scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.js', false, '1.4.3.2');
+	$scripts->add( 'plupload-html5', '/wp-includes/js/plupload/plupload.html5.js', array('plupload'), '1.4.3.2');
+	$scripts->add( 'plupload-flash', '/wp-includes/js/plupload/plupload.flash.js', array('plupload'), '1.4.3.2');
+	$scripts->add( 'plupload-silverlight', '/wp-includes/js/plupload/plupload.silverlight.js', array('plupload'), '1.4.3.2');
+	$scripts->add( 'plupload-gears', '/wp-includes/js/plupload/plupload.gears.js', array('plupload'), '1.4.3.2');
+	$scripts->add( 'plupload-html4', '/wp-includes/js/plupload/plupload.html4.js', array('plupload'), '1.4.3.2');
 
-	if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
+	// TODO: find out if we can use the plupload.full.js (it does load browserplus)
+	$scripts->add( 'plupload-full', false, array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-gears', 'plupload-html4'), '1.4.3.2');
+
+	$scripts->add( 'plupload-handlers', '/wp-includes/js/plupload/handlers.js', array('plupload-full', 'jquery'), '1.4.3.2');
+	
+	// TODO: find out if we really need this debug clause with plupload
+	/*if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
 		// queue all SWFUpload scripts that are used by default
 		$scripts->add( 'swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201');
 	} else {
-		$scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201a');
-	}
+		$scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201');
+	}*/
 
-	$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');
 	$max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post;
 	if ( empty($max_upload_size) )
 		$max_upload_size = __('not configured');
 	// these error messages came from the sample swfupload js, they might need changing.
-	$scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array(
-			'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
+	$scripts->localize( 'plupload-handlers', 'pluploadL10n', array(
 			'file_exceeds_size_limit' => __('This file exceeds the maximum upload size for this site.'),
 			'zero_byte_file' => __('This file is empty. Please try another.'),
 			'invalid_filetype' => __('This file type is not allowed. Please try another.'),
+			'not_an_image' => __('This file is not an image. Please try another.'),
+			'image_memory_exceeded' => __('Memery exceeded. Please try another smaller file.'),
+			'image_dimensions_exceeded' => __('This is larger than the maximum size. 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.'),
@@ -243,7 +251,7 @@
 			'crunching' => __('Crunching&hellip;'),
 			'deleted' => __('moved to the trash.'),
 			'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error'),
-			'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};',
+			'l10n_print_after' => 'try{convertEntities(pluploadL10n);}catch(e){};',
 	) );
 
 	$scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');
