afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-07-25 01:14 pm

[dw-free] Arguments cause a page to be indexed as different content on search engines

[commit: http://hg.dwscoalition.org/dw-free/rev/8d2c494bf77a]

http://bugs.dwscoalition.org/show_bug.cgi?id=1427

Refactoring: use functions.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/S2/EntryPage.pm
  • cgi-bin/LJ/S2/ReplyPage.pm
  • cgi-bin/weblib.pl
  • htdocs/talkpost.bml
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r 4dedfba1fe16 -r 8d2c494bf77a cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm	Sat Jul 25 04:48:46 2009 +0000
+++ b/cgi-bin/LJ/S2/EntryPage.pm	Sat Jul 25 13:14:17 2009 +0000
@@ -56,10 +56,7 @@ sub EntryPage
     $p->{head_content} .= qq{<link rel="next" href="$next_url" />\n} if $next_url;
 
     # canonical link to the entry or comment thread
-    my $canonical_url = $permalink;
-    my $threadid = $get->{thread} + 0;
-    $canonical_url .= "?thread=$threadid#t$threadid" if $threadid;
-    $p->{head_content} .= qq{<link rel="canonical" href="$canonical_url" />\n};
+    $p->{head_content} .= LJ::canonical_link( $permalink, $get->{thread} );
 
     # quickreply js libs
     LJ::need_res(qw(
diff -r 4dedfba1fe16 -r 8d2c494bf77a cgi-bin/LJ/S2/ReplyPage.pm
--- a/cgi-bin/LJ/S2/ReplyPage.pm	Sat Jul 25 04:48:46 2009 +0000
+++ b/cgi-bin/LJ/S2/ReplyPage.pm	Sat Jul 25 13:14:17 2009 +0000
@@ -42,12 +42,10 @@ sub ReplyPage
     return if $opts->{'handler_return'};
     return if $opts->{'redir'};
     my $ditemid = $entry->ditemid;
+    my $replytoid = $get->{replyto} ? $get->{replyto} : 0;
 
     # canonical link to the entry or comment thread
-    my $canonical_url = $entry->url;
-    my $replytoid = $get->{replyto} ? $get->{replyto} + 0 : 0;
-    $canonical_url .= "?thread=$replytoid#t$replytoid" if $replytoid;
-    $p->{head_content} .= qq{<link rel="canonical" href="$canonical_url" />\n};
+    $p->{head_content} .= LJ::canonical_link( $entry->url, $replytoid );
 
     $p->{'head_content'} .= $LJ::COMMON_CODE{'chalresp_js'};
 
diff -r 4dedfba1fe16 -r 8d2c494bf77a cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Sat Jul 25 04:48:46 2009 +0000
+++ b/cgi-bin/weblib.pl	Sat Jul 25 13:14:17 2009 +0000
@@ -3604,4 +3604,14 @@ sub statusvis_message_js {
     return "<script>Site.StatusvisMessage=\"" . LJ::Lang::ml("statusvis_message.$statusvis_full") . "\";</script>";
 }
 
+# returns canonical link for use in header of journal pages
+sub canonical_link {
+    my ( $url, $tid ) = @_;
+    if ( $tid += 0 ) {  # sanitize input
+        $url .= "?thread=$tid" . LJ::Talk::comment_anchor( $tid );
+    }
+    return qq{<link rel="canonical" href="$url" />\n};
+
+}
+
 1;
diff -r 4dedfba1fe16 -r 8d2c494bf77a htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Sat Jul 25 04:48:46 2009 +0000
+++ b/htdocs/talkpost.bml	Sat Jul 25 13:14:17 2009 +0000
@@ -134,10 +134,7 @@ body<=
     my $entry = LJ::Entry->new($u, ditemid => $ditemid);
 
     # canonical link to the entry or comment thread
-    my $canonical_url = $entry->url;
-    my $threadid = $GET{replyto} + 0;
-    $canonical_url .= "?thread=$threadid#t$threadid" if $threadid;
-    $head .= qq{<link rel="canonical" href="$canonical_url" />\n};
+    $head .= LJ::canonical_link( $entry->url, $GET{replyto} );
 
     $parpost ||= $item;  # if there's no parent post, remote is reply to top-level item
 
diff -r 4dedfba1fe16 -r 8d2c494bf77a htdocs/talkread.bml
--- a/htdocs/talkread.bml	Sat Jul 25 04:48:46 2009 +0000
+++ b/htdocs/talkread.bml	Sat Jul 25 13:14:17 2009 +0000
@@ -115,10 +115,7 @@ body<=
     my $entry = LJ::Entry->new($u, ditemid => $ditemid);
 
     # canonical link to the entry or comment thread
-    my $canonical_url = $entry->url;
-    my $threadid = $GET{thread} + 0;
-    $canonical_url .= "?thread=$threadid#t$threadid" if $threadid;
-    $$head .= qq{<link rel="canonical" href="$canonical_url" />\n};
+    $$head .= LJ::canonical_link( $entry->url, $GET{thread} );
 
     $u->preload_props("opt_blockrobots", "adult_content") if $u->is_visible;
     if (!$u->is_visible || $u->should_block_robots || ($entry && $entry->should_block_robots)) {
--------------------------------------------------------------------------------