#!/usr/bin/perl -wT -I. # # TWiki WikiClone (see $wikiversion in wiki.pm for version) # # 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@takefive.com , # TakeFive Software Inc. # # 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.ai.mit.edu/copyleft/gpl.html use CGI; use wiki; $query = new CGI; &main(); sub buildCategoryItem { my ( $catitems, $ctext ) = @_; my $catname = "", $scatname = "", $catmodifier = "", $catvalue = ""; my @cmd = split( /\|/, $catitems ); my $src = ""; my $len = @cmd; if( $len < "2" ) { return ( $catname, $catmodifier, $catvalue ) } # check for CategoryName=CategoryValue parameter my $cvalue = $query->param( $cmd[1] ); if( $cvalue ) { $src = "$cvalue"; } elsif( $ctext ) { foreach( split( /\n/, $ctext ) ) { if( /$cmd[1]/ ) { $src = $_; last; } } } if( $cmd[0] eq "select" ) { $catname = $cmd[1]; $scatname = $catname; $scatname =~ s/[^a-zA-z0-9]//g; my $size = $cmd[2]; $catvalue = ""; } elsif( $cmd[0] eq "checkbox" ) { $catname = $cmd[1]; $scatname = $catname; $scatname =~ s/[^a-zA-z0-9]//g; if( $cmd[2] eq "true" || $cmd[2] eq "1" ) { $i = $len - 4; $catmodifier = "$catmodifier\n "; $catmodifier = "$catmodifier\n "; } $itemsPerLine = $cmd[3]; $catvalue = "\n"; for( $i = 4; $i < $len; $i++ ) { my $value = $cmd[$i]; my $svalue = $value; $svalue =~ s/[^a-zA-z0-9]//g; my $flag = ""; if( $src =~ /$value[^a-zA-Z0-9\.]/ ) { $flag = "checked"; } $catvalue = "$catvalue\n"; if( ( $itemsPerLine > 0 ) && (($i-4) % $itemsPerLine == $itemsPerLine - 1 ) ) { $catvalue = "$catvalue\n"; } } $catvalue = "$catvalue\n
$value   
\n"; } elsif( $cmd[0] eq "radio" ) { $catname = $cmd[1]; $scatname = $catname; $scatname =~ s/[^a-zA-z0-9]//g; $itemsPerLine = $cmd[2]; $catvalue = "\n"; for( $i = 3; $i < $len; $i++ ) { my $value = $cmd[$i]; my $svalue = $value; $svalue =~ s/[^a-zA-z0-9]//g; my $flag = ""; if( $src =~ /$value[^a-zA-Z0-9\.]/ ) { $flag = "checked"; } elsif( ( $scatname eq "UseCategory" ) && ( ( $i == 3 && $ctext ) || ( $i == 4 && ! $ctext ) ) ) { $flag = "checked"; } $catvalue = "$catvalue\n"; if( ( $itemsPerLine > 0 ) && (($i-3) % $itemsPerLine == $itemsPerLine - 1 ) ) { $catvalue = "$catvalue\n"; } } $catvalue = "$catvalue\n
$value   
\n"; } elsif( $cmd[0] eq "text" ) { $catname = $cmd[1]; $scatname = $catname; $scatname =~ s/[^a-zA-z0-9]//g; $src =~ /(.*)/; if( $1 ) { $src = $1; } else { $src = ""; } $catvalue = ""; } return ( $catname, $catmodifier, $catvalue ) } sub main { my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ) || ""; my $theUrl = $query->url; # Makes creating a new topic more flexible by allowing you to specify a template to use. my $theCreateTemplate = $query->param( 'create' ) || ""; # Added by HaroldGottschalk ( $topic, $webName, $scriptUrlPath, $userName ) = &wiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl ); my $saveCmd = $query->param( 'cmd' ) || ""; my $breakLock = $query->param( 'breaklock' ) || ""; my $onlyWikiName = $query->param( 'onlywikiname' ) || ""; my $tmpl="", $tcat="", $icat="", $text=""; my $before="", $atext="", $ctext="", $after=""; my $catname="", $catmod="", $catvalue=""; my $extra = ""; my $scriptSuffix = $wiki::scriptSuffix; if( ! &wiki::webExists( $webName ) ) { print "Content-type: text/html\n\n"; $tmpl= &wiki::readTemplate( "noweb" ); $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); print $tmpl; return; } if( ( $onlyWikiName ) && ( ! &wiki::isWikiName( $topic ) ) && ( ! &wiki::topicExists( $webName, $topic ) ) ) { # do not allow non-wikinames, redirect to view topic print $query->redirect( "$scriptUrlPath/view$scriptSuffix/$webName/$topic" ); return; } my $lockUser = &wiki::topicIsLocked( $topic ); if( ( ! $breakLock ) && ( $lockUser ) ) { # warn user that other person is editing this topic $lockUser = &wiki::userToWikiName( $lockUser ); print $query->redirect( "$scriptUrlPath/oops$scriptSuffix/$webName/$topic?template=oopslocked¶m1=$lockUser" ); return; } &wiki::lockTopic( $topic ); print "Content-type: text/html\n\n"; $tmpl= &wiki::readTemplate( "edit" ); $icat= &wiki::readTemplate( "twikicatitems" ); if( &wiki::topicExists( $webName, $topic ) ) { $text= &wiki::readTopic($topic); } else { if(length($theCreateTemplate) == 0){ # Added by HaroldGottschalk # Default Template to use for new topic. $text= &wiki::readTemplate( "notedited" ); } else{ # Use Template specified by parm create $text= &wiki::readTemplate( $theCreateTemplate ); } # End Add by HaroldGottschalk $extra = "(not exist)"; my $foo = &wiki::getLocaldate(); $text =~ s/%DATE%/$foo/go; $foo = &wiki::userToWikiName( $userName ); $text =~ s/%USERNAME%/$foo/go; } if( $icat ) { # extract category section and build category form elements ( $before, $ctext, $after) = split( //, $text); # cut TWikiCat part $text = $before; if( ! $ctext ) { $ctext = ""; } if( $after ) { $text .= $after; } $tcat = &wiki::readTemplate( "twikicatedit" ); if( ! $tcat ) { $tcat = &wiki::readTemplate( "twikicatview" ); } my $line = "", $ttext = "", $temp = ""; ( $before, $line, $after) = split( /%REPEAT%/, $tcat ); foreach( split( /\n/, $icat ) ) { ( $catname, $catmod, $catvalue ) = buildCategoryItem( $_, $ctext ); if( $catname ) { $catname = &wiki::getRenderedVersion( $catname ); $temp = $line; $temp =~ s/%CATNAME%/$catname/go; $temp =~ s/%CATMODIFIER%/$catmodifier/go; $temp =~ s/%CATVALUE%/$catvalue/go; $ttext = "$ttext$temp"; } } $tcat = "$before$ttext$after"; } if( $saveCmd ne "repRev" ) { # cut attachment section if not in debug mode ( $before, $atext, $after) = split( //, $text ); $text = $before; if( $after ) { $text .= $after; } } $text =~ s/&/&\;/go; $text =~ s//>\;/go; $text =~ s/\t/ /go; if( $wiki::doLogTopicEdit ) { # write log entry &wiki::writeLog( "edit", "$webName.$topic", $extra ); } if( $saveCmd ) { $tmpl =~ s/\(edit\)/\(edit cmd=$saveCmd\)/go; } $tmpl =~ s/%CMD%/$saveCmd/go; $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); $tmpl =~ s/%TEXT%/$text/go; $tmpl =~ s/%TWIKICAT%/$tcat/go; print $tmpl; }