? comment_order.patch
Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal/drupal/CHANGELOG.txt,v
retrieving revision 1.268
diff -u -p -r1.268 CHANGELOG.txt
--- CHANGELOG.txt	20 May 2008 20:13:34 -0000	1.268
+++ CHANGELOG.txt	3 Jul 2008 14:33:54 -0000
@@ -13,6 +13,8 @@ Drupal 7.0, xxxx-xx-xx (development vers
     * Implemented drag-and-drop positioning for poll options.
     * Provided descriptions for user permissions.
     * Removed comment controls for users.
+    * Removed display order settings for comment module. Comment display
+      order can now be customised using the Views module.
 - Search:
     * Added support for language-aware searches.
 - Testing:
Index: modules/comment/comment.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.install,v
retrieving revision 1.22
diff -u -p -r1.22 comment.install
--- modules/comment/comment.install	14 May 2008 13:12:40 -0000	1.22
+++ modules/comment/comment.install	3 Jul 2008 14:33:54 -0000
@@ -24,6 +24,11 @@ function comment_update_1() {
   return array();
 }
 
+/**
+ * @defgroup updates-5.x-to-6.x Comment updates from 5.x to 6.x
+ * @{
+ */
+
 function comment_update_6001() {
   $ret[] = update_sql("ALTER TABLE {comments} DROP score");
   $ret[] = update_sql("ALTER TABLE {comments} DROP users");
@@ -70,6 +75,31 @@ function comment_update_6003() {
   return $ret;
 }
 
+/**
+ * @} End of "defgroup updates-5.x-to-6.x"
+ * The next series of updates should start at 7000.
+ */
+
+/**
+ * @defgroup updates-6.x-to-7.x Comment updates from 6.x to 7.x
+ * @{
+ */
+ 
+/**
+ * Remove comment settings for page ordering.
+ */
+function comment_update_7000() {
+  $types = node_get_types();
+  foreach ($types as $type => $object) {
+    variable_del('comment_default_order' . $type);
+  }
+  return array(array('success' => TRUE, 'query' => 'Comment order settings removed.'));
+}
+  
+/**
+ * @} End of "defgroup updates-6.x-to-7.x"
+ * The next series of updates should start at 8000.
+ */
 
 /**
  * Implementation of hook_schema().
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.641
diff -u -p -r1.641 comment.module
--- modules/comment/comment.module	20 Jun 2008 16:52:55 -0000	1.641
+++ modules/comment/comment.module	3 Jul 2008 14:33:54 -0000
@@ -41,16 +41,6 @@ define('COMMENT_MODE_THREADED_COLLAPSED'
 define('COMMENT_MODE_THREADED_EXPANDED', 4);
 
 /**
- * Comments are ordered by date - newest first.
- */
-define('COMMENT_ORDER_NEWEST_FIRST', 1);
-
-/**
- * Comments are ordered by date - oldest first.
- */
-define('COMMENT_ORDER_OLDEST_FIRST', 2);
-
-/**
  * Anonymous posters cannot enter their contact information.
  */
 define('COMMENT_ANONYMOUS_MAYNOT_CONTACT', 0);
@@ -230,7 +220,6 @@ function comment_node_type($op, $info) {
   $settings = array(
     'comment',
     'comment_default_mode',
-    'comment_default_order',
     'comment_default_per_page',
     'comment_anonymous',
     'comment_subject_field',
@@ -350,35 +339,24 @@ function comment_get_recent($number = 10
 function comment_new_page_count($num_comments, $new_replies, $node) {
   $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
   $mode = _comment_get_display_setting('mode', $node);
-  $order = _comment_get_display_setting('sort', $node);
   $pagenum = NULL;
   $flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED));
-  if ($num_comments <= $comments_per_page || ($flat && $order == COMMENT_ORDER_NEWEST_FIRST)) {
-    // Only one page of comments or flat forum and newest first.
-    // First new comment will always be on first page.
+  if ($num_comments <= $comments_per_page) {
+    // Only one page of comments.
     $pageno = 0;
   }
+  elseif ($flat) {
+    // Flat comments.
+    $count = $num_comments - $new_replies;
+    $pageno =  $count / $comments_per_page;
+  }
   else {
-    if ($flat) {
-      // Flat comments and oldest first.
-      $count = $num_comments - $new_replies;
-    }
-    else {
-      // Threaded comments. See the documentation for comment_render().
-      if ($order == COMMENT_ORDER_NEWEST_FIRST) {
-        // Newest first: find the last thread with a new comment.
-        $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY thread DESC LIMIT 1', $node->nid, $new_replies);
-        $thread = db_result($result);
-        $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND thread > '" . $thread . "'", $node->nid);
-      }
-      else {
-        // Oldest first: find the first thread with a new comment.
-        $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1)) LIMIT 1', $node->nid, $new_replies);
-        $thread = substr(db_result($result), 0, -1);
-        $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '" . $thread . "'", $node->nid);
-      }
-      $count = db_result($result_count);
-    }
+    // Threaded comments.
+    // Find the first thread with a new comment.
+    $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1)) LIMIT 1', $node->nid, $new_replies);
+    $thread = substr(db_result($result), 0, -1);
+    $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '" . $thread . "'", $node->nid);
+    $count = db_result($result_count);
     $pageno =  $count / $comments_per_page;
   }
 
@@ -511,13 +489,6 @@ function comment_form_alter(&$form, $for
       '#options' => _comment_get_modes(),
       '#description' => t('Expanded views display the body of the comment. Threaded views keep replies together.'),
     );
-    $form['comment']['comment_default_order'] = array(
-      '#type' => 'radios',
-      '#title' => t('Display order'),
-      '#default_value' => variable_get('comment_default_order_' . $form['#node_type']->type, COMMENT_ORDER_NEWEST_FIRST),
-      '#options' => _comment_get_orders(),
-      '#description' => t('Comments are displayed in ascending or descending order.'),
-    );
     $form['comment']['comment_default_per_page'] = array(
       '#type' => 'select',
       '#title' => t('Comments per page'),
@@ -921,7 +892,6 @@ function comment_render($node, $cid = 0)
     }
 
     $mode = _comment_get_display_setting('mode', $node);
-    $order = _comment_get_display_setting('sort', $node);
     $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
 
     if ($cid && is_numeric($cid)) {
@@ -955,30 +925,19 @@ function comment_render($node, $cid = 0)
         $query_count .= ' AND c.status = %d';
         $query_args[] = COMMENT_PUBLISHED;
       }
-
-      if ($order == COMMENT_ORDER_NEWEST_FIRST) {
-        if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
-          $query .= ' ORDER BY c.cid DESC';
-        }
-        else {
-          $query .= ' ORDER BY c.thread DESC';
-        }
+      if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
+        $query .= ' ORDER BY c.cid';
       }
