about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-30 01:57:52 +0000
committerEric Wong <e@80x24.org>2016-05-30 01:57:52 +0000
commitfbcb7de93884b7915ea17906d112e1e8cb0dd490 (patch)
tree7d5b50d96f133827affb4808364358e121677828
parent1addae0198108a14cec9d3b306f5c51c70a5e053 (diff)
downloadpublic-inbox-fbcb7de93884b7915ea17906d112e1e8cb0dd490.tar.gz
Still a work in progress, but SearchView no longer depends
on Plack::Request at all and Feed is getting there.

We now parse all query parameters up front, but we may do
that lazily again in the future.
-rw-r--r--lib/PublicInbox/Feed.pm18
-rw-r--r--lib/PublicInbox/SearchView.pm14
-rw-r--r--lib/PublicInbox/WWW.pm16
3 files changed, 28 insertions, 20 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 81895dbf..07774cbf 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -140,8 +140,8 @@ sub emit_html_index {
 
         # if the 'r' query parameter is given, it is a legacy permalink
         # which we must continue supporting:
-        my $cgi = $ctx->{cgi};
-        if ($cgi && !$cgi->param('r') && $srch) {
+        my $qp = $ctx->{qp};
+        if ($qp && !$qp->{r} && $srch) {
                 $state->{srch} = $srch;
                 $last = PublicInbox::View::emit_index_topics($state);
                 $param = 'o';
@@ -149,7 +149,7 @@ sub emit_html_index {
                 $last = emit_index_nosrch($ctx, $state);
                 $param = 'r';
         }
-        $footer = nav_footer($cgi, $last, $feed_opts, $state, $param);
+        $footer = nav_footer($ctx, $last, $feed_opts, $state, $param);
         if ($footer) {
                 my $list_footer = $ctx->{footer};
                 $footer .= "\n\n" . $list_footer if $list_footer;
@@ -174,9 +174,9 @@ sub emit_index_nosrch {
 }
 
 sub nav_footer {
-        my ($cgi, $last, $feed_opts, $state, $param) = @_;
-        $cgi or return '';
-        my $old_r = $cgi->param($param);
+        my ($ctx, $last, $feed_opts, $state, $param) = @_;
+        my $qp = $ctx->{qp} or return '';
+        my $old_r = $qp->{$param};
         my $head = '    ';
         my $next = '    ';
         my $first = $state->{first};
@@ -186,7 +186,7 @@ sub nav_footer {
                 $next = qq!<a\nhref="?$param=$last"\nrel=next>next</a>!;
         }
         if ($old_r) {
-                $head = $cgi->path_info;
+                $head = $ctx->{env}->{PATH_INFO};
                 $head = qq!<a\nhref="$head">head</a>!;
         }
         my $atom = "<a\nhref=\"$feed_opts->{atomurl}\">Atom feed</a>";
@@ -200,11 +200,11 @@ sub each_recent_blob {
         my $addmsg = qr!^:000000 100644 \S+ \S+ A\t(${hex}{2}/${hex}{38})$!;
         my $delmsg = qr!^:100644 000000 \S+ \S+ D\t(${hex}{2}/${hex}{38})$!;
         my $refhex = qr/(?:HEAD|${hex}{4,40})(?:~\d+)?/;
-        my $cgi = $ctx->{cgi};
+        my $qp = $ctx->{qp};
 
         # revision ranges may be specified
         my $range = 'HEAD';
-        my $r = $cgi->param('r') if $cgi;
+        my $r = $qp->{r} if $qp;
         if ($r && ($r =~ /\A(?:$refhex\.\.)?$refhex\z/o)) {
                 $range = $r;
         }
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 0ae05052..2ec7ddf8 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -16,7 +16,7 @@ our $LIM = 50;
 
 sub sres_top_html {
         my ($ctx) = @_;
-        my $q = PublicInbox::SearchQuery->new($ctx->{cgi});
+        my $q = PublicInbox::SearchQuery->new($ctx->{qp});
         my $code = 200;
 
         # double the limit for expanded views:
@@ -260,13 +260,13 @@ use warnings;
 use PublicInbox::Hval;
 
 sub new {
-        my ($class, $cgi) = @_;
-        my $r = $cgi->param('r');
-        my ($off) = (($cgi->param('o') || '0') =~ /(\d+)/);
+        my ($class, $qp) = @_;
+
+        my $r = $qp->{r};
         bless {
-                q => $cgi->param('q'),
-                x => $cgi->param('x') || '',
-                o => $off,
+                q => $qp->{'q'},
+                x => $qp->{x} || '',
+                o => (($qp->{o} || '0') =~ /(\d+)/),
                 r => (defined $r && $r ne '0'),
         }, $class;
 }
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index a8202073..e211cd6d 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -40,7 +40,15 @@ sub run {
 sub call {
         my ($self, $env) = @_;
         my $cgi = Plack::Request->new($env);
-        my $ctx = {cgi => $cgi, pi_config => $self->{pi_config}, www => $self};
+        my $ctx = { cgi => $cgi, env => $env, www => $self,
+                pi_config => $self->{pi_config} };
+
+        # we don't care about multi-value
+        my %qp = map {
+                (split('=', $_, 2))
+        } split(/[&;]/, uri_unescape($env->{QUERY_STRING}));
+        $ctx->{qp} = \%qp;
+
         my $path_info = $env->{PATH_INFO};
         my $method = $env->{REQUEST_METHOD};
 
@@ -180,7 +188,7 @@ sub get_index {
         require PublicInbox::Feed;
         my $srch = searcher($ctx);
         footer($ctx);
-        if (defined $ctx->{cgi}->param('q')) {
+        if ($ctx->{env}->{QUERY_STRING} =~ /(?:\A|[&;])q=/) {
                 require PublicInbox::SearchView;
                 PublicInbox::SearchView::sres_top_html($ctx);
         } else {
@@ -262,7 +270,7 @@ sub footer {
         my $cgi = $ctx->{cgi};
         my $http = $cgi->base->as_string . $obj->{name};
         $seen{$http} or unshift @urls, $http;
-        my $ssoma_url = PublicInbox::Hval::prurl($cgi->{env}, SSOMA_URL);
+        my $ssoma_url = PublicInbox::Hval::prurl($ctx->{env}, SSOMA_URL);
         if (scalar(@urls) == 1) {
                 $urls = "URL for <a\nhref=\"" . $ssoma_url .
                         qq(">ssoma</a> or <b>git clone --mirror $urls[0]</b>);
@@ -394,7 +402,7 @@ sub r301 {
                 $obj = $ctx->{-inbox};
         }
         my $url = $obj->base_url($cgi);
-        my $qs = $cgi->env->{QUERY_STRING};
+        my $qs = $ctx->{env}->{QUERY_STRING};
         $url .= (uri_escape_utf8($mid) . '/') if (defined $mid);
         $url .= $suffix if (defined $suffix);
         $url .= "?$qs" if $qs ne '';