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-08-09 01:14 pm

[dw-free] S2 page summary module doesn't show threaded comments

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

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

Show number of replies to each comment (default is still as a tooltip); some
refactoring.

Patch by [personal profile] kareila.

Files modified:
  • bin/upgrading/s2layers/core2.s2
--------------------------------------------------------------------------------
diff -r f869d77eb4b4 -r 418db41d190c bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2	Sun Aug 09 09:05:46 2009 +0000
+++ b/bin/upgrading/s2layers/core2.s2	Sun Aug 09 13:14:11 2009 +0000
@@ -1993,6 +1993,13 @@ set text_post_comment_friends = "Leave a
 set text_post_comment_friends = "Leave a comment";
 set text_read_comments_friends = "1 comment // # comments";
 
+property string text_read_comments_threads {
+    des = "Link text to read comment threads from an entry";
+    format = "plurals";
+    example = "1 response // # responses";
+}
+set text_read_comments_threads = "1 response // # responses";
+
 ##===============================
 ## Text - entry actions
 ##===============================
@@ -3271,73 +3278,84 @@ function print_module_poweredby() {
     close_module();
 }
 
+function print_module_pagesummary_comment_count(Comment comment) : int {
+    var int count = 0;
+    foreach var Comment c ( $comment.replies ) {
+        $count = $count + 1 + print_module_pagesummary_comment_count($c);
+    }
+    return $count;
+}
+
+function print_module_pagesummary_comments(string esubject, int count, string prop) : string {
+    var string subject = ($esubject != "" ? striphtml($esubject) : "<em>$*text_nosubject</em>");
+    var string module_comment_text = get_plural_phrase($count, $prop);
+
+    if ($*module_pagesummary_opts_comments_tooltip) {
+        return "title='$module_comment_text'>$subject</a>";
+    }
+    elseif ($count != 0) {
+        return ">$subject</a> +$module_comment_text";
+    }
+    else {
+        return ">$subject</a>";
+    }
+}
+
 function print_module_pagesummary() {
     var Page p = get_page();
-    var string title = $*text_module_pagesummary;
-
     var string[] links = [];
-    if ($p isa EntryPage) {
+
+    if ( $p isa EntryPage ) {
         var EntryPage cp = $p as EntryPage;
-        var string subject;
-        var string poster;
         foreach var Comment c ( $cp.comments ) {
-            $poster = isnull $c.poster ? $*text_poster_anonymous : $c.poster->ljuser();
-            $subject = ($c.subject != "" ? striphtml($c.subject) : "<em>$*text_nosubject</em>");
-            $links[size $links] = """$poster - <a href="#$c.anchor">$subject</a>""";
-        }
-    }
-
-    elseif ($p isa FriendsPage) {
+            var int count = print_module_pagesummary_comment_count($c);
+            var string comment_display =
+                print_module_pagesummary_comments($c.subject, $count, "text_read_comments_threads");
+            var string poster = isnull $c.poster ? $*text_poster_anonymous : $c.poster->ljuser();
+
+            $links[size $links] = """$poster - <a href="#$c.anchor" $comment_display""";
+        }
+    }
+
+    elseif ( $p isa FriendsPage ) {
         var FriendsPage cp = $p as FriendsPage;
-        var string subject;
-        var string poster;
         foreach var Entry e ( $cp.entries ) {
-            $poster = $e.poster->ljuser();
-            $subject = ($e.subject != "" ? striphtml($e.subject) : "<em>$*text_nosubject</em>");
-            var string module_comment_text = get_plural_phrase($e.comments.count, "text_read_comments_friends");
-            var string comment_display;
-            if ($*module_pagesummary_opts_comments_tooltip) {
-                $comment_display = "title='$module_comment_text'>$subject</a>";
-            }
-            else {
-                 if ($e.comments.count != 0) {
-                     $comment_display = ">$subject</a> +$module_comment_text";
-                 }
-                 else {
-                     $comment_display = ">$subject</a>";
-                 }
-            }
+            var string comment_display =
+                print_module_pagesummary_comments($e.subject, $e.comments.count, "text_read_comments_friends");
+            var string poster = $e.poster->ljuser();
             
-            if (not $e.poster->equals($e.journal)) {
-                $links[size $links] = """$poster in $e.journal - <a href="#entry-$e.itemid" $comment_display""";
-            }
-            else {
+            if ( not $e.poster->equals($e.journal) ) {
+                $poster = "$poster in $e.journal";
+            }
+
+            $links[size $links] = """$poster - <a href="#entry-$e.itemid" $comment_display""";
+        }
+    }
+
+    elseif ( $p isa RecentPage ) {
+        var RecentPage cp = $p as RecentPage;
+        foreach var Entry e ( $cp.entries ) {
+            var string comment_display =
+                print_module_pagesummary_comments($e.subject, $e.comments.count, "text_read_comments");
+            var string poster = $e.poster->ljuser();
+
+            if ( not $e.poster->equals($e.journal) ) {
                 $links[size $links] = """$poster - <a href="#entry-$e.itemid" $comment_display""";
             }
-        }
-    }
-    elseif ($p isa RecentPage) {
-        var RecentPage cp = $p as RecentPage;
-        var string subject;
-        var string poster;
+            else {
+                $links[size $links] = """<a href="#entry-$e.itemid" $comment_display""";
+            }
+        }
+    }
+    
+    elseif ( $p isa DayPage ) {
+        var DayPage cp = $p as DayPage;
         foreach var Entry e ( $cp.entries ) {
-            $subject = ($e.subject != "" ? striphtml($e.subject) : "<em>$*text_nosubject</em>");
-            var string module_comment_text = get_plural_phrase($e.comments.count, "text_read_comments");
-            var string comment_display;
-            if ($*module_pagesummary_opts_comments_tooltip) {
-                $comment_display = "title='$module_comment_text'>$subject</a>";
-            }
-            else {
-                 if ($e.comments.count != 0) {
-                     $comment_display = ">$subject</a> +$module_comment_text";
-                 }
-                 else {
-                     $comment_display = ">$subject</a>";
-                 }
-            }
-            
-            if (not $e.poster->equals($e.journal)) {
-                $poster = $e.poster->ljuser();
+            var string comment_display =
+                print_module_pagesummary_comments($e.subject, $e.comments.count, "text_read_comments");
+            var string poster = $e.poster->ljuser();
+
+            if ( not $e.poster->equals($e.journal) ) {
                 $links[size $links] = """$poster - <a href="#entry-$e.itemid" $comment_display""";
             }
             else {
@@ -3345,42 +3363,12 @@ function print_module_pagesummary() {
             }
         }
     }
-    
-    elseif ($p isa DayPage) {
-        var DayPage cp = $p as DayPage;
-        var string subject;
-        var string poster;
-        foreach var Entry e ( $cp.entries ) {
-            $subject = ($e.subject != "" ? striphtml($e.subject) : "<em>$*text_nosubject</em>");
-            var string module_comment_text = get_plural_phrase($e.comments.count, "text_read_comments");
-            var string comment_display;
-            if ($*module_pagesummary_opts_comments_tooltip) {
-                $comment_display = "title='$module_comment_text'>$subject</a>";
-            }
-            else {
-                 if ($e.comments.count != 0) {
-                     $comment_display = ">$subject</a> +$module_comment_text";
-                 }
-                 else {
-                     $comment_display = ">$subject</a>";
-                 }
-            }
-
-            if (not $e.poster->equals($e.journal)) {
-                $poster = $e.poster->ljuser();
-                $links[size $links] = """$poster - <a href="#entry-$e.itemid" $comment_display""";
-            }
-            else {
-                $links[size $links] = """<a href="#entry-$e.itemid" $comment_display""";
-            }
-        }
-    }
-    if (size($links) < 1) { return; }
-    open_module("pagesummary", $title, "");
+
+    if ( size($links) < 1 ) { return; }
+    open_module("pagesummary", $*text_module_pagesummary, "");
     print_module_list($links);
     close_module();
 }
-
 
 function print_module_tags() {
     var Page p = get_page();
--------------------------------------------------------------------------------

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