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-06-26 02:09 pm

[dw-free] add 'view in original style' link to navigation strip, erase "style=mine&format=l

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

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

Toggle between "my style" and "original style" in the navstrip as
appropriate.

Patch by [personal profile] yvi.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/weblib.pl
--------------------------------------------------------------------------------
diff -r 08ccb45a25f1 -r a02882882284 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Fri Jun 26 13:51:34 2009 +0000
+++ b/bin/upgrading/en.dat	Fri Jun 26 14:07:42 2009 +0000
@@ -3717,6 +3717,8 @@ web.controlstrip.reloadpage.lightstyle=l
 
 web.controlstrip.reloadpage.mystyle=my style
 
+web.controlstrip.reloadpage.origstyle=original style
+
 web.controlstrip.select.friends.all=All Subscriptions
 
 web.controlstrip.select.friends.communities=Communities Only
diff -r 08ccb45a25f1 -r a02882882284 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Fri Jun 26 13:51:34 2009 +0000
+++ b/cgi-bin/weblib.pl	Fri Jun 26 14:07:42 2009 +0000
@@ -2507,7 +2507,6 @@ sub control_strip
     my $view = delete $opts{view} || $r->note( 'view' );
 
     my $querysep = $args ? "?" : "";
-    my $querysep2 = $args ? "&" : "?"; # for the ?style=mine/?format=light options
     my $uri = $baseuri ? "http://$baseuri" : "http://" . $r->header_in('Host') . $r->uri;
     $uri .= "$querysep$args";
     my $euri = LJ::eurl($uri);
@@ -2884,9 +2883,41 @@ LOGIN_BAR
 
     # search box and ?style=mine/?format=light options
     my @view_options;
-    push @view_options, "<a href='$uri${querysep2}style=mine'>" . LJ::Lang::ml( 'web.controlstrip.reloadpage.mystyle' ) . "</a>"
-        if $remote;
-    push @view_options, "<a href='$uri${querysep2}format=light'>" . LJ::Lang::ml( 'web.controlstrip.reloadpage.lightstyle' ) . "</a>"
+    #determine whether style is "mine", and define new uri variable to manipulate
+    #note: all expressions case-insensitive
+    my $currentstylemine = ($uri =~ m/style=mine/i);
+    my $newuri = $uri;
+    #manipulate destination URI for the style links
+    if ($currentstylemine) {
+        #if last character before style=mine is a &, it can be deleted together with style=mine, 
+        #since a ? will still be in front of the other arguments in the string
+        if ($newuri =~ m/\&style=mine/i) {
+            $newuri =~ s/\&style=mine//i;
+        } else {
+            #else the last character before style=mine was a "?" and should not be deleted.
+            #also, delete "&" after style=mine if there is one
+            $newuri =~ s/style=mine\&?//i;
+        }
+        #delete any trailing character - for example
+        #trailing "?" if only "?style=mine" was present in the first place
+        $newuri =~ s/\W$//;
+    }
+    my $querysep2;
+    #check whether newuri still has arguments to determine whether "?" or "&" needs to be used for next argument added
+    if ($newuri =~ m/\?/) {
+        $querysep2 = "&";
+    } else {
+        $querysep2 = "?";
+    }
+    #appropriate links depending on whether style is "mine" and whether format=light is possible on this type of content
+    if ($remote) {
+        if ($currentstylemine) {
+            push @view_options, "<a href='$newuri'>" . LJ::Lang::ml( 'web.controlstrip.reloadpage.origstyle' ) . "</a>"
+        } else {
+            push @view_options, "<a href='$newuri${querysep2}style=mine'>" . LJ::Lang::ml( 'web.controlstrip.reloadpage.mystyle' ) . "</a>"
+        }
+    }
+    push @view_options, "<a href='$newuri${querysep2}format=light'>" . LJ::Lang::ml( 'web.controlstrip.reloadpage.lightstyle' ) . "</a>"
         if $view eq "entry" || $view eq "reply" || $view eq "tag" || $view eq "month" || ( $view eq "lastn" && $uri =~ /\/tag/ );
 
     $ret .= "<td id='lj_controlstrip_search'>";
--------------------------------------------------------------------------------

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