diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-07-03 17:57:03 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-07-03 17:57:03 +0000 |
commit | 1415340ce390e2fa6a872e5efa9a152e34840454 (patch) | |
tree | 31aef1e02db3a18033d50da9bedd718adc349fe1 /modules | |
parent | 0ccb4c40d147d222d081aa2528ee891701efd8b2 (diff) | |
download | brdo-1415340ce390e2fa6a872e5efa9a152e34840454.tar.gz brdo-1415340ce390e2fa6a872e5efa9a152e34840454.tar.bz2 |
- Patch #191499 by catch: remove display order settings and cleaned up some white space.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/comment.install | 30 | ||||
-rw-r--r-- | modules/comment/comment.module | 101 | ||||
-rw-r--r-- | modules/comment/comment.test | 4 |
3 files changed, 53 insertions, 82 deletions
diff --git a/modules/comment/comment.install b/modules/comment/comment.install index 598b476bf..cc1ea7353 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -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(). diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 67861b078..fd949a2f6 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -41,16 +41,6 @@ define('COMMENT_MODE_THREADED_COLLAPSED', 3); 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, $form_state, $form_id) { '#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($node) { 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($setting, $node) { $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); } diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 96a285040..4f28ea4f5 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -293,7 +293,7 @@ class CommentTestCase extends DrupalWebTestCase { } /** - * 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 DrupalWebTestCase { * 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 .'.'); } /** |