| 1 | # PurpleWiki::Apache2Handler.pm | ||
| 2 | # vi:ai:sw=4:ts=4:et:sm | ||
| 3 | # | ||
| 4 | # $Id: Apache2Handler.pm 463 2004-08-09 01:31:48Z cdent $ | ||
| 5 | # | ||
| 6 | # Copyright (c) Blue Oxen Associates 2002-2003. All rights reserved. | ||
| 7 | # | ||
| 8 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||
| 9 | # | ||
| 10 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||
| 11 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||
| 12 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||
| 13 | # The Original WikiWikiWeb (c) Ward Cunningham | ||
| 14 | # | ||
| 15 | # PurpleWiki is free software; you can redistribute it and/or modify | ||
| 16 | # it under the terms of the GNU General Public License as published by | ||
| 17 | # the Free Software Foundation; either version 2 of the License, or | ||
| 18 | # (at your option) any later version. | ||
| 19 | # | ||
| 20 | # This program is distributed in the hope that it will be useful, | ||
| 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | # GNU General Public License for more details. | ||
| 24 | # | ||
| 25 | # You should have received a copy of the GNU General Public License | ||
| 26 | # along with this program; if not, write to the | ||
| 27 | # Free Software Foundation, Inc. | ||
| 28 | # 59 Temple Place, Suite 330 | ||
| 29 | # Boston, MA 02111-1307 USA | ||
| 30 | |||
| 31 | package PurpleWiki::Apache2Handler; | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use IO::File; | ||
| 35 | use PurpleWiki::Config; | ||
| 36 | use PurpleWiki::Parser::WikiText; | ||
| 37 | use Apache::RequestRec (); | ||
| 38 | use Apache::RequestIO (); | ||
| 39 | use Apache::URI; | ||
| 40 | use Apache::Const -compile => qw(OK); | ||
| 41 | |||
| 42 | our $VERSION; | ||
| 43 | $VERSION = sprintf("%d", q$Id: Apache2Handler.pm 463 2004-08-09 01:31:48Z cdent $ =~ /\s(\d+)\s/); | ||
| 44 | |||
| 45 | sub handler { | ||
| 46 | my $r = shift; | ||
| 47 | |||
| 48 | $r->content_type('text/html'); | ||
| 49 | |||
| 50 | my $file = $r->filename(); | ||
| 51 | my $url = $r->construct_url(); | ||
| 52 | |||
| 53 | my $content = readFile($file); | ||
| 54 | my $CONFIG = $ENV{WIKIDB}; | ||
| 55 | my $purpleConfig = new PurpleWiki::Config($CONFIG); | ||
| 56 | my $wikiParser = new PurpleWiki::Parser::WikiText(); | ||
| 57 | my $wiki = $wikiParser->parse($content, | ||
| 58 | wikiword => 1, | ||
| 59 | url => $url, | ||
| 60 | ); | ||
| 61 | |||
| 62 | # select and load a template driver | ||
| 63 | my $templateDriver = $purpleConfig->TemplateDriver(); | ||
| 64 | my $templateClass = "PurpleWiki::Template::$templateDriver"; | ||
| 65 | eval "require $templateClass"; | ||
| 66 | my $wikiTemplate = $templateClass->new; | ||
| 67 | |||
| 68 | $wikiTemplate->vars( body => $wiki->view('wikihtml', | ||
| 69 | wikiword => 1, | ||
| 70 | url => $url), | ||
| 71 | title => $wiki->title, | ||
| 72 | date => $wiki->date ); | ||
| 73 | $r->print($wikiTemplate->process('handler')); | ||
| 74 | |||
| 75 | # FIXME: sometimes okay is not the desired return code | ||
| 76 | return Apache::OK; | ||
| 77 | |||
| 78 | } | ||
| 79 | |||
| 80 | sub readFile { | ||
| 81 | my $file = shift; | ||
| 82 | my $fileContent = ''; | ||
| 83 | |||
| 84 | my $fh = new IO::File(); | ||
| 85 | $fh->open($file) || die "unable to open $file: $!"; | ||
| 86 | return join('', $fh->getlines); | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | 1; | ||
| 92 | |||
| 93 | |||
| 94 | __END__ |