Index: wp-admin/export.php
===================================================================
--- wp-admin/export.php	(revision 16566)
+++ wp-admin/export.php	(working copy)
@@ -16,7 +16,7 @@
 require_once('./includes/export.php');
 $title = __('Export');
 
-add_contextual_help($current_screen,
+add_contextual_help( $current_screen,
 	'<p>' . __('You can export a file of your site&#8217;s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can set filters to have the WXR file only include a certain date, author, category, tag, all posts or all pages, certain publishing statuses.') . '</p>' .
 	'<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>' .
 	'<p><strong>' . __('For more information:') . '</strong></p>' .
@@ -25,24 +25,64 @@
 );
 
 if ( isset( $_GET['download'] ) ) {
-	export_wp();
+	$args = array();
+
+	if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) {
+		$args['content'] = 'all';
+	} else if ( 'posts' == $_GET['content'] ) {
+		$args['content'] = 'post';
+
+		if ( isset( $_GET['limit_category'] ) )
+			$args['category'] = (int) $_GET['cat'];
+
+		if ( isset( $_GET['post_limit_author'] ) )
+			$args['author'] = (int) $_GET['post_author'];
+
+		if ( isset( $_GET['post_limit_date'] ) ) {
+			$args['start_date'] = $_GET['post_start_date'];
+			$args['end_date'] = $_GET['post_end_date'];
+		}
+
+		$args['published'] = isset( $_GET['published_posts'] );
+	} else if ( 'pages' == $_GET['content'] ) {
+		$args['content'] = 'page';
+
+		if ( isset( $_GET['page_limit_author'] ) )
+			$args['author'] = (int) $_GET['page_author'];
+
+		$args['published'] = isset( $_GET['published_pages'] );
+	} else {
+		$args['content'] = $_GET['content'];
+	}
+
+	export_wp( $args );
 	die();
 }
 
 require_once ('admin-header.php');
 
