#!/usr/bin/perl -wTI. #!/usr/bin/perl -d:ptkdb sub BEGIN { $ENV{DISPLAY} = "ss:0.0"; } # # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # # Based on parts of Ward Cunninghams original Wiki and JosWiki. # Copyright (C) 1998 Markus Peter - SPiN GmbH (warpi@spin.de) # Some changes by Dave Harris (drh@bhresearch.co.uk) incorporated # Copyright (C) 1999 Peter Thoeny, peter@thoeny.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html use CGI; use wiki; $query= new CGI; ##### for debug only: Remove next 2 comments (but redirect does not work) #open(STDERR,'>&STDOUT'); # redirect error to browser #$| = 1; # no buffering &main(); sub main { my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ); my $theUrl = $query->url; ( $topic, $webName, $scriptUrlPath, $userName ) = &wiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl ); my $tmpl = ""; my $text = ""; my $rev = $query->param( "rev" ); my $maxrev = 1; my $extra = ""; my $wikiUserName = &wiki::userToWikiName( $userName ); if( ! &wiki::webExists( $webName ) ) { $tmpl= &wiki::readTemplate( "noweb" ); $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); print "Content-type: text/html\n\n"; print $tmpl; return; } my $unlock = $query->param( "unlock" ) || ""; if( $unlock eq "on" ) { # unlock topic, user cancelled out of edit &wiki::lockTopic( $topic, "on" ); } $tmpl= &wiki::readTemplate( "step", $topic ); if( ! $tmpl ) { print "Content-type: text/html\n\n"; print "
"; print "";
print "Check the \$templateDir variable in wikicfg.pm.";
print "";
return;
}
my $topicExists = &wiki::topicExists( $webName, $topic );
if( $topicExists ) {
$maxrev = &wiki::getRevisionNumber( $topic );
$maxrev =~ s/1\.//go; # cut major
if( $rev ) {
$rev =~ s/1\.//go; # cut major
if( $rev < 1 ) { $rev = 1; }
if( $rev > $maxrev ) { $rev = $maxrev; }
$text= &wiki::readVersion( $topic, "1.$rev" );
$extra .= "r1.$rev";
} else {
$text= &wiki::readTopic( $topic );
$rev= $maxrev;
}
} else {
$rev = 1;
if( &wiki::isWikiName( $topic ) ) {
$text= &wiki::readTemplate( "notext" );
} else {
$text= &wiki::readTemplate( "notwiki" );
}
$extra .= " (not exist)";
}
# commented out because not tested and not finished (protect also %INCLUDE% and search)
# # check access permission
# if( ! &wiki::checkAccessPermission( "view", $wikiUserName, $text, $topic, $webName ) ) {
# my $url = &wiki::getOopsUrl( $webName, $topic, "oopsaccessview" );
# print $query->redirect( $url );
# return;
# }
$text = &wiki::handleCommonTags( $text, $topic );
$text = &wiki::getRenderedVersion( $text );
if( $rev < $maxrev ) {
# disable edit of previous revisions
# $tmpl =~ s/%EDITTOPIC%/Edit/go;
# but allow to show the original text
$tmpl =~ s/%EDITTOPIC%/Show<\/B><\/A>/go;
$tmpl =~ s/%REVTITLE%/\(r1.$rev\)/go;
} else {
if( $topicExists ) {
$tmpl =~ s/%EDITTOPIC%/Edit<\/B><\/A>/go;
# remove the NOINDEX meta tag
$tmpl =~ s/]*>//goi;
} else {
$tmpl =~ s/%EDITTOPIC%/Create<\/B><\/A>/go;
}
$tmpl =~ s/%REVTITLE%//go;
}
my $i = $maxrev;
my $j = $maxrev;
my $revisions = "";
my $breakRev = 0;
if( ( $wiki::numberOfRevisions > 0 ) && ( $wiki::numberOfRevisions < $maxrev ) ) {
$breakRev = $maxrev - $wiki::numberOfRevisions + 1;
}
while( $i > 0 ) {
if( $i eq $rev) {
$revisions = "$revisions | r1.$i";
} else {
$revisions = "$revisions | r1.$i";
}
if( $i != 1 ) {
if( $i == $breakRev ) {
$revisions = "$revisions | >...";
$i = 1;
} else {
$j = $i - 1;
$revisions = "$revisions | >";
}
}
$i = $i - 1;
}
$tmpl =~ s/%REVISIONS%/$revisions/go;
if( $topicExists ) {
my( $date, $user ) = &wiki::getRevisionInfo( $topic, "1.$rev", 1 );
$user = &wiki::userToWikiName( $user );
my $temp = &wiki::getRenderedVersion( "r1.$rev - $date by $user" );
$tmpl =~ s/%REVINFO%/$temp/go;
} else {
$tmpl =~ s/%REVINFO%//go;
}
$tmpl = &wiki::handleCommonTags( $tmpl, $topic );
$tmpl =~ s/%TEXT%/$text/go;
$tmpl =~ s|*nop/*>||goi; # remove