From 173bec1574cb6b245a7bcd01f215d7b0315f999b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 5 Jan 2010 20:52:27 -0800 Subject: [PATCH] Handle linking to posts not on the first page on a thread view. Fixes bug #11318. --- lib/WebGUI/Asset/Post.pm | 27 +++++++++++++++++++ lib/WebGUI/Asset/Wobject/Collaboration.pm | 11 ++------ .../Wobject/Collaboration/templateVariables.t | 4 +-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 635e3b526..f3ee74007 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -495,6 +495,33 @@ sub getDeleteUrl { return $self->getUrl("func=delete;revision=".$self->get("revisionDate")); } +#------------------------------------------------------------------- + +=head2 getDirectLinkUrl ( ) + +Returns the URL for this Post, which links directly to its anchor and page. + +=cut + +sub getDirectLinkUrl { + my $self = shift; + my $url; + my $page_size = $self->getThread->getParent->get('postsPerPage'); + my $place = $self->getRank+1; + my $page = int($place/$page_size) + 1; + my $page_frag = 'pn='.$page; + if ($self->get("status") eq "pending") { + $url = $self->getUrl($page_frag.";revision=".$self->get("revisionDate")); + } + else { + $url = $self->getUrl($page_frag); + } + $url .= "#id".$self->getId; + + return $url; +} + + #------------------------------------------------------------------- =head2 getEditUrl ( ) diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 8b4ae34e8..afb2e985a 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -130,7 +130,7 @@ sub appendPostListTemplateVars { if ($self->get("displayLastReply")) { my $lastPost = $post->getLastPost(); %lastReply = ( - "lastReply.url" => $lastPost->getUrl.'#id'.$lastPost->getId, + "lastReply.url" => $lastPost->getDirectLinkUrl, "lastReply.title" => $lastPost->get("title"), "lastReply.user.isVisitor" => $lastPost->get("ownerUserId") eq "1", "lastReply.username" => $lastPost->get("username"), @@ -142,17 +142,10 @@ sub appendPostListTemplateVars { } $hasRead = $post->isMarkedRead; } - my $url; - if ($post->get("status") eq "pending") { - $url = $post->getUrl("revision=".$post->get("revisionDate"))."#id".$post->getId; - } - else { - $url = $post->getUrl."#id".$post->getId; - } my %postVars = ( %{$post->get}, "id" => $post->getId, - "url" => $url, + "url" => $post->getDirectLinkUrl, rating_loop => \@rating_loop, "content" => $post->formatContent, "status" => $post->getStatus, diff --git a/t/Asset/Wobject/Collaboration/templateVariables.t b/t/Asset/Wobject/Collaboration/templateVariables.t index 10ff8a086..b05d16cd7 100644 --- a/t/Asset/Wobject/Collaboration/templateVariables.t +++ b/t/Asset/Wobject/Collaboration/templateVariables.t @@ -89,8 +89,8 @@ ok( !$posts->[0]->{'user.isVisitor'}, 'first post made by visitor'); ok( $posts->[0]->{'hideProfileUrl'}, 'hide profile url, and user is visitor'); ok( !$posts->[0]->{'lastReply.user.isVisitor'}, 'lastReply not made by visitor'); ok( $posts->[0]->{'lastReply.hideProfileUrl'}, 'lastReply hide profile url, since user is visitor'); -is( $posts->[0]->{'lastReply.url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'lastReply url has a query fragment prefixed by "id"'); -is( $posts->[0]->{'url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'url has a query fragment prefixed by "id"'); +is( $posts->[0]->{'lastReply.url'}, $threads[1]->getUrl.'?pn=1#id'.$threads[1]->getId, 'lastReply url has a query fragment prefixed by "id"'); +is( $posts->[0]->{'url'}, $threads[1]->getUrl.'?pn=1#id'.$threads[1]->getId, 'url has a query fragment prefixed by "id"'); ###################################################################