This proposed patch (for HEAD/comment.module/1.235) provides functionality for posting fast and simple Movable-Type-style comments.

A README follows:


Instructions
  1. See 'Themes' section below in order to know why this will not work with
    your theme at first.
  2. Add a new field to 'comments' table in database. Its name must be 'misc' and its type MEDIUMTEXT. Its values can be NULL.
  3. Replace your 'modules/comment.module' file by this one.
  4. 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.

  5. 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.

Comments

drumm’s picture

The 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).

pablobm’s picture

Agreed.

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:

  • INT cid
  • TEXT type
  • TEXT data

An example of such a table would look like:

cid type data
1 author_name John Doe
1 author_email somewhere.out@in.space
2 author_name Manolo el del Bombo
2 author_homepage manolo.futbolero.es

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?

dries’s picture

I 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?

pablobm’s picture

Drupal 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.

dries’s picture

I 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.

Anonymous’s picture

StatusFileSize
new7.86 KB

I 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.

pablobm’s picture

Last comment is mine. Forgot login :P.

dries’s picture

I haven't tried this patch but it looks good. Here are some suggestions:

  1. I'd rename all instance of '...authorname...' to 'name', all instance of '...authoremail' to 'mail' and all instance of '...authorhomepage...' to 'homepage'. That is, the SQL tables, the variables and the forms.
  2. I don't think the comment pages validate as XHTML. From the looks, you forgot to remove a trailing <div> in: $output .= t("by %a on %b", array("%a" => theme("comment_author", $comment), "%b" => format_date($comment->timestamp))) ."</div>\n";
  3. I don't think these parentheses should be part of the translatable string: $output .= $name . t(" (identity not verified)");
  4. Instead of trying to fix up broken URLs in _comment_format_url() I urge you to add some input checking. There are functions in includes/common.inc that you can use to validate URLs and e-mail addresses. Please do.
pablobm’s picture

StatusFileSize
new8.5 KB

Here 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:

  1. Show them as new fields in the table, between 'name' and 'status'.
    subject author name mail homepage status ...
    Hello world Anonymous John Doe published ...
    Boring rant Anonymous Manolito Gafotas m@opticos.es http://www.opticos.es published ...
    Inspired comment pablobm published ...
  2. Show them in the 'author' field
    subject author status ...
    Hello world Anonymous (John Doe) published ...
    Boring rant Anonymous (Manolito Gafotas - m@opticos.es - http://www.opticos.es) published ...

The second one is preferred to me. Of course, fields would only show if they are activated in module configuration

dries’s picture

  1. The way the username defaults to 'anonymous' is not correct. You should respect the 'anonymous username' setting by using variable_get("anonymous", "Anonymous").
  2. Not sure I understand how the error reporting (not the error handling) works. Typically, we use drupal_set_message($message, 'error') to output an error message or display the error message with the form element through the form item's $description parameter.
  3. As for the comment listing. The former is confusing, the latter somewhat sloppy. I'd display the author's name and omit his e-mail address and URL. Don't make the username a link or it will be confused with registered users.
Anonymous’s picture

StatusFileSize
new10.38 KB

New 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:

    /*
    ** Check validity of name, email and homepage (if given)
    */
    
    $edit["name"] = strip_tags($edit["name"]);
    
    $nametaken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE name = '%s'", $edit["name"]), 0);
    
    if ($nametaken != 0) {
      return array(t("Name already taken"), t("The name you used as your signature belongs to a registered user."));
    }
    
    if ($edit["email"]) {
      if (!valid_email_address($edit["email"])) {
        return array(t("Invalid e-mail address"), t("The e-mail address you specifed is not valid."));
      }
    }

    if ($edit["homepage"]) {
      if (!valid_url($edit["homepage"], TRUE)) {
        return array(t("Invalid URL for homepage"), t("The URL (web address) you specifed is not valid. Remember that it must be fully qualified, i.e. of the form http://yourhomepage.com/directory."));
      }
    }

then I must say I'm using just the same error reporting used just some lines before, as in:

    /*
    ** Validate the comment's body.
    */

    if ($edit["comment"] == "") {
      return array(t("Empty comment"), t("The comment you submitted is empty."));
    }
dries’s picture

Looks good to me but:

  1. Change 'email' to 'mail' for sake of consistency with the other mail-fields. See the users table for example; we use 'mail' elsewhere.
  2. Provide updates for database/database.mysql and database/updates.inc.
  3. Try using single qoutes around constant strings. Preferred, not required.
  4. There is no point creating tiny _form_comment_xxx() functions when they only have one call site.
pablobm’s picture

StatusFileSize
new15.84 KB

Some notes now:

  1. 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() :

        /*
        ** Sometimes modules display content composed by people who are
        ** not registers members of the site (i.e. mailing list or news
        ** aggregator modules).  This clause enables modules to display
        ** the true author of the content.
        */

    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.

  2. There's a collision problem between users.name and comments.name. I resolve it the following way
    (example taken from code):

    
    $comment = db_fetch_object(db_query("SELECT c.*, u.name as registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d", $cid));
      $comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
    
    

    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).

pablobm’s picture

StatusFileSize
new453 bytes

