Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 21428)
+++ wp-includes/post.php	(working copy)
@@ -2619,10 +2619,13 @@
 	if ( !isset($post_password) || 'private' == $post_status )
 		$post_password = '';
 
-	$post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
-
 	// expected_slashed (everything!)
 	$data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) );
+
+	$sample_data = clone( (object) $data );
+	$sample_data->ID = $post_ID;
+	$data['post_name'] = wp_unique_post_slug( $sample_data );
+
 	$data = apply_filters('wp_insert_post_data', $data, $postarr);
 	$data = stripslashes_deep( $data );
 	$where = array( 'ID' => $post_ID );
@@ -2839,72 +2842,88 @@
  *
  * @global wpdb $wpdb
  * @global WP_Rewrite $wp_rewrite
- * @param string $slug the desired slug (post_name)
- * @param integer $post_ID
- * @param string $post_status no uniqueness checks are made if the post is still draft or pending
- * @param string $post_type
- * @param integer $post_parent
+ * @param obj $slug the desired slug (post_name)
+ * @param integer $deprecated_post_ID
+ * @param string $deprecated_post_status
+ * @param string $deprecated_post_type
+ * @param integer $deprecated_post_parent
  * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
  */
-function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
-	if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
-		return $slug;
+function wp_unique_post_slug( $post, $deprecated_post_ID = null, $deprecated_post_status = null, $deprecated_post_type = null, $deprecated_post_parent = null ) {
+	if ( $deprecated_post_ID || $deprecated_post_status || $deprecated_post_type || $deprecated_post_parent )
+		_deprecated_argument( __FUNCTION__, '3.5' );
 
+	if ( ! is_object($post) ) {
+		_doing_it_wrong( __FUNCTION__, _('This function expects a post object as its only parameter.'), '3.5' );
+		$post = array(
+			'ID' => $deprecated_post_ID,
+			'post_name' => $post, // used to be $post->post_name
+			'post_status' => $deprecated_post_status,
+			'post_type' => $deprecated_post_type,
+			'post_parent' => $deprecated_post_parent,
+		);
+		$post = (object) $post;
+	}
+
+	if ( 'publish' === $post->post_status
+		&& ( ! isset($post->filter) || 'sample' !== $post->filter ) )
+		return $post->post_name;
+
 	global $wpdb, $wp_rewrite;
 
-	$original_slug = $slug;
+	$original_slug = $post->post_name;
 
 	$feeds = $wp_rewrite->feeds;
 	if ( ! is_array( $feeds ) )
 		$feeds = array();
 
 	$hierarchical_post_types = get_post_types( array('hierarchical' => true) );
-	if ( 'attachment' == $post_type ) {
+	if ( 'attachment' == $post->post_type ) {
 		// Attachment slugs must be unique across all types.
 		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
-		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
+		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->ID ) );
 
-		if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
+		if ( $post_name_check || in_array( $post->post_name, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $post->post_name ) ) {
 			$suffix = 2;
 			do {
-				$alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
-				$post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
+				$alt_post_name = substr ($post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
+				$post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post->ID ) );
 				$suffix++;
 			} while ( $post_name_check );
-			$slug = $alt_post_name;
+			$post->post_name = $alt_post_name;
 		}
-	} elseif ( in_array( $post_type, $hierarchical_post_types ) ) {
+	} elseif ( in_array( $post->post_type, $hierarchical_post_types ) ) {
 		// Page slugs must be unique within their own trees. Pages are in a separate
 		// namespace than posts so page slugs are allowed to overlap post slugs.
 		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1";
-		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) );
+		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->ID, $post_parent ) );
 
-		if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
+		if ( $post_name_check || in_array( $post->post_name, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $post->post_name )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $post->post_name, $post->post_type, $post_parent ) ) {
 			$suffix = 2;
 			do {
-				$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
-				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
+				$alt_post_name = substr( $post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
+				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->ID, $post_parent ) );
 				$suffix++;
 			} while ( $post_name_check );
-			$slug = $alt_post_name;
+			$post->post_name = $alt_post_name;
 		}
 	} else {
 		// Post slugs must be unique across all posts.
 		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
-		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
+		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->post_type, $post->ID ) );
 
-		if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
+		if ( $post_name_check || in_array( $post->post_name, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $post->post_name, $post->post_type ) ) {
 			$suffix = 2;
 			do {
-				$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
-				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
+				$alt_post_name = substr( $post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
+				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->post_type, $post->ID ) );
 				$suffix++;
 			} while ( $post_name_check );
-			$slug = $alt_post_name;
+			$post->post_name = $alt_post_name;
 		}
 	}
 
-	return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug );
+	return apply_filters( 'wp_unique_post_slug', $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $original_slug );
 }
 
 /**
@@ -3718,7 +3737,7 @@
 		$post_name = sanitize_title($post_name);
 
 	// expected_slashed ($post_name)
-	$post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
+	$post_name = wp_unique_post_slug( (object) array( 'post_name' => $post_name, 'ID' => $post_ID, 'post_status' => $post_status, 'post_type' => $post_type, 'post_parent' => $post_parent ) );
 
 	if ( empty($post_date) )
 		$post_date = current_time('mysql');
Index: wp-admin/includes/post.php
===================================================================
--- wp-admin/includes/post.php	(revision 21428)
+++ wp-admin/includes/post.php	(working copy)
@@ -1034,10 +1034,10 @@
 	if ( !is_null($name) )
 		$post->post_name = sanitize_title($name ? $name : $title, $post->ID);
 
-	$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
-
 	$post->filter = 'sample';
 
+	$post->post_name = wp_unique_post_slug( $post );
+
 	$permalink = get_permalink($post, true);
 
 	// Replace custom post_type Token with generic pagename token for ease of use.
