mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-12-03 05:29 am

[dw-free] Logic for checking format=light/style=mine, etc arguments is duplicated in various places

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

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

Deduplicate logic for creating style arguments in URLs.

Patch by [personal profile] afuna.

Files modified:
  • cgi-bin/LJ/S2.pm
  • cgi-bin/LJ/S2/EntryPage.pm
  • cgi-bin/weblib.pl
  • htdocs/talkpost.bml
  • htdocs/talkpost_do.bml
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r 0b282f02da3d -r 861cff38f7de cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Thu Dec 03 04:54:44 2009 +0000
+++ b/cgi-bin/LJ/S2.pm	Thu Dec 03 05:29:36 2009 +0000
@@ -1854,12 +1854,9 @@ sub Entry_from_entryobj
 
     # is style=mine used?  or if remote has it on and this entry is not part of
     # their journal.  if either are yes, it needs to be added to comment links
-    my $stylemine = "";
-    $stylemine .= "style=mine"
-        if $get->{style} eq 'mine' ||
-            ( $remote && $remote->prop( 'opt_stylemine' ) &&
-              $remote->id != $journalid );
-
+    my %opt_stylemine = $remote && $remote->prop( 'opt_stylemine' ) && $remote->id != $journalid ? ( style => 'mine' ) : ();
+    my $style_args = LJ::viewing_style_args( %$get, %opt_stylemine );
+    
     #load and prepare subject and text of entry
     my $subject = $entry_obj->subject_html;
     my $text = $entry_obj->event_raw;
@@ -1872,7 +1869,7 @@ sub Entry_from_entryobj
     my $suspend_msg = $entry_obj && $entry_obj->should_show_suspend_msg_to( $remote ) ? 1 : 0;
     # cleaning the entry text: cuts and such
     my $cut_disable = $opts->{cut_disable};
