This proposed patch (for HEAD/comment.module/1.235) provides functionality for posting fast and simple Movable-Type-style comments.
A README follows:
Instructions
- See 'Themes' section below in order to know why this will not work with
your theme at first. - Add a new field to 'comments' table in database. Its name must be 'misc' and its type MEDIUMTEXT. Its values can be NULL.
- Replace your 'modules/comment.module' file by this one.
- Go to Administer->Configuration->Modules->Comment and set some options:
- Default display mode: flat list - expanded
- Additional fields: turn on those you wish
- Location of comment submission form: display below post or comments
You can also hide comment controls and change comments display order.
- Have fun and give some feedback
Database
This module saves comments additional data in a new field in 'comments' table called 'misc', in the form of a serialized array.
Themes
This module offers a sample theme implementation that you can see using
the 'example' standard theme.
Other themes need to explicitly manage new fields in order to show them, unless they are simple CSS themes based on default HTML structure. (Not the case for xtemplate and chameleon, the ones bundled with Drupal at the moment).
Design notes
New field for database 'comments' is called 'misc' instead of 'data', which would have been better in order to unpack its data with drupal_unpack(). This is due to a conflict with 'data' field in 'user' table when querying data from both tables at a time through a JOIN.
| Comment | File | Size | Author |
|---|---|---|---|
| #52 | fix_redirects_2.patch | 3.8 KB | morbus iff |
| #47 | redir_experiment.patch | 1.25 KB | morbus iff |
| #39 | fix_redirects.patch | 877 bytes | morbus iff |
| #35 | comment_0.diff | 670 bytes | Anonymous (not verified) |
| #34 | comment.diff | 10.38 KB | Anonymous (not verified) |
Comments
Comment #1
drummThe misc field in the database looks like it is serialized. Serialized data in the database usually causes annoyances (what if you want to list all the people who have anonymously commented with identity, or search them). Breaking it out into separate columns should be preferred.
This data might even belong in a separate table: it would save space because these values would be blank for logged in users and it could avoid storing duplicate data for not logged in users who have the same identity (such as comments from the same anonymous session).
Comment #2
pablobm commentedAgreed.
The reason I did that way was to allow easier addition of new fields, or even (in a future), provide some mechanism to define them via some parameters.
To get the best form the two worlds, it seems intelligent to save this data in a separate table. It would be something like:
An example of such a table would look like:
Why text for type, instead of an int (which would be cheaper in terms of space)?. If anyone want to propose its own fields in the future, it would be better to use meaningful names for them, instead of a number that could be in conflict with the module of anyone else's numbers.
Opinions?
Comment #3
dries commentedI wonder if we need the fields configurable/extensible -- it is in Drupal's interest to encourage people to create a normal account where you can define what fields to add and remove. What fields would you like to add?
Comment #4
pablobm commentedDrupal was created with the idea of a platform for collaborative work in mind, and so an user//pass scheme was adecuate, but many people uses Drupal beyond that and this fast-comment approach is more adecuate for many other uses.
Of course, I think this should be turned off by default on Drupal installations, since it can give new problems, like increasing trolling and spam. Users who turn it on should really know what they want.
About fields extensibility... to be sincere, I don't really know which other fields could be useful. I thought it could be useful to somebody as those three fields were for me (name, email, homepage). Thinking about it occurs to me somebody could ask for IM addresses (AIM, MSN, Jabber...) and depending the way you ask for them, you could use one or more fields.
Well, it might be not as necessary as I thought int the first term. This extensibility may be eliminated after all.
Comment #5
dries commentedI suggest to add the aforementioned fields (name, e-mail, URL) to the comment table, to normalize the data and to drop the exstensibility in favor of performance. We've put a lot of effort into optimizing the comment module as there are quite a few Drupal sites with large comment threads.
We could also look into ways to ease registration and to create a better synergy between both systems. I'm mentioning this, because I feel this needs to be discussed thoroughly. For one, we must make sure (registered) users can't (easily) be impersonated.
Comment #6
(not verified) commentedI attach a new version of this feature request patch.
Now these three fields are fields in the 'comments' table themselves, as proposed by Dries.
I suppose this causes no big issues with database size when they are not used at all, since the 'locales' table has plenty of this hardly-ever-usable fields.
Comment #7
pablobm commentedLast comment is mine. Forgot login :P.
Comment #8
dries commentedI haven't tried this patch but it looks good. Here are some suggestions:
$output .= t("by %a on %b", array("%a" => theme("comment_author", $comment), "%b" => format_date($comment->timestamp))) ."</div>\n";$output .= $name . t(" (identity not verified)");_comment_format_url()I urge you to add some input checking. There are functions inincludes/common.incthat you can use to validate URLs and e-mail addresses. Please do.Comment #9
pablobm commentedHere is the path with those changes in it. (Diffed from comment.module/1.238, as filename suggests).
I've also added a check that given name doesn't belong to a registered user.
I have a question now: should these fields be shown on /admin/comment listing?. In that case, what's the best way to render them in the table?
I come up with two posibilities:
The second one is preferred to me. Of course, fields would only show if they are activated in module configuration
Comment #10
dries commentedvariable_get("anonymous", "Anonymous").drupal_set_message($message, 'error')to output an error message or display the error message with the form element through the form item's$descriptionparameter.Comment #11
(not verified) commentedNew patch (against comment.module/1.240) attached, implementing suggestion 1 and 3.
About suggestion 2, I don't understand what error reporting do you speak about.
If it is the one at
function comment_post($edit), lines 290-312, this is:then I must say I'm using just the same error reporting used just some lines before, as in:
Comment #12
dries commentedLooks good to me but:
userstable for example; we use 'mail' elsewhere.database/database.mysqlanddatabase/updates.inc._form_comment_xxx()functions when they only have one call site.Comment #13
pablobm commentedSome notes now:
About how to render this not-so-anonymous commenters in diverse places where their names
are needed, I've noticed next comment in
common.inc:format_name():So I understand it should apply in this case too, providing a general handling for these names. Theme
designers should be the ones to look if a given user has defined mail and homepage and decide how to
show them when this behaviour is not desired.
There's a collision problem between users.name and comments.name. I resolve it the following way
(example taken from code):
This has two problems. The first is that of remembering to add the aliasing for u.name and the second line
always we have to deal with this sort of queries. The second problem is we are aliasing the preferred alternative
(we prefer logged in users) and if somebody forgets the second line, the logged in users will be the affected
ones.
About the latter problem, why not aliasing the comments' one?. The answer is: there are five queries
on the form "SELECT c.* ..." affected by this, and no "SELECT u.* ..." queries at all, and expand
formers' wildcards would be an ugly and error-prone job. (I don't have problem on doing that, but
it sounds ugly and I'd like a experienced opinion before doing it).
Comment #14
pablobm commentedAttaching patch for database/database.mysql
Comment #15
pablobm commentedAttaching patch for database/updates.inc
Comment #16
pablobm commentedI don't know if needed, but I attach a patch for database/database.pgsql also
Comment #17
dries commentedI tried your patch and had to fix a number of bugs to get it semi-working. New patch attached.
Still, it is not working correctly yet.
Getting there ...
Comment #18
dries commentedUpdates:
Comment #19
pablobm commentedAbout #17:
other posting errors, like the 'Empty comment' one, do this exactly that way. If this is not enough, what should I do?. I suppose an alternative would be issue a drupal_set_message() and continue like previewing the comment, without caring if it was "preview" or "post" the pressed command.
that are usually overriden by it. Am I wrong?
About #18:
This is the same I said when answering to #17.2. Xtemplate overrides theme_comment() with xtemplate_comment(),
that uses format_name() in order to show the name, instead of my theme_comment_name(), what is right, since
xtemplate didn't know about it. Same applies to Chameleon and others.
A quick fix would be patching format_name(), but I bet site admins would prefer be them the ones to decide
(through the theme), what to do at the respect. Or am I missing something? (probably, :P).
Comment #20
pablobm commentedNew patch attached.
the it is set to '', so further actions over the comment will treat it as a 100% anonymous comment.
About your patch, when you added "c.mail" field to two queries, you didn't see it was already present at the right. The real problem was "c.name" field was being queried two times. I've fixed this. An example:
Was wrong in my code, but you didn't noticed the two fields on the right and patched as:
Now it is OK, as:
Additionally, I see that when MYSQL sees "DEFAULT ''" it does not understand what I thought it undestood,
so I'll add a new patch for
database/database.mysql(as well as .pgsql file). This (makingNULL by default this three fields, instead of taking the value similar fields in database take), will
make processing easier.
(i.e.: I made 'mail' "DEFAULT ''" and I got a "''" mail address when not typed in)
Comment #21
pablobm commentedNew patch for database/database.mysql (see #20.)
Comment #22
pablobm commentedNew patch for database/database.pgsql (see #20.)
Comment #23
pablobm commentedNew patch for database/updates.inc (see #20.)
Comment #24
davidnunez commentedThis is a very important feature request to me!
I've been hacking away at an alternate version of this feature for a while, now...
I don't know if this can give you any ideas, but please check out: http://www.davidnunez.com/blog/title/Anonymous+Comments+Hack
The main difference is that I modified format_name() way up in "includes/common.inc" to look for anonymous user uid=0 and substitute in a name and url link if they existed... That helped simplify the number of changes I needed to make in other places.
My hack has been working fairly solidly, but it's not as generalized as it could be.
I absolutely believe that we need the option to have the user's name link to their url, their email address, both, or nothing at all (if you're concerned about people confusing anonymous members with registered members). This should be a four-way toggle in the Admin menu.
I like the approach you are taking here, so far. I'm looking forward to testing this out.
Comment #25
dries commentedformat_name()and to route all 'name displaying' throughformat_name()so we don't have to update all themes. I'm not sure it is feasible but if it can be done cleanly, I'm all for it.Comment #26
(not verified) commentedWhile at this, why don't you look at my implementation:
http://cvs.drupal.org/viewcvs/contributions/modules/comment_author/?only...
I did not patched format_user(), just overloaded comment->name on comment_view()
See the module/patch in action here:
http://trip.ee/node/view/5893
Comment #27
pablobm commentedThe problem with
#24
is that format_name() is used in many places in Drupal, and we cannot show something like "John Doe " (with links) everywhere (as example in
#9).
The problem with
#26
is (I think, by reading
#5)that of having data is separate tables, thus slowing down sites with large threads
My opinion is we should leave format_name() untouched, as well as the default theme_comment*() functions. Doing so will show names in every theme, but just names.
Then, theme designers would decide if show additional fields, calling format_name() as default does, or formatting them by themselves.
I attach the corresponding patch
Comment #28
pablobm commentedIn the last post, when I say:
...something like "John Doe " (with links) everywhere...
I really want to say:
...something like "John Doe <john.doe@nowhere.no>" (with links) everywhere...
Or even better:
...something like
"John Doe <john.doe@nowhere.no>" everywhere...
Comment #29
dries commentedI committed a slightly modified version of your patch to HEAD. Thanks. I'm marking this report 'active'.
I modified
format_name()to behave differently in absence of$user->uid. Hopefully we can sort out the remaining issues (eg. lack of warning about what will happen with their e-mail address, lack of communication as to what are required fields, error handling of incorrect comment submissions, and post submission handling) in a timely manner.Comment #30
pablobm commentedOne at a time. About "error handling of incorrect comment submissions"...
Since checking for this fields is done the same way it is for other fields (empty-comment check, for example), I wonder if all handlings should be modified the same way. In this case, would it be needed to open a different issue for that? (since it would not a anonymous-comments specific issue anymore).
And more important than that: what should be the right way to do that?
Comment #31
morbus iffThere also seems to be another problem. Using tonight's CVS , if a user leaves an anonymous comment, their name is linked to the profile URL of the content author (such that clicking on the commenter's name would give you the author profile of the content).
Comment #32
morbus iff#31 is irrelevant now - latest CVS fixed it.
Seeing something else though. I can't, for the life of me, get any comment to work, regardless of whether it's anonymous or authenticated. All the comments show up in the watchdog as being added, and I can "view details" no problem. However, when I click "view comment", they never show up in the page (regardless of threaded, a reply to an existing comment, or a new comment on the post). Finally, when an auth'd user "previews" his comment (which is required on my test installation), the name/info shows up as "Anonymous" in the preview form.
Comment #33
(not verified) commentedThis patch should do the job.
It has two changes, one seems to be my fault. The other one seems that was lost in merging with HEAD.
Comment #34
(not verified) commentedThis patch should do the job.
It has two changes, one seems to be my fault. The other one seems that was lost in merging with HEAD.
Comment #35
(not verified) commentedIt seems I like to screw things up. Sorry.
Forget my last dupe follow-ups, please. Here is the patch again
Comment #36
morbus iffPablo's comment_0.diff (#35) fixed my #32. Changing status to patch for commit.
Comment #37
dries commentedWhen I apply this patch, the anonymous user names always show up as 'Anonymous' while the information is stored properly in the database (the link to the homepage is correct though). Without this patch, the correct usernames are shown. Looks like I'm having the opposite problem ... ?
Comment #38
morbus iffHeh, heh. Yay! :)
With a clean CVS checkout today, authenticated user comments show up as "Anonymous", and anonymous comments show up correctly (with or without homepage links, and with the "(not verified)") addition. With the patch applied, everything shows up as I expect, including previews.
How can we help each other test and clarify further?
Comment #39
morbus iffI've attached a patch that fixes the redirect issues mentioned on drupal-devel, reprinting here for onlookers: "After submitting a comment, you are not directed to the correct page. The user should see that his or her comment is being posted so it is better to redirect the user to 'node/view/x'. This bug is not introduced by Pablo's patch." The patch also fixes a similar incorrect redirect issue when the user is modifying their comment view settings (you know, the whole "do I want to see it threaded?" form).
I'm not sure if I'm using drupal_goto correctly here, especially since I'm "hardcoding" the "node/view" string. What happens when the user has used an alternate path (as per the path.module)? I suspect this will be transparent, but if the user has requested the alternate path, shouldn't they return to the alternate path? The only other places I could find that used drupal_goto with hardcoded values was the forum.module:
456: drupal_goto("node/view/$nid");and user.module:901: drupal_goto("user/edit");Comment #40
dries commentedI can reproduce the problem now - comments by authenticated users are indeed shown as anonymous. Applying the patch fixes this behavior but breaks the anonymous comments. Test against a hybrid comment thread that uses both comment styles and you'll see. A better patch is needed.
Code-wise I think it is better to test against
$comment->uidthan to test against$comment->name. At least it is slightly more consistent with the rest of the code.Comment #41
dries commentedThe redirect patch looks like an improvement as the use of
comment_node_url()appears to be broken. I suggest we remove the last instance ofcomment_node_url()too as well as the function itself.Christina suggested we should redirect the poster to his or her comment so he or she can see the comment being posted. Ideally, we would be redirecting to
node/view/<em>xxx</em>#comment-<em>yyy</em>. Looking at the code, this might need a bit more work so maybe that should be postponed until we start working on the 'Preview' and 'Submit' code (to improve the interaction design of the error handling).Comment #42
gábor hojtsyThe current comment redirect works with remembering the previous page in the session. But if the user navigates on multiple pages, then the session will contain false information, and the redirect will be odd. This is also an issue in 4.4. The reason for having non hard-coded redirects is that the book page or the forum page has different URLs for the nodes, and if we redirect the user to the node/view page, then it will not be the book or forum node view page, which the user might started to add the comment on.
I am myself fine with hard coded redirects to node/view, as my site has unique URLs for content (or at least it is not supposed to display differently with different URLs). Some people using the book module might find this approach broken. But the current comment redirect method is also broken anyway.
Comment #43
morbus iffRe: #40. Still can't duplicate what you're seeing, unfortunately. My testbed server (on a roving DSL IP address, so fear the reset) appears to be displaying fine: http://68.237.140.171:8888/?q=node/view/1.
Comment #44
morbus iffGoba: quite true. One possible way of fixing this would be to include the proper redirect location as a hidden value in the form itself (much like we pass nid, pid, and cid in theme_comment_form). It's a similar approach to comment_node_url, only the form values tell us where to go, as opposed to the query string. There doesn't seem to be any other magical way, within the code itself, to determine the proper URL to redirect to, since all URLs and params received at time of posting are comment/reply related, and not content type related (I'm ignoring costly determinations like $node->type, which would be another possibility).
Would that work for all circumstances? If I have time today, I'll whip out a patch for it. The big, big, big, downside to this approach is templates that have themed _comment_form will need to be updated to include the new hidden field.
Comment #45
gábor hojtsyMorbus: the hidden field approach was suggested before, but as far as I remember, it was said to be unfriendly to the caching mechnanisms, so if someone uses page caching, the behaviour will still be odd. It can only be made cache friendly, if the previous URL can be stored in a GET param, since the request URI is used to index the cache. But that is quite ugly.
I am not convinced that separate comment submission pages should be cached, but I don't know a good way to exclude them from caching. Having the hidden field on node pages with the comment form displayed would not be a problem, as the hidden field would contain the URL of the node page itself. This is only a problem for pages generated exclusively for comment submission.
Comment #46
morbus iffSigh, in fiddling, I fixed the problem Goba mentioned, but there was still an unsolved bug - the "add new comment" link for nodes that had no comments didn't play nicely with my hopes that the proper node type would be passed in the URL at some point (viewing a node THEN replying/adding, everything worked dandy). So, ignore my #45; it's not a valid solution. What is the cost of adding a "get node type" SQL, solely for the redirect?
Comment #47
morbus iffGah - didn't see Goba's reply before I added my own. My failed approach was based on the GET - a new 'type' hidden field was added to the form based on arg(0), and that was used to generate the final URL for drupal_goto. I've attached the (unfinished, unworking, not for commit) patch that demonstrates that technique. As I mentioned, however, it fails for "add new comment" links on, for example, the main page. Since the "add new comment" link went directly to comment/reply/3, arg(0) was never set properly (compared to viewing the node first, THEN adding/replying).
I'll next experiment with grabbing the $nid type from the database. That wouldn't be based on anything exterior (thus, ignoring caching methods), nor would it require the xtemplate to change (as per the attached patch). The downside to this one, however, is the extra cost of a SQL statement.
Comment #48
dries commentedWhen you submit a comment, you know the $nid, no?
Comment #49
morbus iffRight. So the approach of the in-progress patch is to get $nid's $type, and base the URL around "$type/view/$nid". In this approach, I'm worried about my ignorance of the rest of Drupal's content types. What is the type of a project node? Of a forum node? Of all the different contributed node modules? Is basing the URL on the $nid $type stored in the DB a folly? Still experimenting.
Comment #50
gábor hojtsy$type/view/$nid will not work. There is no such URL as story/view/$nid for example. It would basically be fine to redirect to node/view/$nid if the nodes would not have multiple possible views. A node can be in a book (regardless of the type of the node), and the book view of the node lives under a different URL then node/view/$nid. Now if you approach the comment form from the book view, you expect the system to get you back there. That cannot be computed from the node type, since there are multiple URLs for one node, that is the problem.
Comment #51
fx-1 commentedDries wrote: I can reproduce the problem now - comments by authenticated users are indeed shown as anonymous. Applying the patch fixes this behavior but breaks the anonymous comments. Test against a hybrid comment thread that uses both comment styles and you'll see. A better patch is needed.
I repro'd this by going from 4.4.1 to HEAD this morning, and I see what you mean.
But: Pablom's patch in #35 fixed this for me, and didn't break anonymous comments... at least not with this morning's checkout. Checked against all comment threading styles using HEAD's xtemplate theme's default style. Sorry if I'm missing something here, but it looks like it works (this aspect of it anyway) to me.
FWIW, it's: http://441tohead.lineofsight.org/ user/pass: admin
Comment #52
morbus iffGoba - thanks for your intellect.
Giving up on the SQL/type idea, I went back to the closest "solution" I had: the hidden form field mentioned in #44 through #47. The problem with that one was that there was no way to know what /type/ of node was being commented on if the user clicked on a "add new comment" link from a main page or similar equivalent - we went directly to comment/reply/$nid, as opposed to something like book/reply/$nid.
What the attached patch does is, in the absense of a GET hint, we default to "node". For the most part, this seems to work correctly from a template/visual standpoint (for Goba's specific example of a book template compared to a generic node template, I could find no evidence of the default book templates offering "add new comment" from an index/contents page without "book" in the URL. Regardless, a book page promoted to the main page of the site isn't much of a problem, as the user would be in the generic node template on the main page, and wouldn't know they're not seeing the book template after a comment redirect).
The downside of all this is that we've added one new hidden form field to three forms (moderation, comment preferences, and the comment form), and thus, customized templates that don't have those fields will default to the same erroneous behavior that prompted this patch (which isn't any worse than what they're already used to, however).
Some further notes about the patch: Dries, even though I've removed all mention of comment_node_url from the case statement, I didn't remove the function - there are two other places in the code that use it, and I didn't investigate them enough to see if they have the same sort of problem with redirects. Finally, this patch quickly (and probably dirtily) implements Christina's #comment-yyy suggestion, first by modifying code_post to return the comment ID. The case statement now checks to see if comment_post returns an array (in which case, an error occurred); any other return value is assumed to be the $cid, and we use that as a fragment to drupal_goto.
Comment #53
morbus iffDries: would you commit a patch that turned "name", "mail" and "homepage" to "anon_name", "anon_mail", and "anon_url", as per jseng's "Drupal for Bloggers" patch? As per my comments, I think they're a much stronger choice of field names.
Comment #54
dries commentedI'll give your patch some thought: maybe our best bet is to get rid of the multiple views (i.e. nuke
book/view/nid). It is handy but confusing. Not sure it is legitimate to remove.An alternative - but probably not easy to implement with the menu system - might be to change the URL scheme from
comment/reply/nid/cidto something likebook/view/nid/cid/replyorbook/reply/nid/cid.Personally, I'm not really in favor of the
anon_prefix.Comment #55
Chris Johnson commentedHmm, sounds like our database schema is wrong, if that is how nodes are being treated.
That is, our database insists that there is one and only one node type associated with a node (i.e. node.nid => node.type). If I understand Goba's response to Morbus, a single node (node.nid) can actually belong to several types -- for example, a story and a book.
If this is true, then I think we will continue to have these sorts of problems which are difficult to solve in a clean fashion until the database scheme is changed to match how it is used -- and code is changed to use the database in a consistent, API-like manner.
Hacking clever new features in by overloading database field meanings will almost always guarantee significant structurally intransigent problems in the future.
Comment #56
gábor hojtsyThe book is some kind of cummulative stuff, which can contain any type of node, so it is quite versatile in what it can contain. A node still has one type, but as it can be part of more than one vocabulary, it can also be part of a book vocabulary, which means that it gets another URL to access it. It does not mean it has multiple types, it is just classified into different vocabularies in the taxonomy.
Comment #57
dries commentedI committed patch #35 by Pablo to HEAD until others can reproduce my problem.
Comment #58
dries commentedComment #59
(not verified) commented