I've been working on a couple modules that modify and enhance the commenting system (file attachments in comments, and custom comment validation for specific nodetypes). Another patch (http://drupal.org/node/14708) would add limited form and validation customizatoin, but this one adds nodeapi-style form_pre, form_post, validate, and view hooks.

It's my first patch offered to the Drupal core, hope it's useful.

Comments

koorneef’s picture

When applied to CVS (2005-08-13):
(lucas@bsd1)/www/koorneef/test.koorneef.net/modules$ patch < comment.module_10.patch
Hmm... Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: modules/comment.module
|===================================================================
|RCS file: /cvs/drupal/drupal/modules/comment.module,v
|retrieving revision 1.364
|diff -u -r1.364 comment.module
|--- modules/comment.module 1 Aug 2005 05:14:05 -0000 1.364
|+++ modules/comment.module 5 Aug 2005 05:19:14 -0000
--------------------------
Patching file comment.module using Plan A...
Hunk #1 failed at 434.
Hunk #2 failed at 1417.
Hunk #3 failed at 1427.
Hunk #4 failed at 1469.
Hunk #5 succeeded at 1699 with fuzz 2.
4 out of 5 hunks failed--saving rejects to comment.module.rej
done

I'll see if I can update the patch ...

koorneef’s picture

StatusFileSize
new2.05 KB

Found the problem: the patch file had DOS format line-endings. Corrected in new version: 11.

Patch applies, but captcha is not appearing on comment form (it did with the older patches, see http://drupal.org/node/14708). Have to investigate further ....

eaton’s picture

after some investigation it appears that captcha is expecting a general 'form' $op for the hook, rathre than the 'form_pre' and 'form_post' ops that this patch supplies.

I added the pre and post operations to mirror the nodeapi form hooks, I'm not sure that a third general 'form' op would be a good idea. Any thoughts?

moshe weitzman’s picture

i think consistency with nodeapi is important, so no 'form' operation ... this patch looks simple and useful to me.

arnabdotorg’s picture

+1 for consistency; we can (I will) modify captcha to form_post once this hits core.

eaton’s picture

StatusFileSize
new2.75 KB

An updated version of the patch with some tweaks. First, the 'form_pre' and 'form_post' operations have been changed to 'form pre' and 'form post' to reflect the nodeapi naming conventions.

Second, a 'form param' hook has been added, mirroring nodapi's form param hook. This allows modules that modify the comment form to integrate file uploading and other niceties.

chx’s picture

In the beginning comments were supposed to be simple texts.. If you add files, how do you display without 'load' and 'view' operations? If you add 'load' and 'view', then why not create a 'comment' node type?

eaton’s picture

Your point is a good one. I'd like to work on a comprehensive comment node type rewrite, but this was a 'good enough' solution that helped out existing modules like captcha and doesn't break existing comment-based solutions.

the comment file-attachment stuff is just a possible use of some of the hooks; right now it's impossible. in the future a much cleaner solution would be nice. i've also used the validation hooks in implementing debate.module and microfiction.module.

eaton’s picture

I've checked in a proof of concept module called image_thread that relies on this patch to provide image uploading in a node's comments. I'm using it on a small site for photoshop image contests. That module is rough, but it gives an example of how the new hooks might be used to provide more complex enhancements.

http://cvs.drupal.org/viewcvs/drupal/contributions/modules/image_thread/

chx’s picture

Important notice: if this gets in, then project module can be overhauled to use the comment system!

eaton’s picture

Anyone willing to review this for 4.7 inclusion? I have high hopes...

nedjo’s picture

qualified +1: I have looked over but not applied this patch.

I like the added functionality. In general, it helps move us toward parallelism between different object types--which is good. My feeling is: unless there's a good reason *not* to expose a particular Drupal object type (comment, term, vocabulary, user, for a start) to nodeapi-like hooks, we should do so. If someone wants to do it with nodes, likely there's a good use case with other object types. Case in point: I'm continually frustrated with the inability to act on taxonomy term views (my patch, http://drupal.org/node/10399, a year ago, went nowhere, but maybe I should revive it).

Why not just use a node type? Because nodes are for different things than comments--twisting them into comments is bad practice.

The potential to use this for project.module, as suggested, is an added bonus.

Cvbge’s picture

A question about last patch: in db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", 0, NULL, 0, 0, $nid); why do you use NULL for last_comment_timestamp if it'd %d? It will be changed to '0', so if you want to use reall sql NULL type you need to put it directly.

eaton’s picture

Actually, that line isn't one of the added or changed lines, it was in the CVS copy that I patched from. I can take a look to see if the CVS version has changed dramatically since I created the patch -- I haven't had a chance to update in a couple of days.

Cvbge’s picture

Ah, didn't pay attention to the fact that it's not changed in patch... sorry about that. Happens sometimes to me ;)

eaton’s picture

To anyone interested in seeing these hooks go into core, taking a bit of time to apply it and give feedback would be great. Some example modules that demonstrate the new hooks are at:

