Index: modules/comment/comment.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.admin.inc,v
retrieving revision 1.36
diff -u -p -r1.36 comment.admin.inc
--- modules/comment/comment.admin.inc 3 Nov 2009 05:27:18 -0000 1.36
+++ modules/comment/comment.admin.inc 10 Nov 2009 19:36:08 -0000
@@ -69,10 +69,12 @@ function comment_admin_overview($form, &
$query = db_select('comment', 'c')->extend('PagerDefault')->extend('TableSort');
$query->join('users', 'u', 'u.uid = c.uid');
$query->join('node', 'n', 'n.nid = c.nid');
+ $query->join('field_data_comment_body', 'b', 'c.cid = b.entity_id');
$query->addField('u', 'name', 'registered_name');
$query->addField('n', 'title', 'node_title');
+ $query->addField('b', 'comment_body_value', 'comment_body');
$result = $query
- ->fields('c', array('subject', 'nid', 'cid', 'comment', 'changed', 'status', 'name', 'homepage'))
+ ->fields('c', array('subject', 'nid', 'cid', 'changed', 'status', 'name', 'homepage'))
->fields('u', array('uid'))
->condition('c.status', $status)
->limit(50)
@@ -91,7 +93,7 @@ function comment_admin_overview($form, &
'#type' => 'link',
'#title' => $comment->subject,
'#href' => 'comment/' . $comment->cid,
- '#options' => array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid),
+ '#options' => array('attributes' => array('title' => truncate_utf8($comment->comment_body, 128)), 'fragment' => 'comment-' . $comment->cid),
),
),
'author' => theme('username', array('account' => $comment)),
@@ -160,7 +162,7 @@ function comment_admin_overview_submit($
// Allow modules to respond to the updating of a comment.
module_invoke_all('comment_' . $form_state['values']['operation'], $comment);
// Add an entry to the watchdog log.
- watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)));
+ watchdog('content', 'Comment: updated %cid.', array('%cid' => $comment->cid), WATCHDOG_NOTICE, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)));
}
}
cache_clear_all();
@@ -193,7 +195,7 @@ function comment_multiple_delete_confirm
$comment = comment_load($cid);
if (is_object($comment) && is_numeric($comment->cid)) {
$subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
- $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '
', '#suffix' => check_plain($subject) . '');
+ $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid);
$comment_counter++;
}
}
@@ -235,7 +237,7 @@ function comment_confirm_delete($form, &
$form['#comment'] = $comment;
return confirm_form(
$form,
- t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)),
+ t('Are you sure you want to delete the comment by %name', array('%name' => $comment->name)),
'node/' . $comment->nid,
t('Any replies to this comment will be lost. This action cannot be undone.'),
t('Delete'),
Index: modules/comment/comment.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.install,v
retrieving revision 1.51
diff -u -p -r1.51 comment.install
--- modules/comment/comment.install 16 Oct 2009 13:20:15 -0000 1.51
+++ modules/comment/comment.install 10 Nov 2009 19:36:09 -0000
@@ -10,6 +10,9 @@
* Implement hook_uninstall().
*/
function comment_uninstall() {
+ // Delete comment_body field.
+ field_delete_field('comment_body');
+
// Remove variables.
variable_del('comment_block_count');
$node_types = array_keys(node_type_get_types());
@@ -43,6 +46,19 @@ function comment_enable() {
db_insert('node_comment_statistics')
->from($query)
->execute();
+
+ // Create comment body field.
+ // @todo this should be done in comment_install, but causes exceptions
+ // in simpletest due to dependencies between entity_get_info() and
+ // taxonomy_install().
+ $field = array(
+ 'field_name' => 'comment_body',
+ 'type' => 'text_long',
+ );
+ field_create_field($field);
+
+ // Create instances on all existing node types.
+ node_types_rebuild();
}
/**
@@ -194,6 +210,92 @@ function comment_update_7009() {
return array();
}
+ /**
+ * Create the comment_body field.
+ */
+function comment_update_7010() {
+ $ret = array();
+ // Create comment body field.
+ $field = array(
+ 'field_name' => 'comment_body',
+ 'type' => 'text_long',
+ );
+ field_create_field($field);
+
+ // Add the field to comments for all existing bundles.
+ $body_instance = array(
+ 'field_name' => 'comment_body',
+ 'label' => 'Body',
+ 'object_type' => 'comment',
+ 'settings' => array('text_processing' => 1),
+ // Hide field labels by default.
+ 'display' => array(
+ 'full' => array(
+ 'label' => 'hidden',
+ ),
+ ),
+ );
+ foreach (node_type_get_types() as $info) {
+ $body_instance['bundle'] = 'comment_node_' . $info->type;
+ field_create_instance($body_instance);
+ }
+
+ return array();
+}
+
+/**
+ * Migrate data from the comment field to field storage.
+ */
+function comment_update_7011(&$context) {
+ $ret = array();
+
+ // This is a multipass update. First set up some comment variables.
+ if (empty($context['total'])) {
+ $comments = (bool) db_query_range('SELECT 1 FROM {comment}', 0, 1)->fetchField();
+ if (!$comments) {
+ // The update will finish when $context['types'] is an empty array.
+ // Since we have nothing to do if there's no comments on the site, except
+ // drop the columns, set that here for convenience.
+ $context['types'] = array();
+ }
+ else {
+ $context['etid'] = _field_sql_storage_etid('comment');
+ $context['types'] = node_type_get_types();
+ }
+ $context['total'] = count($context['types']);
+ }
+ if (!empty($context['types'])) {
+ $type = array_shift($context['types']);
+
+ $query = db_select('comment', 'c');
+ $query->innerJoin('node', 'n', 'c.nid = n.nid AND n.type = :type', array(':type' => $type->type));
+ $query->addField('c', 'cid', 'entity_id');
+ $query->addExpression("'comment_node_$type->type'", 'bundle');
+ $query->addExpression($context['etid'], 'etid');
+ $query->addExpression('0', 'deleted');
+ $query->addExpression("'" . FIELD_LANGUAGE_NONE . "'", 'language');
+ $query->addExpression('0', 'delta');
+ $query->addField('c', 'comment', 'comment_body_value');
+ $query->addField('c', 'format', 'comment_body_format');
+
+ $comment_body = field_info_field('comment_body');
+ $comment_body_table = _field_sql_storage_tablename($comment_body);
+
+ db_insert($comment_body_table)
+ ->from($query)
+ ->execute();
+ }
+
+ // On the last pass of the update, $context['types'] will be empty.
+ if (empty($context['types'])) {
+ db_drop_field($ret, 'comment', 'subject');
+ }
+
+ $ret['#finished'] = 1 - count($context['types']) / $context['total'];
+
+ return $ret;
+}
+
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
@@ -236,12 +338,6 @@ function comment_schema() {
'default' => '',
'description' => 'The comment title.',
),
- 'comment' => array(
- 'type' => 'text',
- 'not null' => TRUE,
- 'size' => 'big',
- 'description' => 'The comment body.',
- ),
'hostname' => array(
'type' => 'varchar',
'length' => 128,
@@ -269,13 +365,6 @@ function comment_schema() {
'size' => 'tiny',
'description' => 'The published status of a comment. (0 = Not Published, 1 = Published)',
),
- 'format' => array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The {filter_format}.format of the comment body.',
- ),
'thread' => array(
'type' => 'varchar',
'length' => 255,
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.800
diff -u -p -r1.800 comment.module
--- modules/comment/comment.module 3 Nov 2009 06:47:22 -0000 1.800
+++ modules/comment/comment.module 10 Nov 2009 19:36:09 -0000
@@ -236,6 +236,22 @@ function comment_count_unpublished() {
*/
function comment_node_type_insert($info) {
field_attach_create_bundle('comment', 'comment_node_' . $info->type);
+
+ // Attach the body field by default.
+ $instance = array(
+ 'field_name' => 'comment_body',
+ 'label' =>'Body',
+ 'object_type' => 'comment',
+ 'bundle' => 'comment_node_' . $info->type,
+ 'settings' => array('text_processing' => 1),
+ // Hide field labels by default.
+ 'display' => array(
+ 'full' => array(
+ 'label' => 'hidden',
+ ),
+ ),
+ );
+ field_create_instance($instance);
}
/**
@@ -390,13 +406,17 @@ function comment_get_recent($number = 10
// and are visible to the current user.
$nids = db_query_range("SELECT nc.nid FROM {node_comment_statistics} nc WHERE nc.comment_count > 0 ORDER BY nc.last_comment_timestamp DESC", 0, $number)->fetchCol();
- $comments = array();
if (!empty($nids)) {
// Step 2: From among the comments on the nodes selected in the first query,
// find the $number of most recent comments.
// Using Query Builder here for the IN-Statement.
$query = db_select('comment', 'c');
$query->innerJoin('node', 'n', 'n.nid = c.nid');
+ $query->innerJoin('users', 'u', 'u.uid = c.uid');
+//// $query->addField('n', 'title', 'node_title');
+ $query->addExpression('IF(c.uid != 0, u.name, c.name)', 'name');
+//- ->fields('c', array('nid', 'subject', 'cid', 'created', 'changed'))
+//+ ->fields('c', array('nid', 'cid', 'uid', 'timestamp'))
return $query
->fields('c', array('nid', 'subject', 'cid', 'created', 'changed'))
->condition('c.nid', $nids, 'IN')
@@ -408,7 +428,7 @@ function comment_get_recent($number = 10
->fetchAll();
}
- return $comments;
+ return array();
}
/**
@@ -471,6 +491,7 @@ function comment_new_page_count($num_com
function theme_comment_block() {
$items = array();
$number = variable_get('comment_block_count', 10);
+
foreach (comment_get_recent($number) as $comment) {
$items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . '
' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed)));
}
@@ -839,11 +860,6 @@ function comment_build_content($comment,
// Remove previously built content, if exists.
$comment->content = array();
- // Build comment body.
- $comment->content['comment_body'] = array(
- '#markup' => check_markup($comment->comment, $comment->format, '', TRUE),
- );
-
field_attach_prepare_view('comment', array($comment->cid => $comment), $build_mode);
$comment->content += field_attach_view('comment', $comment, $build_mode);
@@ -1159,17 +1175,12 @@ function comment_node_delete(stdClass $n
* Implement hook_node_update_index().
*/
function comment_node_update_index(stdClass $node) {
- $text = '';
- if ($node->comment != COMMENT_NODE_HIDDEN) {
- $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(
- ':nid' => $node->nid,
- ':status' => COMMENT_PUBLISHED
- ));
- foreach ($comments as $comment) {
- $text .= '' . check_plain($comment->subject) . '
' . check_markup($comment->comment, $comment->format, '', TRUE);
- }
+ if ($node->comment && $cids = comment_get_thread($node)) {
+ $comments = comment_load_multiple($cids);
+ comment_prepare_thread($comments);
+ $build = comment_build_multiple($comments, $node);
}
- return $text;
+ return drupal_render($build);
}
/**
@@ -1288,8 +1299,6 @@ function comment_save($comment) {
'created' => $comment->created,
'changed' => $comment->changed,
'subject' => $comment->subject,
- 'comment' => $comment->comment,
- 'format' => $comment->comment_format,
'uid' => $comment->uid,
'name' => $comment->name,
'mail' => $comment->mail,
@@ -1302,7 +1311,7 @@ function comment_save($comment) {
// Allow modules to respond to the updating of a comment.
module_invoke_all('comment_update', $comment);
// Add an entry to the watchdog log.
- watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)));
+ watchdog('content', 'Comment: updated %cid.', array('%subject' => $comment->cid), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)));
}
else {
// Add the comment to database. This next section builds the thread field.
@@ -1364,8 +1373,6 @@ function comment_save($comment) {
'pid' => empty($comment->pid) ? 0 : $comment->pid,
'uid' => $comment->uid,
'subject' => $comment->subject,
- 'comment' => $comment->comment,
- 'format' => $comment->comment_format,
'hostname' => ip_address(),
'created' => $comment->created,
'changed' => $comment->changed,
@@ -1431,6 +1438,7 @@ function comment_delete_multiple($cids)
comment_delete_multiple($child_cids);
_comment_update_node_statistics($comment->nid);
}
+ //parent::attachLoad($comments);
}
}
@@ -1841,15 +1849,6 @@ function comment_form($form, &$form_stat
$default = '';
}
- $form['comment'] = array(
- '#type' => 'textarea',
- '#title' => t('Comment'),
- '#rows' => 15,
- '#default_value' => $default,
- '#text_format' => isset($comment->format) ? $comment->format : filter_default_format(),
- '#required' => TRUE,
- );
-
$form['cid'] = array(
'#type' => 'value',
'#value' => !empty($comment->cid) ? $comment->cid : NULL,
@@ -1924,8 +1923,7 @@ function comment_preview($comment) {
$node = node_load($comment->nid);
if (!form_get_errors()) {
- $comment->format = $comment->comment_format;
-
+ $comment->format = $comment->comment_body['zxx'][0]['format'];
// Attach the user and time information.
if (!empty($comment->author)) {
$account = user_load_by_name($comment->author);
@@ -2054,13 +2052,15 @@ function comment_submit($comment) {
// 1) Filter it into HTML
// 2) Strip out all HTML tags
// 3) Convert entities back to plain-text.
- $comment['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment['comment'], $comment['comment_format'])))), 29, TRUE);
+
+ $comment['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment['comment_body']['zxx'][0]['value'], $comment['comment_body']['zxx'][0]['format'])))), 29, TRUE);
// Edge cases where the comment body is populated only by HTML tags will
// require a default subject.
if ($comment['subject'] == '') {
$comment['subject'] = t('(No subject)');
}
}
+
return (object)$comment;
}
@@ -2109,8 +2109,8 @@ function comment_form_submit($form, &$fo
$redirect = array('node/' . $node->nid, array('query' => $query, 'fragment' => 'comment-' . $comment->cid));
}
else {
- watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject), WATCHDOG_WARNING);
- drupal_set_message(t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject)), 'error');
+ watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %title.', array('%title' => $node->title), WATCHDOG_WARNING);
+ drupal_set_message(t('Comment: unauthorized comment submitted or comment submitted to a closed post %title.', array('%title' => $node->title)), 'error');
// Redirect the user to the node they are commenting on.
$redirect = 'node/' . $node->nid;
}
@@ -2136,6 +2136,7 @@ function template_preprocess_comment(&$v
$variables['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';
$variables['signature'] = $comment->signature;
$variables['title'] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => "comment-$comment->cid"));
+ $variables['permalink'] = l('#', 'comment/' . $comment->cid, array('fragment' => "comment-$comment->cid"));
$variables['template_files'][] = 'comment-' . $variables['node']->type;
// Helpful $content variable for templates.
@@ -2402,7 +2403,7 @@ function comment_unpublish_action($comme
->fields(array('status' => COMMENT_NOT_PUBLISHED))
->condition('cid', $cid)
->execute();
- watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject));
+ watchdog('action', 'Unpublished comment %cid.', array('%cid' => $cid));
}
/**
@@ -2421,12 +2422,13 @@ function comment_unpublish_action($comme
*/
function comment_unpublish_by_keyword_action($comment, $context) {
foreach ($context['keywords'] as $keyword) {
- if (strpos($comment->comment, $keyword) !== FALSE || strpos($comment->subject, $keyword) !== FALSE) {
+ $text = drupal_render($comment);
+ if (strpos($text, $keyword) !== FALSE) {
db_update('comment')
->fields(array('status' => COMMENT_NOT_PUBLISHED))
->condition('cid', $comment->cid)
->execute();
- watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject));
+ watchdog('action', 'Unpublished comment %cid.', array('%cid' => $comment->cid));
break;
}
}
@@ -2488,16 +2490,6 @@ function comment_menu_alter(&$items) {
}
/**
- * Implement hook_filter_format_delete().
- */
-function comment_filter_format_delete($format, $fallback) {
- db_update('comment')
- ->fields(array('format' => $fallback->format))
- ->condition('format', $format->format)
- ->execute();
-}
-
-/**
* Implements hook_rdf_mapping().
*/
function comment_rdf_mapping() {
Index: modules/comment/comment.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.pages.inc,v
retrieving revision 1.28
diff -u -p -r1.28 comment.pages.inc
--- modules/comment/comment.pages.inc 1 Nov 2009 12:11:10 -0000 1.28
+++ modules/comment/comment.pages.inc 10 Nov 2009 19:36:09 -0000
@@ -108,7 +108,7 @@ function comment_reply(stdClass $node, $
*/
function comment_approve($comment) {
$comment->status = COMMENT_PUBLISHED;
- $comment->comment_format = $comment->format;
+// $comment->comment_format = $comment->format;
comment_save($comment);
drupal_set_message(t('Comment approved.'));
Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.52
diff -u -p -r1.52 comment.test
--- modules/comment/comment.test 20 Oct 2009 17:33:42 -0000 1.52
+++ modules/comment/comment.test 10 Nov 2009 19:36:09 -0000
@@ -24,14 +24,14 @@ class CommentHelperCase extends DrupalWe
*/
function postComment($node, $comment, $subject = '', $contact = NULL) {
$edit = array();
- $edit['comment'] = $comment;
-
+ $edit['comment_body[zxx][0][value]'] = $comment;
+
$preview_mode = variable_get('comment_preview_article', DRUPAL_OPTIONAL);
$subject_mode = variable_get('comment_subject_field_article', 1);
// Must get the page before we test for fields.
if ($node !== NULL) {
- $this->drupalGet('comment/reply/' . $node->nid);
+ $test = $this->drupalGet('comment/reply/' . $node->nid);
}
if ($subject_mode == TRUE) {
@@ -44,6 +44,7 @@ class CommentHelperCase extends DrupalWe
if ($contact !== NULL && is_array($contact)) {
$edit += $contact;
}
+
switch ($preview_mode) {
case DRUPAL_REQUIRED:
// Preview required so no save button should be found.
@@ -67,6 +68,7 @@ class CommentHelperCase extends DrupalWe
// Get comment ID
preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
+
// Get comment.
if ($contact !== TRUE) { // If true then attempting to find error message.
if ($subject) {
@@ -355,7 +357,7 @@ class CommentInterfaceTest extends Comme
$this->assertTrue($this->node, t('Article node created.'));
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertNoText('This discussion is closed', t('Posting to node with comments enabled'));
- $this->assertField('edit-comment', t('Comment body field found.'));
+ $this->assertField('edit-comment-body-zxx-0-value', t('Comment body field found.'));
// Delete comment and make sure that reply is also removed.
$this->drupalLogout();
@@ -572,6 +574,7 @@ class CommentAnonymous extends CommentHe
$this->assertPattern('/]*?)id="comments"([^>]*?)>/', t('Comments were displayed.'));
$this->assertLink('Login', 1, t('Link to login was found.'));
$this->assertLink('register', 1, t('Link to register was found.'));
+
}
}
Index: modules/comment/comment.tpl.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.tpl.php,v
retrieving revision 1.16
diff -u -p -r1.16 comment.tpl.php
--- modules/comment/comment.tpl.php 19 Oct 2009 20:33:21 -0000 1.16
+++ modules/comment/comment.tpl.php 10 Nov 2009 19:36:09 -0000
@@ -18,6 +18,7 @@
* Preprocess functions can reformat it by calling format_date() with the
* desired parameters on the $comment->changed variable.
* - $new: New comment marker.
+ * - $permalink: Comment permalink.
* - $picture: Authors picture.
* - $signature: Authors signature.
* - $status: Comment status. Possible values are:
@@ -64,6 +65,7 @@
>
+
$author, '!datetime' => $created));