I'm trying to run Kwiki from inside Mason/ModPerl/Apache.
The file below does a fine job of displaying Kwiki pages inside Mason, but
clicking on links seems to take me to a random Kwiki page. Most of this code
is taken from Kwiki::ModPerl. I'm sure this post in itself will cause more
questions, so where do I go from here?
Paul...
<%once>
use Kwiki;
use DBA::Constants;
BEGIN {
eval { require mod_perl2 } || require mod_perl;
if ( $mod_perl::VERSION >= 1.999021 ) {
require Apache2::RequestRec;
require Apache2::RequestUtil;
require Apache2::RequestIO;
require Apache2::Const;
Apache2::Const->import qw(:common);
} else {
if ( $mod_perl::VERSION >= 1.99 ) {
require Apache::RequestRec;
require Apache::RequestUtil;
require Apache::RequestIO;
require Apache::Const;
Apache::Const->import qw(:common);
} else {
require Apache;
require Apache::Constants;
Apache::Constants->import( qw/:response :common/);
}
}
}
chdir qq{$CONSTANTS{FILE_BASE}/code/mason/masonkwiki} or die "couldn't chdir:
$!\n";
my $hub = Kwiki->new->debug->load_hub(qw(config*.*[!~] -plugins plugins)); $hub
-> load_class('pages');
</%once>
<%shared>
my($head) = "";
my($title) = "KWIKI";
$title="init";
my($page) = 'HomePage';
eval { $hub->pre_process }
or print_error($@,$r,$hub,'Pre-Process Error');
my($html) = eval { $hub->process };
if ($@){
print_error($@,$r,$hub,'Process Error');
} else {
if (defined $html) {
$hub->headers->print;
unless($r->header_only) {
# $m->print($html);
}
}
eval { $hub->post_process }
or print_error($@,$r,$hub,'Post-Process Error');
}
# Strip XHTML declare
$html =~ s/<\![^>]*>//;
$html =~ s/.*?<head>(.*)<\/head>.*?<body>(.*?)<\/body>/$2/s;
$head = $1;
if ($head =~ s/<title>([^<]*)<\/title>//m) {
$title = $1;
}
$head =~ s/(href=")([^\/h])/$1masonkwiki\/$2/g;
$head =~ s/(src=")([^\/h])/$1masonkwiki\/$2/g;
$head =~ s(masonkwiki/index.cgi) (masonkwiki/index.html)g;
sub print_error {
my $error = shift;
my ($r,$hub,$msg) = @_;
$hub->headers->content_type('text/html');
$hub->headers->charset('UTF-8');
$hub->headers->expires('now');
$hub->headers->pragma('no-cache');
$hub->headers->cache_control('no-cache');
$hub->headers->redirect('');
$hub->headers->print;
$r->print("<h1>Software Error:</h1><h2>$msg</h2><pre>\n$error</pre>");
return;
}
</%shared>
<%init>
$html =~ s/(href=")([^\/h])/$1masonkwiki\/$2/g;
$html =~ s/(src=")([^\/h])/$1masonkwiki\/$2/g;
$html =~ s(masonkwiki/index.cgi) (masonkwiki/index.html)g;
</%init>
%#<% $title |h%><br />
%#head::<% $head |h%>::head<br /><br /><br />
<% $html %>
<%method headers><!-- Kwiki head start -->
<% $head %>
<!-- Kwiki head end -->
</%method>
<%method title><% $title %></%method>