http://drupal.org/node/28163 (a module with optional wordcount restrictions on comments)
http://drupal.org/node/28407(a module that prevents individuals from commenting until they have 'joined' a given debate)
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/image_thread/ (a module that lets users upload images in the comments of a node)

These modules are rough, but give examples of how the hooks might be used.

Poromenos@www.poromenos.org’s picture

Any hope of a patch for 4.6.3? This is really useful.

eaton’s picture

StatusFileSize
new2.36 KB

Attached is a patch against 4.6.3. Hopefully, the HEAD version of it will be approved. Feedback is much appreciated...

meba’s picture

Category: feature » bug
Priority: Normal » Critical

your patch for 4.6.3 is again in DOS format...
also, none of these patches works for 4.6.2 :(

eaton’s picture

meba, apologies regarding the windows format. The patch doesn't apply against 4.6.2 beause there were changes in the 4.6.3 branch to comments.module.

To be honest, I'm not going to be putting energy into a 4.6 patch now. I'm hoping to get some testing done and push for inclusion in HEAD, so that it can be made 'standard'. Once that happens, I think it can safely be backported to 4.6.x.

michaelsb’s picture

Category: bug » feature

I'm working on task.module and I wanted to provide task updates through comments. This patch did the trick and was such a big time saver (thanks to killes for recommending it).

However, I do have a feature request for this patch. I'd be nice if you could pass $comment by reference, so that I could use 'validate' to validate and update certain values. This way when 'view' is executed $comment will already have the validated data and I want have to call my hook_validate function again. This will mimic the way node hooks work, for example hook_validate passes $node by reference.

Also, update your patch to include the newest comment.module changes. The main one being the removal of ?> at the end of the file.

All in all, I give this patch a +1 for it's usefulness. Thanks!

eaton’s picture

StatusFileSize
new3.48 KB

New version attached. This one applies cleanly against the current HEAD, and passes the comment by reference so various handlers don't have to do double-duty.

eaton’s picture

StatusFileSize
new3.47 KB

A discussion with UnConeD and chx indicates that passing by reference is the norm in node.module, but is not kosher with te comment.module's way of doing things. This version includes all other tweaks but does NOT pass by ref.

eaton’s picture

StatusFileSize
new2.67 KB

Fixing a silly bug in the form param code that would've nuked any 'destination' parameter.

eaton’s picture

StatusFileSize
new2.7 KB

Er, rather, fixed in THIS version. Properly keeps all the assorted values of the attributes array.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I downloaded the patch and checked it against my comment upload module and the thing works.

dries’s picture

Status: Reviewed & tested by the community » Needs work

I'll commit this if someone takes the time to move all the comment moderation stuff out of core into a separate module (by using this patch). Given such API, this is a logical clean-up. It would help validate the usefulness of this patch.

eaton’s picture

Status: Needs work » Needs review
StatusFileSize
new35.62 KB

Here's a patched version of comment.module that pulls out all moderation functions. Admin approval of comments is still there, though it's a little odd to get to (you have to hit the approval queue, edit the comment, expand the 'admin' options for the comment, and select 'published').

Next step is the creation of a separate comment moderation module.

eaton’s picture

StatusFileSize
new38.13 KB

In the interest of fast turnaround, here's the next iteration. It passes the $comment by reference in cases of update, insert, view, and validate so that modules can alter the comment dynamically (including the post-status of said comment). It also adds (in order to make things a bit more like nodeapi) a 'form admin' hook, for form options that should only be presented to those with comment administration rights.

With those modifications, I believe that everything necessary for contrib moderations systems should be in place.

eaton’s picture

StatusFileSize
new39.77 KB

And then, yet one more.

This replaces a number of the hooks with an actual commentapi invocation function, allowing stuff to properly do nifty things like altering the comment body. It's currently working on http://head.angrylittletree.com though I haven't yet set up any of the example modules to hook into the 'commentapi' function rather than the older 'comment' hook.

eaton’s picture

StatusFileSize
new39.73 KB

Changed the name back to _comment, rather than _commentapi, based on previous debate about changing _nodeapi to _node.

That's the only change.

eaton’s picture

StatusFileSize
new39.73 KB

And then, finally, one more change to make sure that form param values don't clobber over form destinations.

eaton’s picture

StatusFileSize
new39.2 KB

updating the phpdoc block for the comment_hook_comment() function.

eaton’s picture

The code works as Dries recommended, but the upcoming formapi conversion makes it a bit awkward. the form pre, form post, form admin, and form param hooks that it exposes are only a single 'form' hook in the new system.

With Adrian's thumbs-up, I used this patch as the basis of the formapi converted comment.module. If the new formapi makes it to HEAD, this patch will be redundant and unecessary.

If the new form api for some reason doesn't make it into 4.7, this patch will still be useful. But I think all of us want the forms work to make it in...

eaton’s picture

Status: Needs review » Closed (duplicate)

These hooks were integrated into the formapi conversion, as its new system makes the process much cleaner. I'll point to this issue as a patch for 4.6, but it's fixed in head.

eaton’s picture

Status: Closed (duplicate) » Closed (fixed)
eaton’s picture

For reference:

The version of this patch that was committed to HEAD with FormsAPI contains the following hooks:

form
validate
insert
update
delete
view

Due to the FormsAPI changes, 'form pre', 'form post,' and 'form param' are unecessary as separate hooks. One single form hook allows weighted elements to be inserted into the form, and the form params to be altered. A 4.6.x backport would still require the pre/post/param hooks.

RickR-1’s picture

This is what I'm getting when trying to install this patch. I'm trying to get CAPTCHA to work.
--------------------------
|Index: modules/comment.module
|===================================================================
|RCS file: /cvs/drupal/drupal/modules/comment.module,v
|retrieving revision 1.369
|diff -u -r1.369 comment.module
|--- modules/comment.module 7 Sep 2005 20:45:53 -0000 1.369
|+++ modules/comment.module 13 Sep 2005 23:44:28 -0000
--------------------------
Patching file comment.module using Plan A...
Hunk #1 succeeded at 25 with fuzz 1 (offset -6 lines).
Hunk #2 succeeded at 46 (offset -6 lines).
Hunk #3 succeeded at 89 with fuzz 2 (offset 4 lines).
Hunk #4 succeeded at 108 (offset -7 lines).
Hunk #5 succeeded at 205 (offset 4 lines).
Hunk #6 failed at 288.
Hunk #7 failed at 392.
Hunk #8 succeeded at 490 (offset -52 lines).
Hunk #9 succeeded at 636 (offset 4 lines).
Hunk #10 failed at 643.
Hunk #11 succeeded at 647 (offset -52 lines).
Hunk #12 succeeded at 711 (offset 4 lines).
Hunk #13 succeeded at 674 (offset -52 lines).
Hunk #14 succeeded at 750 (offset 4 lines).
Hunk #15 failed at 846.
Hunk #16 succeeded at 808 (offset -52 lines).
Hunk #17 succeeded at 883 (offset 4 lines).
Hunk #18 failed at 983.
Hunk #19 succeeded at 1053 (offset 3 lines).
Hunk #20 failed at 1076.
Hunk #21 succeeded at 1109 with fuzz 2 (offset 8 lines).
Hunk #22 failed at 1119.
Hunk #23 failed at 1138.
Hunk #24 failed at 1169.
Hunk #25 failed at 1182.
Hunk #26 failed at 1196.
Hunk #27 failed at 1205.
Hunk #28 succeeded at 1211 (offset -4 lines).
Hunk #29 succeeded at 1273 (offset 8 lines).
Hunk #30 succeeded at 1271 (offset -57 lines).
12 out of 30 hunks failed--saving rejects to comment.module.rej
done

eaton’s picture

This patch is no longer supported for HEAD -- its functionality is in the new comment.module albeit with modifications. CAPTCHA will need to be upgraded for 4.7 to support it. If you're using version 4.6.3, you might try the version of this patch on comment 18 (http://drupal.org/node/28255#comment-42155) ... CAPTCHA may require a different patch altogether.

RickR-1’s picture

I'm using 4.6.0 and none of the patches seem to work. I've updated my comment.module to the 4.6.3 release and the 4.6.3 patch doesn't work either.

tng@neuralgourmet.com’s picture

Doesn't work for me on 4.6.3 either.

tsk1979’s picture

I am on 4.6.4, which version of the patch I should use for using captcha in comment modules?

amitbapat’s picture

Version: x.y.z » 4.6.5

I'm using 4.6.5 and my comment.module shows following Id string:
// $Id: comment.module,v 1.347.2.8 2005-11-15 20:37:56 dries Exp $

Which patch should I be using?

Thanks,

learndrupal-1’s picture

Title: Hooks for comment enhancements » Captcha comment enhancements for Drupal Version 4.6.5
Category: feature » support
Status: Closed (fixed) » Active

Can someone please let me know what patches I should apply to comment module to make captcha work with comment?

Drupal Version 4.6.5

loloyd’s picture

Priority: Critical » Normal
Status: Active » Needs work

If I have my wits right, users of Drupal Version 4.6.5 cannot use any of the aforementioned patches for the comments module.

This is because the comments.module 4.6.5 is dated Nov 16, 2005 while the previously mentioned patches ante-date this. I'll see if I can contribute a fix by hacking the most recent patch that tries to include the captcha module for 4.6.5.

chx’s picture

Status: Needs work » Closed (won't fix)

4.6 does not get new features and new hooks are definitely features. Do not reopen issue. Thanks.

learndrupal-1’s picture

loloyd - hello, I am hoping you are making progress on this issue. I have sent you a message, and hope you will see it. Thanks,

learndrupal

avpaderno’s picture

Title: Captcha comment enhancements for Drupal Version 4.6.5 » Hooks for comment enhancements
Category: Support request » Feature request
Issue summary: View changes
Status: Closed (won't fix) » Fixed
avpaderno’s picture

Status: Fixed » Closed (fixed)