-      elseif ($order == COMMENT_ORDER_OLDEST_FIRST) {
-        if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
-          $query .= ' ORDER BY c.cid';
-        }
-        else {
-          // See comment above. Analysis reveals that this doesn't cost too
-          // much. It scales much much better than having the whole comment
-          // structure.
-          $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
-        }
+      else {
+        // See comment above. Analysis reveals that this doesn't cost too
+        // much. It scales much much better than having the whole comment
+        // structure.
+        $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
       }
+      
       $query = db_rewrite_sql($query, 'c', 'cid');
       $query_count = db_rewrite_sql($query_count, 'c', 'cid');
 
-      // Start a form, for use with comment control.
       $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
 
       $divs = 0;
@@ -1770,7 +1729,6 @@ function theme_comment_post_forbidden($n
 function template_preprocess_comment_wrapper(&$variables) {
   // Provide contextual information.
   $variables['display_mode']  = _comment_get_display_setting('mode', $variables['node']);
-  $variables['display_order'] = _comment_get_display_setting('sort', $variables['node']);
   $variables['template_files'][] = 'comment-wrapper-' . $variables['node']->type;
 }
 
@@ -1805,19 +1763,6 @@ function _comment_get_modes() {
 }
 
 /**
- * Return an array of viewing orders for comment listings.
- *
- * We can't use a global variable array because the locale system
- * is not initialized yet when the comment module is loaded.
- */
-function _comment_get_orders() {
-  return array(
-    COMMENT_ORDER_NEWEST_FIRST => t('Date - newest first'),
-    COMMENT_ORDER_OLDEST_FIRST => t('Date - oldest first')
-  );
-}
-
-/**
  * Return an array of "comments per page" settings from which the user
  * can choose.
  */
@@ -1839,10 +1784,6 @@ function _comment_get_display_setting($s
       $value = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED_EXPANDED);
       break;
 
-    case 'sort':
-      $value = variable_get('comment_default_order_' . $node->type, COMMENT_ORDER_NEWEST_FIRST);
-      break;
-
     case 'comments_per_page':
       $value = variable_get('comment_default_per_page_' . $node->type, 50);
   }
Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.9
diff -u -p -r1.9 comment.test
--- modules/comment/comment.test	24 Jun 2008 17:01:33 -0000	1.9
+++ modules/comment/comment.test	3 Jul 2008 14:33:55 -0000
@@ -293,7 +293,7 @@ class CommentTestCase extends DrupalWebT
   }
 
   /**
-   * Checks current pag for specified comment.
+   * Checks current page for specified comment.
    *
    * @param object $comment Comment object.
    * @param boolean $reply The comment is a reply to another comment.
@@ -373,7 +373,7 @@ class CommentTestCase extends DrupalWebT
    *   Comments per page value.
    */
   function setCommentsPerPage($number) {
-    $this->setCommentSettings('comment_default_per_page', $number, 'Number of comments per page set to ' . $number .'.');
+    $this->setCommentSettings('comment_default_per_page_article', $number, 'Number of comments per page set to ' . $number .'.');
   }
 
   /**
