Commit 75d449d1 authored by Dries's avatar Dries
Browse files

- Patch #506218 by catch: remove collapsed comments as is and tidy up comment settings.

parent 603efa27
......@@ -109,6 +109,23 @@ function comment_update_7003() {
return $ret;
}
/**
* Rename comment display setting variables.
*/
function comment_update_7004() {
$types = node_type_get_types();
foreach ($types as $type => $object) {
$setting = variable_get('comment_default_mode_' . $type, 4);
if ($setting == 3 || $setting == 4) {
variable_set('comment_default_mode_' . $type, 1);
}
else {
variable_set('comment_default_mode_' . $type, 0);
}
}
return array();
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
......@@ -20,25 +20,15 @@
*/
define('COMMENT_PUBLISHED', 1);
/**
* Comments are displayed in a flat list - collapsed.
*/
define('COMMENT_MODE_FLAT_COLLAPSED', 1);
/**
* Comments are displayed in a flat list - expanded.
*/
define('COMMENT_MODE_FLAT_EXPANDED', 2);
/**
* Comments are displayed as a threaded list - collapsed.
*/
define('COMMENT_MODE_THREADED_COLLAPSED', 3);
define('COMMENT_MODE_FLAT', 0);
/**
* Comments are displayed as a threaded list - expanded.
*/
define('COMMENT_MODE_THREADED_EXPANDED', 4);
define('COMMENT_MODE_THREADED', 1);
/**
* Anonymous posters cannot enter their contact information.
......@@ -130,15 +120,9 @@ function comment_theme() {
'template' => 'comment-folded',
'arguments' => array('comment' => NULL, 'node' => NULL),
),
'comment_flat_collapsed' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
),
'comment_flat_expanded' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
),
'comment_thread_collapsed' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
),
'comment_thread_expanded' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
),
......@@ -404,7 +388,7 @@ 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);
$pagenum = NULL;
$flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED));
$flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;
if ($num_comments <= $comments_per_page) {
// Only one page of comments.
$pageno = 0;
......@@ -526,7 +510,7 @@ function comment_node_view($node, $build_mode) {
'fragment' => 'comment-form',
'html' => TRUE,
);
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
$links['comment_add']['href'] = "comment/reply/$node->nid";
}
else {
......@@ -569,61 +553,53 @@ function comment_form_node_type_form_alter(&$form, $form_state) {
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['comment']['comment'] = array(
'#type' => 'radios',
'#title' => t('Default comment setting'),
'#default_value' => variable_get('comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN),
'#options' => array(t('Hidden'), t('Closed'), t('Open')),
'#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
);
$form['comment']['comment_default_mode'] = array(
'#type' => 'radios',
'#title' => t('Default display mode'),
'#default_value' => variable_get('comment_default_mode_' . $form['#node_type']->type, COMMENT_MODE_THREADED_EXPANDED),
'#options' => _comment_get_modes(),
'#description' => t('Expanded views display the body of the comment. Threaded views keep replies together.'),
'#type' => 'checkbox',
'#title' => t('Threading'),
'#default_value' => variable_get('comment_default_mode_' . $form['#node_type']->type, COMMENT_MODE_THREADED),
'#description' => t('Show comment replies in a threaded list.'),
);
$form['comment']['comment_default_per_page'] = array(
'#type' => 'select',
'#title' => t('Comments per page'),
'#default_value' => variable_get('comment_default_per_page_' . $form['#node_type']->type, 50),
'#options' => _comment_per_page(),
'#description' => t('Additional comments will be displayed on separate pages.'),
);
$form['comment']['comment'] = array(
'#type' => 'select',
'#title' => t('Default comment setting for new content'),
'#default_value' => variable_get('comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN),
'#options' => array(t('Hidden'), t('Closed'), t('Open')),
);
$form['comment']['comment_anonymous'] = array(
'#type' => 'radios',
'#type' => 'select',
'#title' => t('Anonymous commenting'),
'#default_value' => variable_get('comment_anonymous_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT),
'#options' => array(
COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'),
COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'),
COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information')),
'#description' => t('This option is enabled when anonymous users have permission to post comments on the <a href="@url">permissions page</a>.', array('@url' => url('admin/user/permissions', array('fragment' => 'module-comment')))),
COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'))
);
if (!user_access('post comments', drupal_anonymous_user())) {
$form['comment']['comment_anonymous']['#disabled'] = TRUE;
$form['comment']['comment_anonymous']['#access'] = FALSE;
}
$form['comment']['comment_subject_field'] = array(
'#type' => 'radios',
'#title' => t('Comment subject field'),
'#type' => 'checkbox',
'#title' => t('Allow comment title'),
'#default_value' => variable_get('comment_subject_field_' . $form['#node_type']->type, 1),
'#options' => array(t('Disabled'), t('Enabled')),
'#description' => t('Can users provide a unique subject for their comments?'),
);
$form['comment']['comment_preview'] = array(
'#type' => 'radios',
'#title' => t('Preview comment'),
'#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, COMMENT_PREVIEW_REQUIRED),
'#options' => array(t('Optional'), t('Required')),
'#description' => t("Forces a user to look at their comment by clicking on a 'Preview' button before they can actually add the comment"),
);
$form['comment']['comment_form_location'] = array(
'#type' => 'radios',
'#title' => t('Location of comment submission form'),
'#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_SEPARATE_PAGE),
'#options' => array(t('Display on separate page'), t('Display below post or comments')),
'#type' => 'checkbox',
'#title' => t('Show reply form on the same page as comments'),
'#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW),
);
$form['comment']['comment_preview'] = array(
'#type' => 'checkbox',
'#title' => t('Require preview'),
'#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, COMMENT_PREVIEW_OPTIONAL),
);
}
}
......@@ -1193,7 +1169,7 @@ function comment_render($node, $cid = 0) {
$query->condition('c.status', COMMENT_PUBLISHED);
$count_query->condition('c.status', COMMENT_PUBLISHED);
}
if ($mode === COMMENT_MODE_FLAT_COLLAPSED || $mode === COMMENT_MODE_FLAT_EXPANDED) {
if ($mode === COMMENT_MODE_FLAT) {
$query->orderBy('c.cid', 'ASC');
}
else {
......@@ -1215,7 +1191,7 @@ function comment_render($node, $cid = 0) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->depth = count(explode('.', $comment->thread)) - 1;
if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
if ($mode == COMMENT_MODE_THREADED) {
if ($comment->depth > $divs) {
$divs++;
$comments .= '<div class="indented">';
......@@ -1228,16 +1204,10 @@ function comment_render($node, $cid = 0) {
}
}
if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
$comments .= theme('comment_flat_collapsed', $comment, $node);
}
elseif ($mode == COMMENT_MODE_FLAT_EXPANDED) {
if ($mode == COMMENT_MODE_FLAT) {
$comments .= theme('comment_flat_expanded', $comment, $node);
}
elseif ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
$comments .= theme('comment_thread_collapsed', $comment, $node);
}
elseif ($mode == COMMENT_MODE_THREADED_EXPANDED) {
elseif ($mode == COMMENT_MODE_THREADED) {
$comments .= theme('comment_thread_expanded', $comment, $node);
}
$num_rows = TRUE;
......@@ -1251,7 +1221,7 @@ function comment_render($node, $cid = 0) {
// If enabled, show new comment form if it's not already being displayed.
$reply = arg(0) == 'comment' && arg(1) == 'reply';
if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_BELOW) && !$reply) {
if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW) && !$reply) {
$output .= theme('comment_form_box', array('nid' => $nid), t('Post new comment'));
}
if ($output) {
......@@ -1389,9 +1359,9 @@ function comment_get_display_ordinal($cid, $node_type) {
if (!user_access('administer comments')) {
$query->condition('c1.status', COMMENT_PUBLISHED);
}
$mode = variable_get('comment_default_mode_' . $node_type, COMMENT_MODE_THREADED_EXPANDED);
$mode = variable_get('comment_default_mode_' . $node_type, COMMENT_MODE_THREADED);
if ($mode == COMMENT_MODE_FLAT_EXPANDED || $mode == COMMENT_MODE_FLAT_COLLAPSED) {
if ($mode == COMMENT_MODE_FLAT) {
// For flat comments, cid is used for ordering comments due to
// unpredicatable behavior with timestamp, so we make the same assumption
// here.
......@@ -1646,7 +1616,7 @@ function comment_form(&$form_state, $edit, $title = NULL) {
// already previewing the submission. However, if there are form errors,
// we hide the save button no matter what, so that optional form elements
// (e.g., captchas) can be updated.
if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {
if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_OPTIONAL) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
......@@ -2013,19 +1983,6 @@ function template_preprocess_comment_folded(&$variables) {
}
/**
* Theme comment flat collapsed view.
*
* @param $comment
* The comment to be themed.
* @param $node
* The comment node.
* @ingroup themeable
*/
function theme_comment_flat_collapsed($comment, $node) {
return theme('comment_view', $comment, $node, '', 0);
}
/**
* Theme comment flat expanded view.
*
......@@ -2039,19 +1996,6 @@ function theme_comment_flat_expanded($comment, $node) {
return theme('comment_view', $comment, $node, module_invoke_all('link', 'comment', $comment, 0));
}
/**
* Theme comment thread collapsed view.
*
* @param $comment
* The comment to be themed.
* @param $node
* The comment node.
* @ingroup themeable
*/
function theme_comment_thread_collapsed($comment, $node) {
return theme('comment_view', $comment, $node, '', 0);
}
/**
* Theme comment thread expanded view.
*
......@@ -2083,7 +2027,7 @@ function theme_comment_post_forbidden($node) {
if ($authenticated_post_comments) {
// We cannot use drupal_get_destination() because these links
// sometimes appear on /node and taxonomy listing pages.
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
$destination = 'destination=' . drupal_urlencode("comment/reply/$node->nid#comment-form");
}
else {
......@@ -2137,10 +2081,8 @@ function theme_comment_submitted($comment) {
*/
function _comment_get_modes() {
return array(
COMMENT_MODE_FLAT_COLLAPSED => t('Flat list - collapsed'),
COMMENT_MODE_FLAT_EXPANDED => t('Flat list - expanded'),
COMMENT_MODE_THREADED_COLLAPSED => t('Threaded list - collapsed'),
COMMENT_MODE_THREADED_EXPANDED => t('Threaded list - expanded')
COMMENT_MODE_FLAT => t('Flat list'),
COMMENT_MODE_THREADED => t('Threaded list')
);
}
......@@ -2163,7 +2105,7 @@ function _comment_per_page() {
function _comment_get_display_setting($setting, $node) {
switch ($setting) {
case 'mode':
$value = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED_EXPANDED);
$value = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
break;
case 'comments_per_page':
......
......@@ -26,7 +26,7 @@ class CommentHelperCase extends DrupalWebTestCase {
* @param boolean $preview Should preview be required.
* @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
*/
function postComment($node, $subject, $comment, $preview = TRUE, $contact = NULL) {
function postComment($node, $subject, $comment, $preview = FALSE, $contact = NULL) {
$edit = array();
$edit['subject'] = $subject;
$edit['comment'] = $comment;
......@@ -248,7 +248,7 @@ class CommentInterfaceTest extends CommentHelperCase {
$this->setCommentPreview(TRUE);
$this->setCommentForm(TRUE);
$this->setCommentSubject(FALSE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, t('Comment paging changed.'));
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
$this->drupalLogout();
// Post comment without subject.
......@@ -267,7 +267,7 @@ class CommentInterfaceTest extends CommentHelperCase {
$this->drupalLogin($this->web_user);
$subject_text = $this->randomName();
$comment_text = $this->randomName();
$comment = $this->postComment($this->node, $subject_text, $comment_text);
$comment = $this->postComment($this->node, $subject_text, $comment_text, TRUE);
$comment_loaded = comment_load($comment->id);
$this->assertTrue($this->commentExists($comment), t('Comment found.'));
......@@ -280,7 +280,7 @@ class CommentInterfaceTest extends CommentHelperCase {
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$this->assertText($subject_text, t('Individual comment-reply subject found.'));
$this->assertText($comment_text, t('Individual comment-reply body found.'));
$reply = $this->postComment(NULL, '', $this->randomName());
$reply = $this->postComment(NULL, '', $this->randomName(), TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.'));
$this->assertEqual($comment->id, $reply_loaded->pid, t('Pid of a reply to a comment is set correctly.'));
......@@ -290,14 +290,14 @@ class CommentInterfaceTest extends CommentHelperCase {
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$this->assertText($subject_text, t('Individual comment-reply subject found.'));
$this->assertText($comment_text, t('Individual comment-reply body found.'));
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName());
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), t('Second reply found.'));
$this->assertEqual(rtrim($comment_loaded->thread, '/') . '.01/', $reply_loaded->thread, t('Thread of second reply grows correctly.'));
// Edit reply.
$this->drupalGet('comment/edit/' . $reply->id);
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName());
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
$this->assertTrue($this->commentExists($reply, TRUE), t('Modified reply found.'));
// Correct link count
......@@ -306,7 +306,7 @@ class CommentInterfaceTest extends CommentHelperCase {
// Confirm a new comment is posted to the correct page.
$this->setCommentsPerPage(2);
$comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName());
$comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
$this->assertTrue($this->commentExists($comment_new_page), t('Page one exists. %s'));
$this->drupalGet('node/' . $this->node->nid, array('query' => 'page=1'));
$this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s'));
......@@ -351,7 +351,7 @@ class CommentInterfaceTest extends CommentHelperCase {
// Submit comment through node form.
$this->drupalLogin($this->web_user);
$this->drupalGet('node/' . $this->node->nid);
$form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
$form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
$this->assertTrue($this->commentExists($form_comment), t('Form comment found.'));
// Disable comment form on node page.
......@@ -410,12 +410,12 @@ class CommentAnonymous extends CommentHelperCase {
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertTrue($this->commentContactInfoAvailable(), t('Contact information available.'));
$anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, TRUE);
$anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), FALSE, TRUE);
$this->assertText(t('E-mail field is required.'), t('E-mail required.')); // Name should have 'Anonymous' for value by default.
$this->assertFalse($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) not found.'));
// Post comment with contact info (required).
$anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, array('mail' => 'tester@simpletest.org'));
$anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), FALSE, array('mail' => 'tester@simpletest.org'));
$this->assertTrue($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) found.'));
// Unpublish comment.
......@@ -496,7 +496,7 @@ class CommentPagerTest extends CommentHelperCase {
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT_EXPANDED, t('Comment paging changed.'));
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
// Set comments to one per page so that we are able to test paging without
// needing to insert large numbers of comments.
......@@ -537,7 +537,7 @@ class CommentPagerTest extends CommentHelperCase {
// If we switch to threaded mode, the replies on the oldest comment
// should be bumped to the first page and comment 6 should be bumped
// to the second page.
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, t('Switched to threaded mode.'));
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
$this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
$this->assertTrue($this->commentExists($reply, TRUE), t('In threaded mode, reply appears on page 1.'));
$this->assertFalse($this->commentExists($comments[1]), t('In threaded mode, comment 2 has been bumped off of page 1.'));
......@@ -575,7 +575,7 @@ class CommentApprovalTest extends CommentHelperCase {
// Post anonymous comment without contact info.
$subject = $this->randomName();
$body = $this->randomName();
$this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message.
$this->postComment($this->node, $subject, $body, FALSE, TRUE); // Set $contact to true so that it won't check for id and message.
$this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), t('Comment requires approval.'));
// Get unapproved comment id.
......@@ -609,7 +609,7 @@ class CommentApprovalTest extends CommentHelperCase {
// Post anonymous comment without contact info.
$subject = $this->randomName();
$body = $this->randomName();
$this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message.
$this->postComment($this->node, $subject, $body, FALSE, TRUE); // Set $contact to true so that it won't check for id and message.
$this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), t('Comment requires approval.'));
// Get unapproved comment id.
......
......@@ -512,11 +512,9 @@ function search_index($sid, $type, $text) {
$linknid = $match[1];
if ($linknid > 0) {
// Note: ignore links to uncacheable nodes to avoid redirect bugs.
$node = db_fetch_object(db_query('SELECT n.title, n.nid, n.vid, r.format FROM {node} n INNER JOIN {node_revision} r ON n.vid = r.vid WHERE n.nid = %d', $linknid));
if (filter_format_allowcache($node->format)) {
$link = TRUE;
$linktitle = $node->title;
}
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid))->fetchObject();
$link = TRUE;
$linktitle = $node->title;
}
}
}
......
......@@ -387,7 +387,7 @@ class UserCancelTestCase extends DrupalWebTestCase {
// Create comment.
module_load_include('test', 'comment');
$comment = CommentHelperCase::postComment($node, '', $this->randomName(32), TRUE, TRUE);
$comment = CommentHelperCase::postComment($node, '', $this->randomName(32), FALSE, TRUE);
$this->assertTrue(comment_load($comment->id), t('Comment found.'));
// Create a node with two revisions, the initial one belonging to the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment