Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 17468)
+++ wp-includes/post.php	(working copy)
@@ -1793,7 +1793,8 @@
 	if ( false !== $count )
 		return $count;
 
-	$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
+	$query = apply_filters( 'wp_count_posts_sql', $wpdb->prepare( $query, $type ), $type, $perm );
+	$count = $wpdb->get_results( $query, ARRAY_A );
 
 	$stats = array();
 	foreach ( get_post_stati() as $state )
@@ -1805,7 +1806,7 @@
 	$stats = (object) $stats;
 	wp_cache_set($cache_key, $stats, 'counts');
 
-	return $stats;
+	return apply_filters( 'wp_count_posts', $stats, $type, $perm );
 }
 
 
@@ -5012,7 +5013,7 @@
  * @uses wp_find_hierarchy_loop()
  *
  * @param int $post_parent ID of the parent for the post we're checking.
- * @parem int $post_ID ID of the post we're checking.
+ * @param int $post_ID ID of the post we're checking.
  *
  * @return int The new post_parent for the post.
  */
@@ -5236,4 +5237,23 @@
 }
 add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
 
-?>
\ No newline at end of file
+/**
+ * Return array of posts for post_type='page' for those pages with the given page template.
+ *
+ * @param string $template Filename of the assigned template for a page.
+ *
+ * @return array The posts that have a template matching the one passed.
+ */
+function get_pages_by_template( $template, $args ) {
+	global $wpdb;
+	$args = wp_parse_args($args,array(
+		'post_type' => 'page',
+		'posts_per_page' => -1,
+		'meta_key' => '_wp_page_template',
+		'meta_value' => $template,
+		'suppress_filters' => true,
+	));
+	$result = new WP_Query($args);
+	return apply_filters( 'get_pages_by_template', $result->posts );
+}
+?>
