Index: wp-includes/class-wp-xmlrpc-server.php
===================================================================
--- wp-includes/class-wp-xmlrpc-server.php	(revision 19640)
+++ wp-includes/class-wp-xmlrpc-server.php	(working copy)
@@ -64,6 +64,7 @@
 			'wp.getMediaItem'		=> 'this:wp_getMediaItem',
 			'wp.getMediaLibrary'	=> 'this:wp_getMediaLibrary',
 			'wp.getPostFormats'     => 'this:wp_getPostFormats',
+			'wp.getPosts'			=> 'this:wp_getPosts',
 
 			// Blogger API
 			'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
@@ -1702,6 +1703,204 @@
 		return $formats;
 	}
 
+	/**
+	 * Prepares term data for return in an XML-RPC object
+	 *
+	 * @param array $term The unprepared term data
+	 * @return array The prepared term data
+	 */
+	function prepare_term( $term ) {
+		$_term = (array) $term;
+
+		return apply_filters( 'xmlrpc_prepare_term', $_term, $term );
+	}
+
+	function prepare_post( $post, $fields ) {
+		// holds the data for this post. built up based on $fields
+		$_post = array( 'post_id' => $post['ID'] );
+
+		// prepare common post fields
+		$post_fields = array(
+			'post_title' => $post['post_title'],
+			'post_date' => new IXR_Date(mysql2date( 'Ymd\TH:i:s', $post['post_date'], false )),
+			'post_date_gmt' => new IXR_Date(mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false )),
+			'post_modified' => new IXR_Date(mysql2date( 'Ymd\TH:i:s', $post['post_modified'], false )),
+			'post_modified_gmt' => new IXR_Date(mysql2date( 'Ymd\TH:i:s', $post['post_modified_gmt'], false )),
+			'post_status' => $post['post_status'],
+			'post_type' => $post['post_type'],
+			'post_slug' => $post['post_name'],
+			'post_author' => $post['post_author'],
+			'post_password' => $post['post_password'],
+			'post_excerpt' => $post['post_excerpt'],
+			'post_content' => $post['post_content'],
+			'link' => post_permalink( $post['ID'] ),
+			'comment_status' => $post['comment_status'],
+			'ping_status' => $post['ping_status'],
+			'sticky' => ($post['post_type'] === 'post' && is_sticky( $post['ID'] ) ),
+		);
+
+		// Consider future posts as published
+		if ( $post_fields['post_status'] === 'future' )
+			$post_fields['post_status'] = 'publish';
+
+		// Fill in blank post format
+		$post_fields['post_format'] = get_post_format( $post['ID'] );
+		if ( empty( $post_fields['post_format'] ) )
+			$post_fields['post_format'] = 'standard';
+
+		// Merge requested $post_fields fields into $_post
+		if ( in_array( 'post', $fields ) ) {
+			$_post = array_merge( $_post, $post_fields );
+		} else {
+			$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) );
+			$_post = array_merge( $_post, $requested_fields );
+		}
+
+		$all_taxonomy_fields = in_array( 'taxonomies', $fields );
+
+		if ( $all_taxonomy_fields || in_array( 'terms', $fields ) ) {
+			$post_type_taxonomies = get_object_taxonomies( $post['post_type'] , 'names' );
+			$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies );
+			$_post['terms'] = array();
+			foreach ( $terms as $term ) {
+				$_post['terms'][] = $this->prepare_term( $term );
+			}
+		}
+
+		// backward compatiblity
+		if ( $all_taxonomy_fields || in_array( 'tags', $fields ) ) {
+			$tagnames = array();
+			$tags = wp_get_post_tags( $post['ID'] );
+			if ( !empty( $tags ) ) {
+				foreach ( $tags as $tag )
+					$tagnames[] = $tag->name;
+				$tagnames = implode( ', ', $tagnames );
+			} else {
+				$tagnames = '';
+			}
+			$_post['tags'] = $tagnames;
+		}
+
+		// backward compatiblity
+		if ( $all_taxonomy_fields || in_array( 'categories', $fields ) ) {
+			$categories = array();
+			$catids = wp_get_post_categories( $post['ID'] );
+			foreach($catids as $catid) {
+				$categories[] = get_cat_name($catid);
+			}
+			$_post['categories'] = $categories;
+		}
+
+		if ( in_array( 'custom_fields', $fields ) )
+			$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] );
+
+		if ( in_array( 'enclosure', $fields ) ) {
+			$_post['enclosure'] = array();
+			$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' );
+			if ( ! empty ( $enclosures ) ) {
+				$encdata = explode("\n", $enclosures[0]);
+				$_post['enclosure']['url'] = trim(htmlspecialchars($encdata[0]));
+				$_post['enclosure']['length'] = (int) trim($encdata[1]);
+				$_post['enclosure']['type'] = trim($encdata[2]);
+			}
+		}
+
+		return apply_filters( 'xmlrpc_prepare_post', $_post, $post, $fields );
+	}
+
+	/**
+	 * Retrieve posts.
+	 *
+	 * The optional $filter parameter modifies the query used to retrieve posts.
+	 * Accepted keys are 'post_type', 'post_status', 'number', 'offset',
+	 * 'orderby', and 'order'.
+	 *
+	 * The optional $fields parameter specifies what fields will be included
+	 * in the response array.
+	 *
+	 * @uses wp_get_recent_posts()
+	 * @see wp_getPost() for more on $fields
+	 * @see get_posts() for more on $filter values
+	 *
+	 * @param array $args Method parameters. Contains:
+	 *  - int     $blog_id
+	 *  - string  $username
+	 *  - string  $password
+	 *  - array   $filter optional
+	 *  - array   $fields optional
+	 * @return array cntains a collection of posts.
+	 */
+	function wp_getPosts( $args ) {
+		$this->escape( $args );
+
+		$blog_id    = (int) $args[0];
+		$username   = $args[1];
+		$password   = $args[2];
+		$filter     = isset( $args[3] ) ? $args[3] : array();
+
+		if ( isset( $args[4] ) )
+			$fields = $args[4];
+		else
+			$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' );
+
+		if ( !$user = $this->login( $username, $password ) )
+			return $this->error;
+
+		do_action( 'xmlrpc_call', 'wp.getPosts' );
+
+		$query = array();
+
+		if ( isset( $filter['post_type'] ) ) {
+			$post_type = get_post_type_object( $filter['post_type'] );
+			if( !( (bool)$post_type ) )
+				return new IXR_Error( 403, __( 'The post type specified is not valid' ) );
+
+			if( ! current_user_can( $post_type->cap->edit_posts ) )
+				return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
+			$query['post_type'] = $filter['post_type'];
+		}
+
+		if ( isset( $filter['post_status'] ) ) {
+			$query['post_status'] = $filter['post_status'];
+		}
+
+		if ( isset ( $filter['number'] ) ) {
+			$query['number'] = absint( $filter['number'] );
+		}
+
+		if ( isset ( $filter['offset'] ) ) {
+			$query['offset'] = absint( $filter['offset'] );
+		}
+
+		if ( isset ( $filter['orderby'] ) ) {
+			$query['orderby'] = $filter['orderby'];
+
+			if ( isset ( $filter['order'] ) ) {
+				$query['order'] = $filter['order'];
+			}
+		}
+
+		do_action('xmlrpc_call', 'wp.getPosts');
+
+		$posts_list = wp_get_recent_posts( $query );
+
+		if ( !$posts_list )
+			return array( );
+
+		// holds all the posts data
+		$struct = array();
+
+		foreach ( $posts_list as $post ) {
+			$post_type = get_post_type_object( $post['post_type'] );
+			if( !current_user_can( $post_type->cap->edit_posts, $post['ID'] ) )
+				continue;
+
+			$struct[] = $this->prepare_post( $post, $fields );
+		}
+
+		return $struct;
+	}
+
 	/* Blogger API functions.
 	 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
 	 */
