When posting a new comment to a node with more comments than in comment_default_per_page_nodetype, the user should be redirected to the right page, along with the right anchor for the comment.
For example, a forum thread has 90 replies, and forums are set to 30 comments per page. When a user posts the 91st comment, she should be taken to page 2 (page 3 of the comments), i.e. example.com/node/1234?page=2#comment-8765
The attached patch fixes this issue. With Drupal 6's new ability to have custom comment settings per node type, I could not figure out a way to do this without calling node_load or writing a database query to determine the node's type. I'm thinking writing an individual query for this may be better than calling node_load (the current solution). Please review and look for optimization possibilities.
Comment | File | Size | Author |
---|---|---|---|
#18 | comment_newpage.patch | 3.98 KB | snufkin |
#10 | comment-redirect_after_post-2_1.patch | 874 bytes | catch |
#9 | comment-redirect_after_post-2_0.patch | 682 bytes | catch |
#6 | comment-redirect_after_post-2.patch | 684 bytes | jrbeeman |
comment-redirect_after_post.patch | 919 bytes | jrbeeman | |
Comments
Comment #1
jrbeeman(Changing version to 6.x-dev)
Comment #2
catchNo time to review this evening, but a big +1 for this. Subscribing so I can take a look tomorrow.
Comment #3
JirkaRybka CreditAttribution: JirkaRybka commentedThis is closely related to http://drupal.org/node/26966 (comment-links in general), and might be probably fixed together with that.
While reviewing (I've no time this moment, unfortunately), please double-check whether this works for both flat AND threaded mode - for threaded the comment may end up anywhere if it's a reply, not only the last page.
Comment #4
catchReview of this issue is blocked by: http://drupal.org/node/187482
Comment #5
catchThis doesn't work on threaded comments - posting a comment to the first page of a thread redirects you to the last page regardless. Without permalinks for comments (i.e. a way to link to a specific comment whilst retaining context) it's going to be near impossible to fix this issue, so marking as needs work and bumping to D7. Obviously if you come up with an approach which will work for D6, please reset the issue and I'll do my best to review it again.
Comment #6
jrbeemanNew attempt at a patch for this. This patch uses the new comment_new_page_count method, which returns the query and looks like it handles all the threading stuff correctly.
Comment #7
catchOK so I just installed this and tested it with a couple of different comment settings, it passed in all cases.
In a related issue Dries pointed out that this doesn't work when comments are in moderation - I think it's worth arguing that the existing implementation doesn't work when comments are in moderation either, so this is a major step forward in usability - allowing people to see their comment once it's posted regardless of paging and threading and bringing the comment system into line with most discussion forums etc. which do the same thing.
I won't mark to RTBC yet in case there are code optimisations, the extra queries are only on comment submit though (and also save people clicking through pagers to see their comment in context afterwards), so that might not be an issue. Very nice work, thanks!
Comment #8
jrbeemanGreat, thanks! Since the new patch uses comment_new_page_count, which requires a node object as a parameter, the node_load is required now. But, like you said, this only occurs upon comment submission, and significantly saves on paging through comments.
Comment #9
catchOK so looking at this again, I reckon $query should be renamed to $page. Attached patch modifies this and nothing else. On the assumption there's no other way to do this than the node_load (and the fact it's only a single node_load on form submission, saving a lot of clicks through the pager caused by current behaviour), going to mark this RTBC. A solution for comments in moderation needs to be found, but that's a seperate issue from the one dealt with by this patch, and will have to wait for D7 I think.
Comment #10
catchOr even better rerolled from root with no offset this time.
Comment #11
catchComment #12
Gábor HojtsyThanks, committed.
Comment #13
catchNo more hacking comment.module in D6 for me! Thanks!
Comment #14
(not verified) CreditAttribution: commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #15
mykle CreditAttribution: mykle commentedstill a problem in drupal 5.x ... is a backport practical?
Comment #16
catchI don't think this will get committed to 5.x even if backported , but if not it would be a small patch to maintain or might be possible to do it in a module. Changing status anyway.
Comment #18
snufkin CreditAttribution: snufkin commentedPatch implements the comment_new_page_count from D6 and adds the page query part similarly to D6 in
comment_form_submit()
. It works with threaded commends in oldest first mode, for some reason it doesn't work for the newest first mode, perhaps someone with more insight into the database queries in that branch of the if can use this as a starting point.I had to add a +1 into the comment count, otherwise the function thinks that we still dont have enough comments. From node load we get the number of comments without our new comment, so the first if branch
if ($num_comments <= $comments_per_page
will be true for the first comment that should be on the next page.Its certainly possible to do this in a contrib module, just implement the function that calculates the new pages, override the comment_form_submit to your own, replicating it and adding the paging part.
Comment #19
Max_Headroom CreditAttribution: Max_Headroom commentedCan you please remove the settings.php changes from your patch.
Comment #20
thinkyhead CreditAttribution: thinkyhead commentedThis set of patches seems to ignore the fact that comments can be edited. At least, the behavior I'm seeing is that even if I edit a comment on the first page of a pager, submitting the comment always takes me to the last page. Can the patch authors confirm that this is a known side-effect?
Comment #21
snufkin CreditAttribution: snufkin commentedYeah, if i remember correctly after so long, the patch automatically calculates the number of comments and forwards the user regardless if that was an edit or a new comment inserted.
Comment #22
TR CreditAttribution: TR commentedA fix for this issue was committed to Drupal 6.x in comment #12.
This issue is still open only for a backport of this fix to Drupal 5.x.
Drupal 5.x is no longer supported. Backport won't happen.
Comment #23
JirkaRybka CreditAttribution: JirkaRybka commentedIn which case, return to the status before #15 is more accurate IMO.