<?php
/*
Plugin Name: Keep Alphabetical Order in Gallery
Version: 1.0
Plugin URI: http://core.trac.wordpress.org/ticket/21643
Description: Allows to keep alphabetical order when uploading multiple images at once.
Author: Sergey Biryukov
Author URI: http://profiles.wordpress.org/sergeybiryukov/
*/

function keep_alphabetical_order_in_gallery( $wp_query ) {
	global $current_screen;

	if ( ! is_admin() || empty( $current_screen->id ) || 'media-upload' != $current_screen->id
		|| empty( $_REQUEST['tab'] ) || ! in_array( $_REQUEST['tab'], array( 'type', 'gallery' ) ) )
		return;

	$wp_query->set( 'orderby', 'menu_order ASC, name' );
	$wp_query->set( 'order', 'ASC' );
}
add_action( 'pre_get_posts', 'keep_alphabetical_order_in_gallery' );
?>