Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.492
diff -u -p -r1.492 taxonomy.module
--- modules/taxonomy/taxonomy.module	2 Aug 2009 15:44:08 -0000	1.492
+++ modules/taxonomy/taxonomy.module	3 Aug 2009 16:32:27 -0000
@@ -1584,19 +1584,16 @@ function theme_taxonomy_term_select($ele
  * @param $depth
  *   How many levels deep to traverse the taxonomy tree. Can be a non-negative
  *   integer or "all".
- * @param $pager
- *   Whether the nodes are to be used with a pager (the case on most Drupal
- *   pages) or not (in an XML feed, for example).
- * @param $order
- *   The order clause for the query that retrieve the nodes.
- *   It is important to specifc the table alias (n).
- *
- *   Example:
- *   array('table_alias.field_name' = 'DESC');
  * @return
- *   An array of node IDs.
+ *   A SelectQuery object pre-configured to select the matching node IDs.
+ *   Example use case:
+ *   <code>
+ *   $nids = taxonomy_select_nodes(array($tid))
+ *     ->execute()
+ *     ->fetchCol();
+ *   </code>
  */
-function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE, $order = array('n.sticky' => 'DESC', 'n.created' =>  'DESC')) {
+function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0) {
   if (count($tids) <= 0) {
     return array();
   }
@@ -1611,9 +1608,11 @@ function taxonomy_select_nodes($tids = a
     $descendant_tids[] = array_merge(array($term->tid), array_map('_taxonomy_get_tid_from_term', $tree));
   }
 
-  $query = db_select('node', 'n');
-  $query->addTag('node_access');
-  $query->condition('n.status', 1);
+  $query = db_select('node', 'n')
+    ->addTag('node_access')
+    ->fields('n', array('nid'))
+    ->condition('n.status', 1)
+    ->distinct();
 
   if ($operator == 'or') {
       $args = call_user_func_array('array_merge', $descendant_tids);
@@ -1626,30 +1625,7 @@ function taxonomy_select_nodes($tids = a
       $query->condition($alias . '.tid', $tids, 'IN');
     }
   }
-
-  if ($pager) {
-    $count_query = clone $query;
-    $count_query->addExpression('COUNT(DISTINCT n.nid)');
-
-    $query = $query
-      ->extend('PagerDefault')
-      ->limit(variable_get('default_nodes_main', 10));
-    $query->setCountQuery($count_query);
-  }
-  else {
-    $query->range(0, variable_get('feed_default_items', 10));
-  }
-
-  $query->distinct(TRUE);
-  $query->addField('n', 'nid');
-  foreach ($order as $field => $direction) {
-    $query->orderBy($field, $direction);
-    // ORDER BY fields need to be loaded too, assume they are in the form table_alias.name
-    list($table_alias, $name) = explode('.', $field);
-    $query->addField($table_alias, $name);
-  }
-
-  return $query->execute()->fetchCol();
+  return $query;
 }
 
 /**
Index: modules/taxonomy/taxonomy.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v
retrieving revision 1.31
diff -u -p -r1.31 taxonomy.pages.inc
--- modules/taxonomy/taxonomy.pages.inc	8 Jul 2009 07:18:08 -0000	1.31
+++ modules/taxonomy/taxonomy.pages.inc	3 Aug 2009 16:32:27 -0000
@@ -41,7 +41,19 @@ function taxonomy_term_page($term) {
     );
   }
 
-  if ($nids = taxonomy_select_nodes(array($term->tid), NULL, TRUE)) {
+  $query = taxonomy_select_nodes(array($term->tid))->extend('PagerDefault');
+  $count_query = clone $query;
+  $count_query->addExpression('COUNT(DISTINCT n.nid)');
+  $query->setCountQuery($count_query);
+
+  $nids = $query
+    ->fields('n', array('sticky', 'created'))
+    ->orderBy('n.sticky', 'DESC')
+    ->orderBy('n.created', 'DESC')
+    ->limit(variable_get('default_nodes_main', 10))
+    ->execute()
+    ->fetchCol();
+  if ($nids) {
     $nodes = node_load_multiple($nids);
     $build += node_build_multiple($nodes);
     $build['pager'] = array(
@@ -71,7 +83,10 @@ function taxonomy_term_feed($term) {
   // Only display the description if we have a single term, to avoid clutter and confusion.
   // HTML will be removed from feed description, so no need to filter here.
   $channel['description'] = $term->description;
-  $nids = taxonomy_select_nodes(array($term->tid, NULL, NULL, FALSE));
+  $nids = taxonomy_select_nodes(array($term->tid))
+    ->range(0, variable_get('feed_default_items', 10))
+    ->execute()
+    ->fetchCol();
 
   node_feed($nids, $channel);
 }
