Skip to content

Commit

Permalink
Item514: magically map /pub URL requests and topic view requests to t…
Browse files Browse the repository at this point in the history
…he right place

git-svn-id: http://svn.foswiki.org/trunk@1451 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Dec 18, 2008
1 parent 8b0b857 commit ee528da
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
Expand Up @@ -8,11 +8,19 @@ One line description, required for extensions repository catalog.
%TOC%

---++ Usage
Automaticalle maps requests for legacy TWiki web topics to Foswiki free topics as per
Automatically maps requests for legacy TWiki web topics to Foswiki free topics as per
[[http://foswiki.org/Development/TopicNameMappingTable][TopicNameMappingTable]].

Map TWIKIWEB to SYSTEMWEB and MAINWEB to USERSWEB - no Preference settings required.

to add similar auto-compatibility for attachments, add (or uncomment) the following ErrorDocument handeling to
your Apache configuration _in the =pub= section_

<verbatim>
#for TWikiCompatibility
ErrorDocument 404 /foswiki/bin/viewfile
</verbatim

---+++ TODO:
1 pub file redirection - will probably have to be a final regex in postRendering

Expand Down
Expand Up @@ -92,4 +92,46 @@ sub earlyInitPlugin {
return;
}

=pod
---++ postRenderingHandler( $text )
* =$text= - the text that has just been rendered. May be modified in place.
using the same simplistic mechanism as DistributedServersPlugin, we fins all
the System and TWiki web pub URL's and make sure they actually exist. If not,
we look in the 'other' place, and modify them if that file does exist.
* TODO: should really protect non-HTML src type url's from re-writing
=cut

sub NOT_postRenderingHandler {
# do not uncomment, use $_[0], $_[1]... instead
#my $text = shift;

# remove duplicated hostPath's
#my $hostUrl = TWiki::Func::getUrlHost( );
#$_[0] =~ s|($hostUrl)($hostUrl)|$1|g;

# $_[0] =~ s/(.*)($Foswiki::cfg{PubUrlPath}\/)(TWiki|$Foswiki::cfg{SystemWebName})([^"']*)/$1.validatePubURL($2, $3, $4)/ge;
$_[0] =~ s/(.*)($Foswiki::cfg{PubUrlPath}\/)([^"'\/]*)([^"'<]*)/$1.validatePubURL($2, $3, $4, $1)/gem;
}

sub validatePubURL {
my ($pubUrl, $web, $file) = @_;
print STDERR "validatePubURL($pubUrl, $web, $file)\n";
my %map = ('TWiki' => $Foswiki::cfg{SystemWebName},
$Foswiki::cfg{SystemWebName} => 'TWiki');

#TODO: make into a hash - and see if we can persist it for fastcgi etc..
my $filePath = $Foswiki::cfg{PubDir}.'/'.$web.$file;
unless (-e $filePath) {
$web = $map{$web};
$filePath = $Foswiki::cfg{PubDir}.'/'.$web.$file;
unless (-e $filePath) {
print STDERR " validatePubURL($pubUrl, $web, $file) ($filePath) - can't find file ine either $map{$web} or $web\n";
}
}
return $pubUrl.$web.$file;
}

1;
3 changes: 3 additions & 0 deletions core/foswiki_httpd_conf.txt
Expand Up @@ -130,6 +130,9 @@ BrowserMatchNoCase ^$ blockAccess

# This line will redefine the mime type for the most common types of scripts
AddType text/plain .shtml .php .php3 .phtml .phtm .pl .py .cgi

#for TWikiCompatibility - or even to make 'attachment not found's more user friendly
ErrorDocument 404 /foswiki/bin/viewfile
</Directory>

# Security note: All other directories should be set so
Expand Down
38 changes: 31 additions & 7 deletions core/lib/Foswiki/UI/View.pm
Expand Up @@ -64,6 +64,21 @@ sub view {
my $rev = $store->cleanUpRevID( $query->param('rev') );

my $topicExists = $store->topicExists( $webName, $topicName );
if (!$topicExists
&& $Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{Enabled}
&& (
$webName eq $Foswiki::cfg{SystemWebName}
|| $webName eq 'TWiki'
)) {
#try the other web (TWikiCompatibility)
my %map = ('TWiki' => $Foswiki::cfg{SystemWebName},
$Foswiki::cfg{SystemWebName} => 'TWiki');
if ($topicExists = $session->{store}->topicExists( $map{$webName}, $topicName )) {
$webName = $map{$webName};
$session->{webName} = $webName;
print STDERR 'BINGO';
}
}

# text and meta of the _latest_ rev of the topic
my ( $currText, $currMeta );
Expand Down Expand Up @@ -481,13 +496,22 @@ sub viewfile {
unless ( $fileName
&& $session->{store}->attachmentExists( $webName, $topic, $fileName ) )
{
throw Foswiki::OopsException(
'attention',
def => 'no_such_attachment',
web => $webName,
topic => $topic,
params => [ 'viewfile', $fileName || '?' ]
);
#try the other web (TWikiCompatibility)
my %map = ('TWiki' => $Foswiki::cfg{SystemWebName},
$Foswiki::cfg{SystemWebName} => 'TWiki');
if ($Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{Enabled}
&& $session->{store}->attachmentExists( $map{$webName}, $topic, $fileName )) {
$webName = $map{$webName};
} else {
throw Foswiki::OopsException(
'attention',
def => 'no_such_attachment',
web => $webName,
topic => $topic,
status => 404,
params => [ 'viewfile', $fileName || '?' ]
);
}
}

# TSA SMELL: Maybe could be less memory hungry if get a file handle
Expand Down
3 changes: 3 additions & 0 deletions core/pub-htaccess.txt
Expand Up @@ -37,6 +37,9 @@ php_flag engine off
# This line will redefine the mime type for the most common types of scripts
AddType text/plain .shtml .php .php3 .phtml .phtm .pl .py .cgi

#for TWikiCompatibility - or even to make 'attachment not found's more user friendly
ErrorDocument 404 /foswiki/bin/viewfile

#add an Expires header that is sufficiently in the future that the browser does not even ask if its uptodate
# reducing the load on the server significantly
#IF you can, you should enable this - it _will_ improve your foswiki experience, even if you set it to under one day.
Expand Down

0 comments on commit ee528da

Please sign in to comment.