fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-04-13 02:29 pm

[dw-free] S2 Entry code cleanup

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

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

Code cleanup: refactor the code that handles the list of tags in each entry.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/S2.pm
  • cgi-bin/LJ/S2/EntryPage.pm
--------------------------------------------------------------------------------
diff -r d178217cf6d6 -r b9060a643e0e cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Tue Apr 13 07:15:22 2010 -0700
+++ b/cgi-bin/LJ/S2.pm	Tue Apr 13 07:34:35 2010 -0700
@@ -1781,6 +1781,21 @@ sub TagDetail
     return $t;
 }
 
+sub TagList
+{
+    my ( $tags, $u, $jitemid, $opts, $taglist ) = @_;
+
+    while ( my ( $kwid, $keyword ) = each %{ $tags || {} } ) {
+        push @$taglist, Tag( $u, $kwid => $keyword );
+    }
+
+    LJ::Hooks::run_hooks( 'augment_s2_tag_list', u => $u, jitemid => $jitemid, tag_list => $taglist );
+    @$taglist = sort { $a->{name} cmp $b->{name} } @$taglist;
+
+    return "" unless $opts->{enable_tags_compatibility} && @$taglist;
+    return LJ::S2::get_tags_text( $opts->{ctx}, $taglist );
+}
+
 sub Entry
 {
     my ($u, $arg) = @_;
@@ -1966,15 +1981,8 @@ sub Entry_from_entryobj
 
     # tags loading and sorting
     my $tags = LJ::Tags::get_logtags( $journal, $jitemid );
-    my @taglist;
-    while (my ($keywordid, $keyword) = each %{$tags->{$jitemid} || {}}) {
-        push @taglist, Tag( $journal, $keywordid => $keyword );
-    }
-
-    @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
-    if ( $opts->{enable_tags_compatibility} && @taglist ) {
-        $text .= LJ::S2::get_tags_text($opts->{ctx}, \@taglist);
-    }
+    my $taglist = [];
+    $text .= TagList( $tags->{$jitemid}, $journal, $jitemid, $opts, $taglist );
 
     # building the CommentInfo and Entry objects
     my $comments = CommentInfo( $entry_obj->comment_info(
@@ -1997,7 +2005,7 @@ sub Entry_from_entryobj
         new_day => 0, #if true, set later
         end_day => 0,   #if true, set later
         userpic => $userpic,
-        tags => \@taglist,
+        tags => $taglist,
         permalink_url => $entry_obj->url,
         moodthemeid => $moodthemeid
         });
diff -r d178217cf6d6 -r b9060a643e0e cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm	Tue Apr 13 07:15:22 2010 -0700
+++ b/cgi-bin/LJ/S2/EntryPage.pm	Tue Apr 13 07:34:35 2010 -0700
@@ -476,23 +476,12 @@ sub EntryPage_entry
     $comments->{show_postlink} &&= $get->{mode} ne 'reply';
     $comments->{show_readlink} &&= $get->{mode} eq 'reply';
 
-    # load tags
-    my @taglist;
-    {
-        my $tag_map = $entry->tag_map;
-        while (my ($kwid, $kw) = each %$tag_map) {
-            push @taglist, Tag($u, $kwid => $kw);
-        }
-        LJ::Hooks::run_hooks('augment_s2_tag_list', u => $u, jitemid => $itemid, tag_list => \@taglist);
-        @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
-    }
-
     my $subject = LJ::CleanHTML::quote_html( $entry->subject_html, $get->{nohtml} );
     my $event = LJ::CleanHTML::quote_html( $entry->event_html, $get->{nohtml} );
 
-    if ($opts->{enable_tags_compatibility} && @taglist) {
-        $event .= LJ::S2::get_tags_text($opts->{ctx}, \@taglist);
-    }
+    # load tags
+    my @taglist;
+    $event .= TagList( $entry->tag_map, $u, $itemid, $opts, \@taglist );
 
     if ($entry->security eq "public") {
         $LJ::REQ_GLOBAL{'text_of_first_public_post'} = $event;
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org