diff options
Diffstat (limited to 'modules/comment')
-rw-r--r-- | modules/comment/comment-node-form.js | 1 | ||||
-rw-r--r-- | modules/comment/comment-rtl.css | 1 | ||||
-rw-r--r-- | modules/comment/comment-wrapper.tpl.php | 1 | ||||
-rw-r--r-- | modules/comment/comment.admin.inc | 1 | ||||
-rw-r--r-- | modules/comment/comment.api.php | 1 | ||||
-rw-r--r-- | modules/comment/comment.css | 1 | ||||
-rw-r--r-- | modules/comment/comment.info | 1 | ||||
-rw-r--r-- | modules/comment/comment.install | 29 | ||||
-rw-r--r-- | modules/comment/comment.module | 94 | ||||
-rw-r--r-- | modules/comment/comment.pages.inc | 1 | ||||
-rw-r--r-- | modules/comment/comment.test | 32 | ||||
-rw-r--r-- | modules/comment/comment.tokens.inc | 1 | ||||
-rw-r--r-- | modules/comment/comment.tpl.php | 1 |
13 files changed, 92 insertions, 73 deletions
diff --git a/modules/comment/comment-node-form.js b/modules/comment/comment-node-form.js index 3550d6ee7..76db2404e 100644 --- a/modules/comment/comment-node-form.js +++ b/modules/comment/comment-node-form.js @@ -1,4 +1,3 @@ -// $Id$ (function ($) { diff --git a/modules/comment/comment-rtl.css b/modules/comment/comment-rtl.css index 5cef41224..39c392965 100644 --- a/modules/comment/comment-rtl.css +++ b/modules/comment/comment-rtl.css @@ -1,4 +1,3 @@ -/* $Id$ */ .indented { margin-left: 0; diff --git a/modules/comment/comment-wrapper.tpl.php b/modules/comment/comment-wrapper.tpl.php index e6ac95e23..3293e88ae 100644 --- a/modules/comment/comment-wrapper.tpl.php +++ b/modules/comment/comment-wrapper.tpl.php @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc index 1b050b106..4f3d35071 100644 --- a/modules/comment/comment.admin.inc +++ b/modules/comment/comment.admin.inc @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file diff --git a/modules/comment/comment.api.php b/modules/comment/comment.api.php index 987d04673..05912655b 100644 --- a/modules/comment/comment.api.php +++ b/modules/comment/comment.api.php @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file diff --git a/modules/comment/comment.css b/modules/comment/comment.css index 4cc8f4c42..4a2675af8 100644 --- a/modules/comment/comment.css +++ b/modules/comment/comment.css @@ -1,4 +1,3 @@ -/* $Id$ */ #comments { margin-top: 15px; diff --git a/modules/comment/comment.info b/modules/comment/comment.info index d244ddf99..7cbe2461a 100644 --- a/modules/comment/comment.info +++ b/modules/comment/comment.info @@ -1,4 +1,3 @@ -; $Id$ name = Comment description = Allows users to comment on and discuss published content. package = Core diff --git a/modules/comment/comment.install b/modules/comment/comment.install index c22655f62..d64b3acde 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file @@ -338,6 +337,33 @@ function comment_update_7006(&$sandbox) { } /** + * Add an index to the created column. + */ +function comment_update_7007() { + db_add_index('comment', 'comment_created', array('created')); +} + +/** + * Update database to match Drupal 7 schema. + */ +function comment_update_7008() { + // Update default status to 1. + db_change_field('comment', 'status', 'status', array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 1, + 'size' => 'tiny', + )); + + // Realign indexes. + db_drop_index('comment', 'comment_status_pid'); + db_add_index('comment', 'comment_status_pid', array('pid', 'status')); + db_drop_index('comment', 'comment_pid_status'); + db_drop_index('comment', 'nid'); +} + +/** * @} End of "addtogroup updates-6.x-to-7.x" */ @@ -442,6 +468,7 @@ function comment_schema() { 'comment_num_new' => array('nid', 'status', 'created', 'cid', 'thread'), 'comment_uid' => array('uid'), 'comment_nid_language' => array('nid', 'language'), + 'comment_created' => array('created'), ), 'primary key' => array('cid'), 'foreign keys' => array( diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 78d35c039..4a737557d 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file @@ -495,6 +494,7 @@ function comment_permalink($cid) { * * @param integer $number * (optional) The maximum number of comments to find. Defaults to 10. + * * @return * An array of comment objects or an empty array if there are no recent * comments visible to the current user. @@ -502,15 +502,12 @@ function comment_permalink($cid) { function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); $query->innerJoin('node', 'n', 'n.nid = c.nid'); - $query->innerJoin('node_comment_statistics', 'ncs', 'ncs.nid = c.nid'); $query->addTag('node_access'); $comments = $query ->fields('c') - ->condition('ncs.comment_count', 0, '>') ->condition('c.status', COMMENT_PUBLISHED) ->condition('n.status', NODE_PUBLISHED) - ->orderBy('ncs.last_comment_timestamp', 'DESC') - ->orderBy('c.cid', 'DESC') + ->orderBy('c.created', 'DESC') ->range(0, $number) ->execute() ->fetchAll(); @@ -989,8 +986,8 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode = $comment->content = array(); // Build fields content. - field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode); - entity_prepare_view('comment', array($comment->cid => $comment)); + field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode); + entity_prepare_view('comment', array($comment->cid => $comment), $langcode); $comment->content += field_attach_view('comment', $comment, $view_mode, $langcode); $comment->content['links'] = array( @@ -1092,8 +1089,8 @@ function comment_links($comment, $node) { * An array in the format expected by drupal_render(). */ function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) { - field_attach_prepare_view('comment', $comments, $view_mode); - entity_prepare_view('comment', $comments); + field_attach_prepare_view('comment', $comments, $view_mode, $langcode); + entity_prepare_view('comment', $comments, $langcode); $build = array( '#sorted' => TRUE, @@ -1406,15 +1403,15 @@ function comment_user_delete($account) { } /** - * This is *not* a hook_access() implementation. This function is called - * to determine whether the current user has access to a particular comment. + * Determines whether the current user has access to a particular comment. * * Authenticated users can edit their comments as long they have not been - * replied to. This prevents people from changing or revising their - * statements based on the replies to their posts. + * replied to. This prevents people from changing or revising their statements + * based on the replies to their posts. * * @param $op - * The operation that is to be performed on the comment. Only 'edit' is recognized now. + * The operation that is to be performed on the comment. Only 'edit' is + * recognized now. * @param $comment * The comment object. * @return @@ -1468,28 +1465,15 @@ function comment_save($comment) { module_invoke_all('entity_presave', $comment, 'comment'); if ($comment->cid) { - // Update the comment in the database. - db_update('comment') - ->fields(array( - 'status' => $comment->status, - 'created' => $comment->created, - 'changed' => $comment->changed, - 'subject' => $comment->subject, - 'uid' => $comment->uid, - 'name' => $comment->name, - 'mail' => $comment->mail, - 'homepage' => $comment->homepage, - 'language' => $comment->language, - )) - ->condition('cid', $comment->cid) - ->execute(); + + drupal_write_record('comment', $comment, 'cid'); // Ignore slave server temporarily to give time for the // saved comment to be propagated to the slave. db_ignore_slave(); // Update the {node_comment_statistics} table prior to executing hooks. - _comment_update_node_statistics($comment->nid); + _comment_update_node_statistics($comment->nid); field_attach_update('comment', $comment); // Allow modules to respond to the updating of a comment. @@ -1554,23 +1538,16 @@ function comment_save($comment) { $comment->name = $user->name; } - $comment->cid = db_insert('comment') - ->fields(array( - 'nid' => $comment->nid, - 'pid' => empty($comment->pid) ? 0 : $comment->pid, - 'uid' => $comment->uid, - 'subject' => $comment->subject, - 'hostname' => ip_address(), - 'created' => $comment->created, - 'changed' => $comment->changed, - 'status' => $comment->status, - 'thread' => $thread, - 'name' => $comment->name, - 'mail' => $comment->mail, - 'homepage' => $comment->homepage, - 'language' => $comment->language, - )) - ->execute(); + // Ensure the parent id (pid) has a value set. + if (empty($comment->pid)) { + $comment->pid = 0; + } + + // Add the values which aren't passed into the function. + $comment->thread = $thread; + $comment->hostname = ip_address(); + + drupal_write_record('comment', $comment); // Ignore slave server temporarily to give time for the // created comment to be propagated to the slave. @@ -1929,11 +1906,9 @@ function comment_form($form, &$form_state, $comment) { '#default_value' => $author, '#maxlength' => 60, '#size' => 30, + '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))), + '#autocomplete_path' => 'user/autocomplete', ); - // If the comment is by a registered user, allow to autocomplete username. - if ($comment->registered_name != '') { - $form['author']['name']['#autocomplete_path'] = 'user/autocomplete'; - } } elseif ($user->uid) { $form['author']['_author'] = array( @@ -2114,18 +2089,21 @@ function comment_form_validate($form, &$form_state) { entity_form_field_validate('comment', $form, $form_state); if (!empty($form_state['values']['cid'])) { + // Verify the name in case it is being changed from being anonymous. + $account = user_load_by_name($form_state['values']['name']); + $form_state['values']['uid'] = $account ? $account->uid : 0; + if ($form_state['values']['date'] && strtotime($form_state['values']['date']) === FALSE) { form_set_error('date', t('You have to specify a valid date.')); } - if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account = user_load_by_name($form_state['values']['name'])) { + if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) { form_set_error('name', t('You have to specify a valid author.')); } } - - // Validate anonymous comment author fields (if given). - if ($form_state['values']['is_anonymous']) { - // If the (original) author of this comment was an anonymous user, verify - // that no registered user with this name exists. + elseif ($form_state['values']['is_anonymous']) { + // Validate anonymous comment author fields (if given). If the (original) + // author of this comment was an anonymous user, verify that no registered + // user with this name exists. if ($form_state['values']['name']) { $query = db_select('users', 'u'); $query->addField('u', 'uid', 'uid'); @@ -2216,7 +2194,7 @@ function comment_form_submit($form, &$form_state) { $comment = comment_form_submit_build_comment($form, $form_state); if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) { // Save the anonymous user information to a cookie for reuse. - if (!$comment->uid) { + if (user_is_anonymous()) { user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage')))); } diff --git a/modules/comment/comment.pages.inc b/modules/comment/comment.pages.inc index 726795a41..7e88bffcb 100644 --- a/modules/comment/comment.pages.inc +++ b/modules/comment/comment.pages.inc @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file diff --git a/modules/comment/comment.test b/modules/comment/comment.test index a76d89c96..770e01d4a 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -1,5 +1,9 @@ <?php -// $Id$ + +/** + * @file + * Tests for comment.module. + */ class CommentHelperCase extends DrupalWebTestCase { protected $admin_user; @@ -303,6 +307,26 @@ class CommentInterfaceTest extends CommentHelperCase { $this->drupalLogin($this->admin_user); $this->setCommentSubject(TRUE); $this->setCommentPreview(DRUPAL_OPTIONAL); + + // Test changing the comment author to "Anonymous". + $this->drupalGet('comment/' . $comment->id . '/edit'); + $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => '')); + $comment_loaded = comment_load($comment->id); + $this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, t('Comment author successfully changed to anonymous.')); + + // Test changing the comment author to an unverified user. + $random_name = $this->randomName(); + $this->drupalGet('comment/' . $comment->id . '/edit'); + $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $random_name)); + $this->drupalGet('node/' . $this->node->nid); + $this->assertText($random_name . ' (' . t('not verified') . ')', t('Comment author successfully changed to an unverified user.')); + + // Test changing the comment author to a verified user. + $this->drupalGet('comment/' . $comment->id . '/edit'); + $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name)); + $comment_loaded = comment_load($comment->id); + $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, t('Comment author successfully changed to a registered user.')); + $this->drupalLogout(); // Reply to comment #2 creating comment #3 with optional preview and no @@ -1694,7 +1718,7 @@ class CommentTokenReplaceTestCase extends CommentHelperCase { foreach ($tests as $input => $expected) { $output = token_replace($input, array('comment' => $comment), array('language' => $language)); - $this->assertFalse(strcmp($output, $expected), t('Sanitized comment token %token replaced.', array('%token' => $input))); + $this->assertEqual($output, $expected, t('Sanitized comment token %token replaced.', array('%token' => $input))); } // Generate and test unsanitized tokens. @@ -1710,7 +1734,7 @@ class CommentTokenReplaceTestCase extends CommentHelperCase { foreach ($tests as $input => $expected) { $output = token_replace($input, array('comment' => $comment), array('language' => $language, 'sanitize' => FALSE)); - $this->assertFalse(strcmp($output, $expected), t('Unsanitized comment token %token replaced.', array('%token' => $input))); + $this->assertEqual($output, $expected, t('Unsanitized comment token %token replaced.', array('%token' => $input))); } // Load node so comment_count gets computed. @@ -1723,7 +1747,7 @@ class CommentTokenReplaceTestCase extends CommentHelperCase { foreach ($tests as $input => $expected) { $output = token_replace($input, array('node' => $node), array('language' => $language)); - $this->assertFalse(strcmp($output, $expected), t('Node comment token %token replaced.', array('%token' => $input))); + $this->assertEqual($output, $expected, t('Node comment token %token replaced.', array('%token' => $input))); } } } diff --git a/modules/comment/comment.tokens.inc b/modules/comment/comment.tokens.inc index 2375cfb6f..d62b7e2f8 100644 --- a/modules/comment/comment.tokens.inc +++ b/modules/comment/comment.tokens.inc @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file diff --git a/modules/comment/comment.tpl.php b/modules/comment/comment.tpl.php index adf93b31c..a483813d2 100644 --- a/modules/comment/comment.tpl.php +++ b/modules/comment/comment.tpl.php @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file |