]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Add munge_url to Debbugs::CGI to abstract out code in _url methods
authorDon Armstrong <don@donarmstrong.com>
Fri, 15 Jun 2007 18:14:53 +0000 (19:14 +0100)
committerDon Armstrong <don@donarmstrong.com>
Fri, 15 Jun 2007 18:14:53 +0000 (19:14 +0100)
 * Add support for switching between version graphs

Debbugs/CGI.pm
cgi/version.cgi

index a9afdd9214ba53a3959e1b5d214522b23528137c..66637c091d9555689c66410ecea59e4234168cd6 100644 (file)
@@ -55,7 +55,7 @@ BEGIN{
      @EXPORT = ();
      %EXPORT_TAGS = (url    => [qw(bug_url bug_links bug_linklist maybelink),
                                qw(set_url_params pkg_url version_url),
-                               qw(submitterurl mainturl)
+                               qw(submitterurl mainturl munge_url)
                               ],
                     html   => [qw(html_escape htmlize_bugs htmlize_packagelinks),
                                qw(maybelink htmlize_addresslinks htmlize_maintlinks),
@@ -112,9 +112,7 @@ sub bug_url{
      else {
          %params = @_;
      }
-     my $url = Debbugs::URI->new('bugreport.cgi?');
-     $url->query_form(bug=>$ref,%params);
-     return $url->as_string;
+     return munge_url('bugreport.cgi?',%params,bug=>$ref);
 }
 
 sub pkg_url{
@@ -126,11 +124,27 @@ sub pkg_url{
      else {
          %params = @_;
      }
-     my $url = Debbugs::URI->new('pkgreport.cgi?');
-     $url->query_form(%params);
-     return $url->as_string;
+     return munge_url('pkgreport.cgi?',%params);
+}
+
+=head2 munge_url
+
+     my $url = munge_url($url,%params_to_munge);
+
+Munges a url, replacing parameters with %params_to_munge as appropriate.
+
+=cut
+
+sub munge_url {
+     my $url = shift;
+     my %params = @_;
+     my $new_url = Debbugs::URI->new($url);
+     %params = ($new_url->query_form(),%params);
+     $new_url->query_form(%params);
+     return $new_url->as_string;
 }
 
+
 =head2 version_url
 
      version_url($package,$found,$fixed)
@@ -147,7 +161,7 @@ sub version_url{
                      fixed   => $fixed,
                      (defined $width)?(width => $width):(),
                      (defined $height)?(height => $height):(),
-                     (defined $width or defined $height)?(collapse => 1):(),
+                     (defined $width or defined $height)?(collapse => 1):(info => 1),
                     );
      return $url->as_string;
 }
index 8d575ffbe948639e5679b60263b8debbfba52b05..b5967be6ef778f7a5c0af453698cba9a96caf0fc 100755 (executable)
@@ -17,7 +17,7 @@ use CGI::Simple;
 use CGI::Alert 'don@donarmstrong.com';
 
 use Debbugs::Config qw(:config);
-use Debbugs::CGI qw(htmlize_packagelinks html_escape cgi_parameters);
+use Debbugs::CGI qw(htmlize_packagelinks html_escape cgi_parameters munge_url);
 use Debbugs::Versions;
 use Debbugs::Versions::Dpkg;
 use Debbugs::Packages qw(getversions makesourceversions);
@@ -34,7 +34,7 @@ my %img_types = (svg => 'image/svg+xml',
 my $q = new CGI::Simple;
 
 my %cgi_var = cgi_parameters(query   => $q,
-                            single  => [qw(package format ignore_boring width height collapse)],
+                            single  => [qw(package format ignore_boring width height collapse info)],
                             default => {package       => 'spamass-milter',
                                         found         => [],
                                         fixed         => [],
@@ -43,8 +43,12 @@ my %cgi_var = cgi_parameters(query   => $q,
                                         format        => 'png',
                                         width         => undef,
                                         height        => undef,
+                                        info          => 0,
                                        },
                            );
+my $this = munge_url('version.cgi?',
+                    %cgi_var,
+                   );
 
 # we want to first load the appropriate file,
 # then figure out which versions are there in which architectures,
@@ -75,6 +79,28 @@ else {
      $cgi_var{format} = 'png';
 }
 
+if ($cgi_var{info} and not defined $cgi_var{dot}) {
+     print "Content-Type: text/html\n\n";
+     print <<END;
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head><title>$cgi_var{package} Version Graph</title></head>
+<body>
+END
+     print '<a href="'.html_escape(munge_url($this,ignore_boring=>$cgi_var{ignore_boring}?0:1)).
+         '">['.($cgi_var{ignore_boring}?"Don't i":'I').'gnore boring]</a> ';
+     print '<a href="'.html_escape(munge_url($this,collapse=>$cgi_var{collapse}?0:1)).
+         '">['.($cgi_var{collapse}?"Don't c":'C').'ollapse]</a> ';
+     print '<a href="'.html_escape(munge_url($this,dot=>1)).
+         '">[Dot]</a><br/>';
+     print '<img src="'.html_escape(munge_url($this,info=>0)).'">';
+     print <<END;
+</body>
+</html>
+END
+         exit 0;
+}
+
 # then figure out which are affected.
 # turn found and fixed into full versions
 @{$cgi_var{found}} = makesourceversions($cgi_var{package},undef,@{$cgi_var{found}});