-    my $cleanhtml_opts = { cuturl => LJ::item_link( $journal, $jitemid, $anum, $stylemine ),
+    my $cleanhtml_opts = { cuturl => LJ::item_link( $journal, $jitemid, $anum, $style_args ),
         ljcut_disable => $cut_disable,
         suspend_msg => $suspend_msg,
         unsuspend_supportid => $suspend_msg ? $entry_obj->prop( 'unsuspend_supportid' ) : 0,
@@ -1938,8 +1935,8 @@ sub Entry_from_entryobj
     my $permalink = $entry_obj->url;
     my $replycount = $entry_obj->reply_count;
     my $nc = "nc=$replycount" if $replycount && $remote && $remote->prop( 'opt_nctalklinks' );
-    my $readurl = LJ::Talk::talkargs( $permalink, $nc, $stylemine );
-    my $posturl = LJ::Talk::talkargs( $permalink, 'mode=reply', $stylemine );
+    my $readurl = LJ::Talk::talkargs( $permalink, $nc, $style_args );
+    my $posturl = LJ::Talk::talkargs( $permalink, 'mode=reply', $style_args );
 
     my $comments_enabled = ( ( $journal->{opt_showtalklinks} eq "Y" ) && ( ! $entry_obj->props->{opt_nocomments} ) ) ? 1 : 0;
     my $has_screened = ( $entry_obj->props->{hasscreened} && LJ::can_manage( $remote, $journal ) ) ? 1 : 0;
diff -r 0b282f02da3d -r 861cff38f7de cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm	Thu Dec 03 04:54:44 2009 +0000
+++ b/cgi-bin/LJ/S2/EntryPage.pm	Thu Dec 03 05:29:36 2009 +0000
@@ -38,9 +38,7 @@ sub EntryPage
 
     my $itemid = $entry->jitemid;
     my $permalink = $entry->url;
-    my $stylemine = $get->{'style'} eq "mine" ? "style=mine" : "";
-    my $style_set = defined $get->{'s2id'} ? "s2id=" . int( $get->{'s2id'} ) : "";
-    my $style_arg = ($stylemine ne '' and $style_set ne '') ? ($stylemine . '&' . $style_set) : ($stylemine . $style_set);
+    my $style_arg = LJ::viewing_style_args( %$get );
 
     if ($u->should_block_robots || $entry->should_block_robots) {
         $p->{'head_content'} .= LJ::robot_meta_tags();
@@ -445,9 +443,7 @@ sub EntryPage_entry
     my $nc = "";
     $nc .= "nc=$replycount" if $replycount && $remote && $remote->{'opt_nctalklinks'};
 
-    my $stylemine = $get->{'style'} eq "mine" ? "style=mine" : "";
-    my $style_set = defined $get->{'s2id'} ? "s2id=" . int( $get->{'s2id'} ) : "";
-    my $style_arg = ($stylemine ne '' and $style_set ne '') ? ($stylemine . '&' . $style_set) : ($stylemine . $style_set);
+    my $style_arg = LJ::viewing_style_args( %$get );
     
     # load the userpic; include the keyword selected by the user 
     # as a backup for the alttext
diff -r 0b282f02da3d -r 861cff38f7de cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Thu Dec 03 04:54:44 2009 +0000
+++ b/cgi-bin/weblib.pl	Thu Dec 03 05:29:36 2009 +0000
@@ -1002,7 +1002,7 @@ sub viewing_style_args {
     my ( %args ) = @_;
     my $valid_style_args = {
         format => { light => 1 },
-        style  => { light => 1, style => 1, site => 1, mine => 1 },
+        style  => { light => 1, site => 1, mine => 1 },
     };
     
     my @valid_args;
diff -r 0b282f02da3d -r 861cff38f7de htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Thu Dec 03 04:54:44 2009 +0000
+++ b/htdocs/talkpost.bml	Thu Dec 03 05:29:36 2009 +0000
@@ -359,7 +359,7 @@ body<=
     $qotd = $entry->prop("qotdid") if $entry;
 
     my $jarg = "journal=$u->{'user'}&amp;";
-    my $readurl = LJ::Talk::talkargs($talkurl, $stylemine, $formatlight);
+    my $readurl = LJ::Talk::talkargs($talkurl, LJ::viewing_style_args( %GET ) );
 
     my $replycount = $entry->prop( "replycount" );
     my $readlink_text = BML::ml( "talk.commentsread.counted",
diff -r 0b282f02da3d -r 861cff38f7de htdocs/talkpost_do.bml
--- a/htdocs/talkpost_do.bml	Thu Dec 03 04:54:44 2009 +0000
+++ b/htdocs/talkpost_do.bml	Thu Dec 03 05:29:36 2009 +0000
@@ -217,10 +217,10 @@ body<=
     my $dtalkid = $comment->{talkid}*256 + $item->{anum};
 
     # Allow style=mine for QR redirects
-    my $stylemine = $POST{'stylemine'} ? 'style=mine' : '';
+    my $style_args = LJ::viewing_style_args( %POST );
 
     my $cthread = $POST{'viewing_thread'} ? "thread=$POST{viewing_thread}" : "view=$dtalkid";
-    my $commentlink = LJ::Talk::talkargs( $talkurl, $cthread, $stylemine ) . LJ::Talk::comment_anchor( $dtalkid );
+    my $commentlink = LJ::Talk::talkargs( $talkurl, $cthread, $style_args ) . LJ::Talk::comment_anchor( $dtalkid );
 
     my $ret = "";
     $ret .= "<?h1 $ML{'.success.title'} h1?>";
diff -r 0b282f02da3d -r 861cff38f7de htdocs/talkread.bml
--- a/htdocs/talkread.bml	Thu Dec 03 04:54:44 2009 +0000
+++ b/htdocs/talkread.bml	Thu Dec 03 05:29:36 2009 +0000
@@ -101,8 +101,7 @@ body<=
     $itemid = $init->{'itemid'}+0;
 
     # Get format/style parameters to pass to the URL later
-    my $formatlight = ( ( $GET{format} eq 'light' ) || ( $GET{style} eq 'light' ) ) ? 'style=light' : '';
-    my $stylemine = $init->{style} eq "mine" ? "style=mine" : "";
+    my $style_args = LJ::viewing_style_args( %GET, %$init );
 
     my $item = LJ::Talk::get_journal_item($u, $itemid);
 
@@ -587,11 +586,11 @@ body<=
                 }
 
                 $ret .= " <span class='talkargs'>(<a href='";
-                $ret .= LJ::Talk::talkargs( $talkurl, "thread=$dtid", $formatlight );
+                $ret .= LJ::Talk::talkargs( $talkurl, "thread=$dtid", $style_args );
                 $ret .= LJ::Talk::comment_anchor( $dtid ) . "'>$T{'link'}</a>)</span>";
 
                 if ($comment->remote_can_edit) {
-                    $ret .= "<a href='" . LJ::Talk::talkargs($comment->edit_url, $stylemine, $formatlight) . "'>" . LJ::img("editcomment", "", { 'align' => 'absmiddle', 'hspace' => 2, 'vspace' => }) . "</a>";
+                    $ret .= "<a href='" . LJ::Talk::talkargs( $comment->edit_url, $style_args ) . "'>" . LJ::img("editcomment", "", { 'align' => 'absmiddle', 'hspace' => 2, 'vspace' => }) . "</a>";
                 }
 
                 if (LJ::Talk::can_delete($remote, $u, $up, $userpost)) {
@@ -686,7 +685,7 @@ body<=
 
                 $ret .= "<p style='margin: 0.7em 0 0.2em 0'><font size='-2'>";
 
-                my $replyurl = LJ::Talk::talkargs($talkurl, "replyto=$dtid", $stylemine, $formatlight);
+                my $replyurl = LJ::Talk::talkargs( $talkurl, "replyto=$dtid", $style_args );
                 if ($post->{'state'} eq 'F') {
                     $ret .= "($T{'frozen'})";
                 } elsif ($remote) {
@@ -716,11 +715,11 @@ body<=
                     $ret .= "(<a href='$rooturl'>$T{'threadroot'}</a>)";
 
                     my $dpid = $parentid * 256 + $init->{'anum'};
-                    $ret .= "(<a href='" . LJ::Talk::talkargs($talkurl, "thread=$dpid", $stylemine, $formatlight);
+                    $ret .= "(<a href='" . LJ::Talk::talkargs( $talkurl, "thread=$dpid",  $style_args );
                     $ret .= LJ::Talk::comment_anchor( $dpid ) . "'>$T{'parent'}</a>)";
                 }
                 if ($post->{'children'} && @{$post->{'children'}}) {
-                    my $url = LJ::Talk::talkargs($talkurl, "thread=$dtid", $stylemine, $formatlight) . LJ::Talk::comment_anchor( $dtid );
+                    my $url = LJ::Talk::talkargs( $talkurl, "thread=$dtid", $style_args ) . LJ::Talk::comment_anchor( $dtid );
                     $ret .= "(<a href='$url'>$T{'thread'}</a>)";
 
                     if ((grep {! $_->{_loaded} and !($_->{state} eq "D")} @{$post->{'children'}}) && $show_thread_expander) {
@@ -736,7 +735,7 @@ body<=
             } else {
                 # link to message
 
-                my $url = LJ::Talk::talkargs( $talkurl, "thread=$dtid", $stylemine, $formatlight ) . LJ::Talk::comment_anchor( $dtid );
+                my $url = LJ::Talk::talkargs( $talkurl, "thread=$dtid", $style_args ) . LJ::Talk::comment_anchor( $dtid );
                 $ret .= "<a name='$htmlid'></a><span id='$htmlid'><table ><tbody><tr>";
                 $ret .= "<td><img src='$LJ::IMGPREFIX/dot.gif' height='1' width='" . ($opts->{'depth'} * 25) . "'></td>";
                 $ret .= "<td><a href='$url'>" . LJ::ehtml($post->{'subject'} || $T{'nosubject'}) . "</a> - $user, <i>$datepost</i>";
@@ -774,7 +773,7 @@ body<=
                             { replycount => $replycount } );
 
         if ( $dthread && $pages == 1 ) {
-            my $readurl = LJ::Talk::talkargs( $talkurl, $stylemine, $formatlight );
+            my $readurl = LJ::Talk::talkargs( $talkurl, $style_args );
             $readlink = "(<a href='$readurl#comments'>$readlink_text</a>) - ";
         } else {
             $readlink = "($comments_count) - " if $replycount > 0;
@@ -783,7 +782,7 @@ body<=
         #
         # Commenting UI
         #
-        my $posturl = LJ::Talk::talkargs($talkurl, "mode=reply", $stylemine, $formatlight);
+        my $posturl = LJ::Talk::talkargs( $talkurl, "mode=reply", $style_args );
 
         $ret .= "<form style='display: inline' method='post' action='$LJ::SITEROOT/talkmulti' name='multiform' id='multiform' >";
 
--------------------------------------------------------------------------------