-$dateoptions = $edateoptions = '';
-$types = "'" . implode("', '", get_post_types( array( 'public' => true, 'can_export' => true ), 'names' )) . "'";
-$stati = "'" . implode("', '", get_post_stati( array( 'internal' => false ), 'names' )) . "'";
-if ( $monthyears = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, YEAR(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `eyear`, MONTH(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `emonth` FROM $wpdb->posts WHERE post_type IN ($types) AND post_status IN ($stati) ORDER BY post_date ASC ") ) {
-	foreach ( $monthyears as $k => $monthyear )
-		$monthyears[$k]->lmonth = $wp_locale->get_month( $monthyear->month, 2 );
-	for( $s = 0, $e = count( $monthyears ) - 1; $e >= 0; $s++, $e-- ) {
-		$dateoptions .= "\t<option value=\"" . $monthyears[$s]->year . '-' . zeroise( $monthyears[$s]->month, 2 ) . '">' . $monthyears[$s]->lmonth . ' ' . $monthyears[$s]->year . "</option>\n";
-		$edateoptions .= "\t<option value=\"" . $monthyears[$e]->eyear . '-' . zeroise( $monthyears[$e]->emonth, 2 ) . '">' . $monthyears[$e]->lmonth . ' ' . $monthyears[$e]->year . "</option>\n";
+function export_date_options() {
+	global $wpdb, $wp_locale;
+
+	$months = $wpdb->get_results( "
+		SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
+		FROM $wpdb->posts
+		WHERE post_type = 'post' AND post_status != 'auto-draft'
+		ORDER BY post_date DESC
+	" );
+
+	$month_count = count( $months );
+	if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
+		return;
+
+	foreach ( $months as $date ) {
+		if ( 0 == $date->year )
+			continue;
+
+		$month = zeroise( $date->month, 2 );
+		echo '<option value="' . $date->year . '-' . $month . '" />' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
 	}
 }
-
 ?>
 
 <div class="wrap">
@@ -52,15 +92,64 @@
 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
 <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p>
 <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress site to import this site.'); ?></p>
+
+<h3><?php _e( 'Choose what to export' ); ?></h3>
 <form action="" method="get">
-<?php submit_button( __('Download Export File'), 'button' ); ?>
 <input type="hidden" name="download" value="true" />
-</p>
+<table class="form-table">
+	<tr>
+		<th scope="row"><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></th>
+		<td><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></td>
+	</tr>
+
+	<tr>
+		<th scope="row"><label><input type="radio" name="content" value="posts" /><?php _e( 'Posts' ); ?></label></th>
+		<td>
+			<fieldset>
+				<label><input type="checkbox" name="limit_category" value="1" /> <?php _e( 'Limit by category' ); ?></label>
+					<?php wp_dropdown_categories(); ?><br />
+
+				<label><input type="checkbox" name="post_limit_author" value="1" /> <?php _e( 'Limit by author' ); ?></label>
+					<?php wp_dropdown_users( array( 'name' => 'post_author', 'multi' => true ) ); ?><br />
+
+				<label><input type="checkbox" name="post_limit_date" value="1" /> <?php _e( 'Limit by date' ); ?></label>
+					<select name="post_start_date">
+						<option value="0"><?php _e( 'Start Date' ); ?></option>
+						<?php export_date_options(); ?>
+					</select>
+					<select name="post_end_date">
+						<option value="0"><?php _e( 'End Date' ); ?></option>
+						<?php export_date_options(); ?>
+					</select><br />
+
+				<label><input type="checkbox" name="published_posts" value="1" /> <?php _e( 'Published posts only' ); ?></label>
+			</fieldset>
+		</td>
+	</tr>
+
+	<tr>
+		<th scope="row"><label><input type="radio" name="content" value="pages" /><?php _e( 'Pages' ); ?></label></th>
+		<td>
+			<fieldset>
+				<label><input type="checkbox" name="page_limit_author" value="1" /> <?php _e( 'Limit by author' ); ?></label>
+					<?php wp_dropdown_users( array( 'name' => 'page_author', 'multi' => true ) ); ?><br />
+
+				<label><input type="checkbox" name="published_pages" value="1" /> <?php _e( 'Published pages only' ); ?></label>
+			</fieldset>
+		</td>
+	</tr>
+
+<?php foreach ( get_post_types( array( '_builtin' => false, 'public' => true, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
+	<tr>
+		<th scope="row"><label><input type="radio" name="content" value="<?php echo $post_type->name; ?>" /><?php echo $post_type->label; ?></label></th>
+		<td></td>
+	</tr>
+<?php endforeach; ?>
+</table>
+
+<?php submit_button( __('Download Export File'), 'secondary' ); ?>
+
 </form>
 </div>
 
-<?php
-
-
-include ('admin-footer.php');
-?>
+<?php include ('admin-footer.php'); ?>
Index: wp-admin/includes/export.php
===================================================================
--- wp-admin/includes/export.php	(revision 16566)
+++ wp-admin/includes/export.php	(working copy)
@@ -25,6 +25,11 @@
 function export_wp( $args = array() ) {
 	global $wpdb, $post;
 
+	$defaults = array( 'content' => 'all', 'author' => false, 'category' => false,
+		'start_date' => false, 'end_date' => false, 'published' => false,
+	);
+	$args = wp_parse_args( $args, $defaults );
+
 	do_action( 'export_wp' );
 
 	$sitename = sanitize_key( get_bloginfo( 'name' ) );
@@ -35,31 +40,71 @@
 	header( 'Content-Disposition: attachment; filename=' . $filename );
 	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
 
-	// grab a snapshot of post IDs, just in case it changes during the export
-	$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type != 'revision' AND post_status != 'auto-draft' ORDER BY post_date_gmt ASC" );
+	$join = '';
+	if ( $args['published'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) )
+		$where = "{$wpdb->posts}.post_status = 'publish'";
+	else
+		$where = "{$wpdb->posts}.post_status != 'auto-draft'";
 
-	$categories = (array) get_categories( array( 'get' => 'all' ) );
-	$tags = (array) get_tags( array( 'get' => 'all' ) );
+	if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) {
+		$ptype = get_post_type_object( $args['content'] );
+		if ( ! $ptype->can_export )
+			$args['content'] = 'post';
 
-	$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
-	$taxonomy_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
+		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $args['content'] );
 
-	// put categories in order with no child going before its parent
-	$cats = array();
-	while ( $cat = array_shift( $categories ) ) {
-		if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
-			$cats[$cat->term_id] = $cat;
-		else
-			$categories[] = $cat;
+		if ( 'post' == $args['content'] ) {
+			if ( $args['category'] && ($term = term_exists( $args['category'], 'category' )) ) {
+				$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
+				$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_id'] );
+			}
+
+			if ( $args['start_date'] )
+				$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );
+
+			if ( $args['end_date'] )
+				$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) );
+		}
+	} else {
+		$where .= " AND {$wpdb->posts}.post_type != 'revision'";
 	}
 
-	// put terms in order with no child going before its parent
-	$terms = array();
-	while ( $t = array_shift( $taxonomy_terms ) ) {
-		if ( $t->parent == 0 || isset( $terms[$t->parent] ) )
-			$terms[$t->term_id] = $t;
-		else
-			$taxonomy_terms[] = $t;
+	if ( $args['author'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) )
+		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
+
+	// grab a snapshot of post IDs, just in case it changes during the export
+	$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
+
+	// get the requested terms ready, empty unless posts filtered by category or all content
+	$cats = $tags = $terms = array();
+	if ( isset( $term ) && $term ) {
+		$cat = get_term( $term['term_id'], 'category' );
+		$cats = array( $cat->term_id => $cat );
+		unset( $term, $cat );
+	} else if ( 'all' == $args['content'] ) {
+		$categories = (array) get_categories( array( 'get' => 'all' ) );
+		$tags = (array) get_tags( array( 'get' => 'all' ) );
+
+		$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
+		$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
+
+		// put categories in order with no child going before its parent
+		while ( $cat = array_shift( $categories ) ) {
+			if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
+				$cats[$cat->term_id] = $cat;
+			else
+				$categories[] = $cat;
+		}
+
+		// put terms in order with no child going before its parent
+		while ( $t = array_shift( $custom_terms ) ) {
+			if ( $t->parent == 0 || isset( $terms[$t->parent] ) )
+				$terms[$t->term_id] = $t;
+			else
+				$custom_terms[] = $t;
+		}
+
+		unset( $categories, $custom_taxonomies, $custom_terms );
 	}
 
 	/**
@@ -271,7 +316,7 @@
 	<title><?php bloginfo_rss( 'name' ); ?></title>
 	<link><?php bloginfo_rss( 'url' ); ?></link>
 	<description><?php bloginfo_rss( 'description' ); ?></description>
-	<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ); ?></pubDate>
+	<pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
 	<language><?php echo get_option( 'rss_language' ); ?></language>
 	<wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
 	<wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
@@ -288,7 +333,7 @@
 <?php foreach ( $terms as $t ) : ?>
 	<wp:term><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $terms[$t->parent]->slug : ''; ?></wp:term_parent><?php wxr_term_name( $t ); ?><?php wxr_term_description( $t ); ?></wp:term>
 <?php endforeach; ?>
-<?php wxr_nav_menu_terms(); ?>
+<?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?>
 
 	<?php do_action( 'rss2_head' ); ?>
 
@@ -299,7 +344,7 @@
 	// fetch 20 posts at a time rather than loading the entire table into memory
 	while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
 	$where = "WHERE ID IN (" . join( ',', $next_posts ) . ")";
-	$posts = $wpdb->get_results( "SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC" );
+	$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
 
 	// Begin Loop
 	foreach ( $posts as $post ) {
