diff -r 7bc60a767fa4 .hgtags --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgtags Wed Sep 24 23:51:17 2008 +0200 @@ -0,0 +1,3 @@ +e59589baefff98a6188067ee88415f48676ea8b9 r2 +3158699ed3228e6fcefb9786714bb0450b4dc06d r3 +edf81cd91586dcd25a030bce86a8bd0d6fec3e4c r4 diff -r 7bc60a767fa4 lib/TWiki.pm --- a/lib/TWiki.pm Mon Aug 11 20:33:37 2008 +0200 +++ b/lib/TWiki.pm Wed Sep 24 23:51:17 2008 +0200 @@ -1051,8 +1051,9 @@ sub getScriptUrl { my $url; if( defined $TWiki::cfg{ScriptUrlPaths} && $script) { $url = $TWiki::cfg{ScriptUrlPaths}{$script}; - } - unless( defined( $url )) { + } elsif ($TWiki::cfg{ShortURLs} && $script eq "view") { + $url = ''; + } else { $url = $TWiki::cfg{ScriptUrlPath}; if( $script ) { $url .= '/' unless $url =~ /\/$/; @@ -1072,7 +1073,27 @@ sub getScriptUrl { ( $web, $topic ) = $this->normalizeWebTopicName( $web, $topic ); - $url .= urlEncode( '/'.$web.'/'.$topic ); +# START SHORTURLs +# see http://twiki.org/cgi-bin/view/TWiki/ShorterUrlCookbook +# needs $TWiki::cfg{HomeWebName} +# see http://twiki.org/cgi-bin/view/Codev/CreateHomeWebVariable + if ($TWiki::cfg{ShortURLs} && $script eq "view") { + my $topicUrl; + if ($topic eq $TWiki::cfg{HomeTopicName}) { + $topicUrl = ''; + } else { + $topicUrl = $topic; + } + if(defined($TWiki::cfg{HomeWebName}) + && $web eq $TWiki::cfg{HomeWebName}) { + $url .= urlEncode( '/'.$topicUrl ); + } else { + $url .= urlEncode( '/'.$web.'/'.$topicUrl ); + } + } else { + $url .= urlEncode( '/'.$web.'/'.$topic ); + } +# END SHORTURLs $url .= _make_params(0, @params); } diff -r 7bc60a767fa4 lib/TWiki.spec --- a/lib/TWiki.spec Mon Aug 11 20:33:37 2008 +0200 +++ b/lib/TWiki.spec Wed Sep 24 23:51:17 2008 +0200 @@ -153,6 +153,15 @@ my $OS = $TWiki::cfg{OS} || ''; # verification. # # $TWiki::cfg{WorkingDir} = '/home/httpd/twiki/working'; + +# **BOOLEAN** +# Do we use short URLs? i.e. use http://my.host/Web/Topic instead of +# http://my.host/bin/view/Web/Topic. +# If you enable this, you *MUST* also edit your web server config, +# to set up Rewrite Rules. +# See http://twiki.org/cgi-bin/view/Codev/ShorterUrlSupport +# for detailed instructions +$TWiki::cfg{ShortURLs} = 0; # **STRING 10** # Suffix of TWiki CGI scripts (e.g. .cgi or .pl). You may need to set this diff -r 7bc60a767fa4 lib/TWiki/UI/View.pm --- a/lib/TWiki/UI/View.pm Mon Aug 11 20:33:37 2008 +0200 +++ b/lib/TWiki/UI/View.pm Wed Sep 24 23:51:17 2008 +0200 @@ -91,10 +91,28 @@ sub view { my $topicExists = $store->topicExists( $webName, $topicName ); + # Detect if we were given only the web name without the trailing / + # then redirect to the proper Web/WebHome URL + if( !$topicExists ) { + my $subwebName = $webName.'/'.$topicName; + if( $session->{store}->webExists( $subwebName ) ) { + $session->redirect($session->getScriptUrl( 1, 'view', + $subwebName, $TWiki::cfg{HomeTopicName} ), undef, 1 ); + } elsif (defined($TWiki::cfg{HomeWebName}) && + $webName eq $TWiki::cfg{HomeWebName}) { + $subwebName = $topicName; + if( $session->{store}->webExists( $subwebName ) ) { + $session->redirect($session->getScriptUrl( 1, 'view', + $subwebName, $TWiki::cfg{HomeTopicName} ), undef, 1 ); + } + } + } + # text and meta of the _latest_ rev of the topic my( $currText, $currMeta ); # text and meta of the chosen rev of the topic my( $meta, $text ); + if( $topicExists ) { require TWiki::Time; ( $currMeta, $currText ) = $store->readTopic