From 1f78c2b077fafc6538c56ec7ad566ae869ae6743 Mon Sep 17 00:00:00 2001 From: Jukka Raimovaara Date: Sun, 30 Apr 2006 13:07:00 +0000 Subject: [PATCH] Added internal redirect (Is there a way to get content_type that wouldn't require File::MMagic?) Apache2::SubRequest's method lookup_file coused segfault in apache, so I scrapped that and used File::MMagic to to content type determing Also fixed credit and added a currentPage.rankIsN variable to navigation --- docs/changelog/6.x.x.txt | 7 ++++--- docs/credits.txt | 2 +- etc/WebGUI.conf.original | 5 +++++ lib/WebGUI.pm | 16 ++++++++++++++ lib/WebGUI/Asset/File.pm | 2 ++ lib/WebGUI/Asset/File/Image.pm | 1 + lib/WebGUI/Asset/Wobject/Navigation.pm | 1 + lib/WebGUI/Session/Http.pm | 29 +++++++++++++++++++++++++- 8 files changed, 58 insertions(+), 5 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 8f7bd2265..e3ec3d9b2 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -48,9 +48,10 @@ - Added a User form field type. - Added a symbol next to items in the asset manager to indicate if they have children or not. - - Added more templating options to the Paginator thanks to Jukka Raimovaara. - - Added the currentPage.rank variable to the nav template thanks to Jukka - Raimovaara. + - Added more templating options to the Paginator. (thanks to Jukka Raimovaara + / Axxion Oy) + - Added the currentPage.rank and currentPage.rankIsN variable to the nav + template. (thanks to Jukka Raimovaara / Axxion Oy) - Added a screenshot feature to the matrix. - Added an option to delete Matrix fields. - Added an API for retrieving email from POP3 servers. diff --git a/docs/credits.txt b/docs/credits.txt index 3c4442ecf..4c9847bc9 100644 --- a/docs/credits.txt +++ b/docs/credits.txt @@ -36,7 +36,7 @@ Contributing Developers..............Peter Beardsley / Appropriate Solutions Tony Mountifield Tavis Parker / ParkerOne Consulting Daniel Quinlan - Jukka Raimovaara + Jukka Raimovaara / Axxion Oy Alan Ritari / DonorWare Hal Roberts / Harvard Steve Simms diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 2b6b7265d..e7265fed2 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -237,6 +237,11 @@ "soapHttpHeaderOverride" : 0, +# Enable streaming Image and File assets thru mod_perl process instead of +# simple redirect. WARNING has impact on performance. + +"enableStreamingUploads" : "0", + # Specify the list of macros you wish to be processed on each page. "macros" : { diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 9a7d304ad..d5937b5c8 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -29,6 +29,7 @@ use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK DECLINED NOT_FOUND DIR_MAGIC_TYPE); use Apache2::ServerUtil (); +use File::MMagic; #------------------------------------------------------------------- @@ -104,6 +105,21 @@ sub contentHandler { $output = page($session); } $session->http->setCookie("wgSession",$session->var->{_var}{sessionId}) unless $session->var->{_var}{sessionId} eq $session->http->getCookies->{"wgSession"}; + my $filename = $session->http->getStreamedFile(); +# print STDERR "file $filename and setting ".$session->config->get("enableStreamingUploads")."!\n"; + if ((defined $filename) && ($session->config->get("enableStreamingUploads") eq "1")) { + #my $subr = $r->lookup_file($filename,$r->output_filters); + my $mm = new File::MMagic; + my $ct = $mm->checktype_filename($filename); + my $oldContentType = $r->content_type($ct); +# print STDERR "contenttype ".$r->content_type()."!\n"; + if ($r->sendfile($filename) ) { + return Apache2::Const::OK(); + } else { + $r->content_type($oldContentType); + } + } + $session->http->sendHeader(); unless ($session->http->isRedirect()) { $session->output->print($output); diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index e2997c6b1..b9d9182da 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -171,6 +171,7 @@ sub getEditForm { #------------------------------------------------------------------- sub getFileUrl { my $self = shift; + #return $self->get("url"); return $self->getStorageLocation->getUrl($self->get("filename")); } @@ -373,6 +374,7 @@ sub www_view { return $self->getContainer->www_view; } $self->session->http->setRedirect($self->getFileUrl); + $self->session->http->setStreamedFile($self->getStorageLocation->getPath($self->get("filename"))); return '1'; } diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index 2b4fcfe9e..3ba55f60d 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -312,6 +312,7 @@ sub www_view { } my $storage = $self->getStorageLocation; $self->session->http->setRedirect($storage->getUrl($self->get("filename"))); + $self->session->http->setStreamedFile($storage->getPath($self->get("filename"))); return "1"; } diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index 3b3869845..76db6a4d5 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -362,6 +362,7 @@ sub view { $var->{'currentPage.url'} = $current->getUrl; $var->{'currentPage.hasChild'} = $current->hasChildren; $var->{'currentPage.rank'} = $current->getRank; + $var->{'currentPage.rankIs'.$current->getRank} = 1; my $currentLineage = $current->get("lineage"); my $lineageToSkip = "noskip"; my $absoluteDepthOfLastPage; diff --git a/lib/WebGUI/Session/Http.pm b/lib/WebGUI/Session/Http.pm index 6b43ed899..644b00abe 100644 --- a/lib/WebGUI/Session/Http.pm +++ b/lib/WebGUI/Session/Http.pm @@ -101,7 +101,6 @@ sub getMimeType { return $self->{_http}{mimetype} || "text/html"; } - #------------------------------------------------------------------- =head2 getStatus ( ) { @@ -117,6 +116,20 @@ sub getStatus { } +#------------------------------------------------------------------- + +=head2 getStreamedFile ( ) { + +Returns the location of a file to be streamed thru mod_perl, if one has been set. + +=cut + +sub getStreamedFile { + my $self = shift; + return $self->{_http}{streamlocation} || undef; +} + + #------------------------------------------------------------------- =head2 isRedirect ( ) @@ -377,5 +390,19 @@ sub setStatus { $self->{_http}{statusDescription} = shift; } +#------------------------------------------------------------------- + +=head2 setStreamedFile ( ) { + +Set a file to be streamed thru mod_perl. + +=cut + +sub setStreamedFile { + my $self = shift; + $self->{_http}{streamlocation} = shift; +} + + 1;