]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
remove redundant NewsGroup class
[public-inbox.git] / lib / PublicInbox / WWW.pm
index 95288a7b4d99379224e8ee262dfac154183488c8..cf370afa750fd5c832ab29a661f1d58bc762252d 100644 (file)
@@ -14,7 +14,7 @@ use 5.008;
 use strict;
 use warnings;
 use Plack::Request;
-use PublicInbox::Config qw(try_cat);
+use PublicInbox::Config;
 use URI::Escape qw(uri_escape_utf8 uri_unescape);
 use constant SSOMA_URL => '//ssoma.public-inbox.org/';
 use constant PI_URL => '//public-inbox.org/';
@@ -23,6 +23,7 @@ use PublicInbox::GitHTTPBackend;
 our $INBOX_RE = qr!\A/([\w\.\-]+)!;
 our $MID_RE = qr!([^/]+)!;
 our $END_RE = qr!(T/|t/|R/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
+our $ATTACH_RE = qr!(\d[\.\d]*)-([[:alnum:]][\w\.-]+[[:alnum:]])!i;
 
 sub new {
        my ($class, $pi_config) = @_;
@@ -73,6 +74,10 @@ sub call {
        } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$END_RE\z!o) {
                msg_page($self, $ctx, $1, $2, $3);
 
+       } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$ATTACH_RE\z!o) {
+               my ($idx, $fn) = ($3, $4);
+               invalid_inbox_mid($self, $ctx, $1, $2) ||
+                       get_attach($ctx, $idx, $fn);
        # in case people leave off the trailing slash:
        } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/(T|t|R)\z!o) {
                my ($inbox, $mid, $suffix) = ($1, $2, $3);
@@ -102,7 +107,7 @@ sub preload {
 
        foreach (qw(PublicInbox::Search PublicInbox::SearchView
                        PublicInbox::Mbox IO::Compress::Gzip
-                       PublicInbox::NewsWWW PublicInbox::NewsGroup)) {
+                       PublicInbox::NewsWWW)) {
                eval "require $_;";
        }
 }
@@ -129,6 +134,8 @@ sub invalid_inbox {
        if (defined $obj) {
                $ctx->{git_dir} = $obj->{mainrepo};
                $ctx->{git} = $obj->git;
+               # for PublicInbox::HTTP::weaken_task:
+               $ctx->{cgi}->{env}->{'pi-httpd.inbox'} = $obj;
                $ctx->{-inbox} = $obj;
                $ctx->{inbox} = $inbox;
                return;
@@ -245,8 +252,6 @@ sub footer {
        my ($ctx) = @_;
        return '' unless $ctx;
        my $obj = $ctx->{-inbox} or return '';
-       my $footer = $obj->footer_html;
-       return $ctx->{footer} = $footer if $footer;
 
        # auto-generate a footer
        chomp(my $desc = $obj->description);
@@ -440,4 +445,10 @@ sub news_www {
        $self->{news_www} = PublicInbox::NewsWWW->new($self->{pi_config});
 }
 
+sub get_attach {
+       my ($ctx, $idx, $fn) = @_;
+       require PublicInbox::WwwAttach;
+       PublicInbox::WwwAttach::get_attach($ctx, $idx, $fn);
+}
+
 1;