fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-11-07 11:36 am

[dw-free] better organization of LJ functions

[commit: http://hg.dwscoalition.org/dw-free/rev/280b068eb022]

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

Move LJ::make_link from ljlib.pl to LJ/S2.pm -- only used there; anything
else we need for this can just use create_url.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/S2.pm
  • cgi-bin/LJ/S2/FriendsPage.pm
  • cgi-bin/LJ/S2/RecentPage.pm
  • cgi-bin/ljlib.pl
--------------------------------------------------------------------------------
diff -r cab163e5dd3b -r 280b068eb022 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Mon Nov 07 19:19:30 2011 +0800
+++ b/cgi-bin/LJ/S2.pm	Mon Nov 07 19:37:25 2011 +0800
@@ -339,6 +339,28 @@
 }
 
 # <LJFUNC>
+# name: LJ::S2::make_link
+# des: Takes a group of key=value pairs to append to a URL.
+# returns: The finished URL.
+# args: url, vars
+# des-url: A string with the URL to append to.  The URL
+#          should not have a question mark in it.
+# des-vars: A hashref of the key=value pairs to append with.
+# </LJFUNC>
+sub make_link
+{
+    my $url = shift;
+    my $vars = shift;
+    my $append = "?";
+    foreach (keys %$vars) {
+        next if ($vars->{$_} eq "");
+        $url .= "${append}${_}=$vars->{$_}";
+        $append = "&";
+    }
+    return $url;
+}
+
+# <LJFUNC>
 # name: LJ::S2::get_tags_text
 # class: s2
 # des: Gets text for display in entry for tags compatibility.
diff -r cab163e5dd3b -r 280b068eb022 cgi-bin/LJ/S2/FriendsPage.pm
--- a/cgi-bin/LJ/S2/FriendsPage.pm	Mon Nov 07 19:19:30 2011 +0800
+++ b/cgi-bin/LJ/S2/FriendsPage.pm	Mon Nov 07 19:37:25 2011 +0800
@@ -277,7 +277,7 @@
         my $newskip = $skip - $itemshow;
         if ($newskip > 0) { $linkvars{'skip'} = $newskip; }
         else { $newskip = 0; }
-        $nav->{'forward_url'} = LJ::make_link($base, \%linkvars);
+        $nav->{'forward_url'} = LJ::S2::make_link( $base, \%linkvars );
         $nav->{'forward_skip'} = $newskip;
         $nav->{'forward_count'} = $itemshow;
         $p->{head_content} .= qq#<link rel="next" href="$nav->{forward_url}" />\n#;
@@ -290,7 +290,7 @@
     unless (($eventnum + $hiddenentries) != $itemshow || $skip == $maxskip || !$is_prev_exist) {
         my $newskip = $skip + $itemshow;
         $linkvars{'skip'} = $newskip;
-        $nav->{'backward_url'} = LJ::make_link($base, \%linkvars);
+        $nav->{'backward_url'} = LJ::S2::make_link( $base, \%linkvars );
         $nav->{'backward_skip'} = $newskip;
         $nav->{'backward_count'} = $itemshow;
         $p->{head_content} .= qq#<link rel="prev" href="$nav->{backward_url}" />\n#;
diff -r cab163e5dd3b -r 280b068eb022 cgi-bin/LJ/S2/RecentPage.pm
--- a/cgi-bin/LJ/S2/RecentPage.pm	Mon Nov 07 19:19:30 2011 +0800
+++ b/cgi-bin/LJ/S2/RecentPage.pm	Mon Nov 07 19:37:25 2011 +0800
@@ -247,7 +247,7 @@
         my $newskip = $skip - $itemshow;
         $newskip = 0 if $newskip <= 0;
         $nav->{'forward_skip'} = $newskip;
-        $nav->{'forward_url'} = LJ::make_link( "$p->{'base_url'}/",
+        $nav->{'forward_url'} = LJ::S2::make_link( "$p->{'base_url'}/",
                                 { skip => $newskip || "", %linkattrs } );
         $nav->{'forward_count'} = $itemshow;
         $p->{head_content} .= qq{<link rel="next" href="$nav->{forward_url}" />\n}
@@ -264,7 +264,7 @@
             $nav->{'backward_url'} = "$p->{'base_url'}/$date_slashes";
         } elsif ($is_prev_exist) {
             my $newskip = $skip + $itemshow;
-            $nav->{'backward_url'} = LJ::make_link( "$p->{'base_url'}/",
+            $nav->{'backward_url'} = LJ::S2::make_link( "$p->{'base_url'}/",
                                 { skip => $newskip || "", %linkattrs } );
             $nav->{'backward_skip'} = $newskip;
         }
diff -r cab163e5dd3b -r 280b068eb022 cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl	Mon Nov 07 19:19:30 2011 +0800
+++ b/cgi-bin/ljlib.pl	Mon Nov 07 19:37:25 2011 +0800
@@ -410,28 +410,6 @@
 }
 
 # <LJFUNC>
-# name: LJ::make_link
-# des: Takes a group of key=value pairs to append to a URL.
-# returns: The finished URL.
-# args: url, vars
-# des-url: A string with the URL to append to.  The URL
-#          should not have a question mark in it.
-# des-vars: A hashref of the key=value pairs to append with.
-# </LJFUNC>
-sub make_link
-{
-    my $url = shift;
-    my $vars = shift;
-    my $append = "?";
-    foreach (keys %$vars) {
-        next if ($vars->{$_} eq "");
-        $url .= "${append}${_}=$vars->{$_}";
-        $append = "&";
-    }
-    return $url;
-}
-
-# <LJFUNC>
 # name: LJ::get_authas_user
 # des: Given a username, will return a user object if remote is an admin for the
 #      username.  Otherwise returns undef.
--------------------------------------------------------------------------------