Attaching patch for database/database.mysql

pablobm’s picture

StatusFileSize
new1.04 KB

Attaching patch for database/updates.inc

pablobm’s picture

StatusFileSize
new471 bytes

I don't know if needed, but I attach a patch for database/database.pgsql also

dries’s picture

StatusFileSize
new18.46 KB

I 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.

  1. The error reporting should not only happen after one clicked 'Post' but also after one clicked 'Preview'. When posting failed, the form should be presented along with an explanation of what's wrong. The form fields should not be emptied.
  2. When I posted as anomyous user, my name and e-mail address are stored properly in the database, yet it doesn't get shown anywhere. I'm using the 'Xtemplate default' theme.
  3. After posting a comment, we used to display a message that the comment has been posted. This is no longer the case. I don't think your patch broke this but I figured I would mention it nonetheless.

Getting there ...

dries’s picture

Updates:

  1. My anonymous username and e-mail address are shown when the comments are collapsed. They are not shown when the coments are unfolded.
  2. I was surprised to see that my e-mail address was publicly shown. This was confusing because (1) I added the URL of my homepage and would expect that to take precedence and (2) I don't want my e-mail address to be shown. I'm not opposed to showing one's e-mail address but it should be communicated to the user.
pablobm’s picture

About #17:

  1. As I said on #11 (I forgot login that time again) I do this that because
    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.
  2. As I understand themes, this should be implemented in-theme, since I can only provide default hooks
    that are usually overriden by it. Am I wrong?
  3. In effect, this seems not to be my fault, but HEAD code's

About #18:

  1. 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).

  2. Just the same.
pablobm’s picture

StatusFileSize
new15.95 KB

New patch attached.

  1. I've noticed that posting as 'Anonymous' issued a 'Name already taken' error. Fixed.
  2. When validating name, if it is set to 'Anonymous' (or whatever anonymous commenters are called)
    the it is set to '', so further actions over the comment will treat it as a 100% anonymous comment.
  3. 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:

    SELECT ... c.name ... c.name, c.mail ...
    

    Was wrong in my code, but you didn't noticed the two fields on the right and patched as:

    SELECT ... c.name, c.mail ... c.name, c.mail ...
    

    Now it is OK, as:

    SELECT ... c.name, c.mail ...
    
  4. 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 (making
    NULL 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)

pablobm’s picture

StatusFileSize
new453 bytes

New patch for database/database.mysql (see #20.)

pablobm’s picture

StatusFileSize
new466 bytes

New patch for database/database.pgsql (see #20.)

pablobm’s picture

StatusFileSize
new1.07 KB

New patch for database/updates.inc (see #20.)

davidnunez’s picture

This 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.

dries’s picture

  1. It is probably a good idea to patch format_name() and to route all 'name displaying' through format_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.
  2. The comment validation needs work, especially now more things can go wrong. When the user's comment is incorrect or incomplete, an error message is shown but his comment is lost. If you don't know how to fix this behavior, we can work on that later.
Anonymous’s picture

While 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

pablobm’s picture

StatusFileSize
new13.8 KB

The 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

pablobm’s picture

In 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...

dries’s picture

I 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.

pablobm’s picture

One 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?

morbus iff’s picture

There 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).

morbus iff’s picture

#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.

Anonymous’s picture

StatusFileSize
new670 bytes

This 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.

Anonymous’s picture

StatusFileSize
new10.38 KB

This 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.

Anonymous’s picture

StatusFileSize
new670 bytes

It seems I like to screw things up. Sorry.

Forget my last dupe follow-ups, please. Here is the patch again

morbus iff’s picture

Pablo's comment_0.diff (#35) fixed my #32. Changing status to patch for commit.

dries’s picture

When 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 ... ?

morbus iff’s picture

Heh, 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?

morbus iff’s picture

StatusFileSize
new877 bytes

I'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");

dries’s picture

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.

Code-wise I think it is better to test against $comment->uid than to test against $comment->name. At least it is slightly more consistent with the rest of the code.

dries’s picture

The redirect patch looks like an improvement as the use of comment_node_url() appears to be broken. I suggest we remove the last instance of comment_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).

gábor hojtsy’s picture

The 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.

morbus iff’s picture

Re: #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.

morbus iff’s picture

Goba: 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.

gábor hojtsy’s picture

Morbus: 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.

morbus iff’s picture

Sigh, 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?

morbus iff’s picture

StatusFileSize
new1.25 KB

Gah - 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.

dries’s picture

When you submit a comment, you know the $nid, no?

morbus iff’s picture

Right. 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.

gábor hojtsy’s picture

$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.

fx-1’s picture

Dries 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

morbus iff’s picture

StatusFileSize
new3.8 KB

Goba - 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.

morbus iff’s picture

Dries: 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.

dries’s picture

I'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/cid to something like book/view/nid/cid/reply or book/reply/nid/cid.

Personally, I'm not really in favor of the anon_ prefix.

Chris Johnson’s picture

Hmm, 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.

gábor hojtsy’s picture

The 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.

dries’s picture

I committed patch #35 by Pablo to HEAD until others can reproduce my problem.

dries’s picture

Anonymous’s picture