diff -r 20aa57f413df README-show_thread.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README-show_thread.txt Thu Oct 22 18:28:53 2009 -0400 @@ -0,0 +1,25 @@ +This patch adds support to redirect to a thread given a file posted in it. +For example, if "1256239265762.jpg" is thread 38372, post 38411, requesting + will +redirect to (thus highlighting the +pertinent post). + + +The example.htaccess contains a RewriteRule to enable requests such as + to redirect internally to +wakaba.pl, so those interested only need to add "/thread" to an existing +image URL in order to jump to the thread where it was posted. + +If you prefer, you can also set up a single RewriteRule in a parent directory, +or even within httpd.conf. This works for any subdirectory nested to arbitrary +depth, so long as no other .htaccess files declare their own RewriteRules. +(This rule won't work if defined in the same directory as wakaba.pl.) + +RewriteRule ^(.*)/+(src/+[^/]+)/+thread/*$ $1/wakaba.pl?task=thread&filename=$2 [L] + + +For Lighttpd, make sure mod_rewrite is enabled in lighttpd.conf, and add the +following rule to your url.rewrite (or url.rewrite_once) list: + +"^(.*)/+(src/+[^/]+)/+thread/*$" => "$1/wakaba.pl?task=thread&filename=$2" + diff -r 20aa57f413df example.htaccess --- a/example.htaccess Thu Oct 22 17:28:57 2009 -0400 +++ b/example.htaccess Thu Oct 22 18:28:53 2009 -0400 @@ -22,4 +22,5 @@ RewriteEngine On RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml RewriteRule \.html$ - [T=application/xhtml+xml;charset=utf-8] +RewriteRule ^(src/+[^/]+)/+thread/*$ wakaba.pl?task=thread&filename=$1 [L] diff -r 20aa57f413df wakaba.pl --- a/wakaba.pl Thu Oct 22 17:28:57 2009 -0400 +++ b/wakaba.pl Thu Oct 22 18:28:53 2009 -0400 @@ -95,6 +95,11 @@ delete_stuff($password,$fileonly,$archive,$admin,@posts); } +elsif($task eq "thread") +{ + my $filename=$query->param("filename"); + show_thread($filename); +} elsif($task eq "admin") { my $password=$query->param("berra"); # lol obfuscation @@ -1231,6 +1236,27 @@ # +# Jump to thread from filename +# +sub show_thread($) +{ + my ($filename) = @_; + my ($sth, $num, $parent); + + $filename =~ s-/+-/-g; + $sth=$dbh->prepare("SELECT num,parent FROM ".SQL_TABLE." WHERE image=?;") or make_error(S_SQLFAIL); + $sth->execute($filename) or make_error(S_SQLFAIL); + ($num, $parent) = $sth->fetchrow_array(); + if ($num) { + make_http_forward(get_reply_link($num, $parent),ALTERNATE_REDIRECT); + } else { + make_error(S_NOTHREADERR); + } +} + + + +# # Admin interface #