#!perl # # TWiki WikiClone (see $wikiversion in wiki.pm for version) # # Copyright (C) 1999 Peter Thoeny, peter.thoeny@ibm.net # # 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; ##### for debug only: Remove next 3 comments (but redirect does not work) #open(STDERR,'>&STDOUT'); # redirect error to browser #$| = 1; # no buffering #print "Content-type: text/html\n\n"; #print "Hello there"; &main(); sub main { # get all parameters from the form my @paramNames = $query->param(); @formDataName = (); @formDataValue = (); @formDataRequired = (); my $name = ""; my $value = ""; my $topicName = ""; # the name of the template page my $wikiName = ""; # the new pages' name foreach( @paramNames ) { # print "$_"; $name = $_; # $name =~ s/([a-z0-9])([A-Z0-9])/$1 $2/go; $value = $query->param( "$name" ); # $formDataRequired[@formDataRequired] = $2; print "($name = $value)"; $formDataName[@formDataName] = $name; $formDataValue[@formDataValue] = $value; if( $name eq "NewPageName" ) { $wikiName = $value; } elsif( $name eq "TemplateTopic" ) { $topicName = $value; } } print "
\n"; my $formLen = @formDataValue; my $thePathInfo = $query->path_info(); my $theUrl = $query->url; ( $topic, $webName, $scriptUrlPath ) = &wiki::initialize( $thePathInfo, $wikiName, $topicName, $theUrl ); my $text = ""; my $scriptSuffix = $wiki::scriptSuffix; # check if user entry already exists #SVEN - if topic exists, need to append this stuff to that topic # if ( ( $wikiName ) && # ( &wiki::topicExists( $webName, $wikiName ) ) # ) # { # print "$wikiName exists..."; # print $query->redirect( "$scriptUrlPath/oops$scriptSuffix/$webName/$topic?template=oopsregexist¶m1=$wikiName" ); # return; # } # check if required fields are filled in # my $x; # for( $x = 0; $x < $formLen; $x++ ) { # if( ( $formDataRequired[$x] ) && ( ! $formDataValue[$x] ) ) { # print $query->redirect( "$scriptUrlPath/oops$scriptSuffix/$webName/$topic?template=oopsregrequ" ); # return; # } # } # check if wikiName is a WikiName if( ! &wiki::isWikiName( $wikiName ) ) { print "$wikiName not a wikiName"; # print $query->redirect( "$scriptUrlPath/oops$scriptSuffix/$webName/$topic?template=oopsregwiki" ); return; } # a WikiName is safe, so untaint variable $wikiName =~ /(.*)/; $wikiName = $1; # everything OK # create user topic if not exist # if( ! &wiki::topicExists( $wiki::mainWebname, $wikiName ) ) { $text = &wiki::readTopic( $topicName ); # the template page $text =~ s/]*)>//goi; $text =~ s/<\/form>//goi; #for these to work at the moment the entire element's markup must be on one line :( $text =~ s//&replaceInput($1, @formDataName, @formDataValue, @formDataRequired)/geoi; $text =~ s/<\/textarea\>/&replaceInput($1, @formDataName, @formDataValue, @formDataRequired)/geoi; $text =~ s//&replaceInput($1, @formDataName, @formDataValue, @formDataRequired)/geoi; # print "$text"; # for( $x = 0; $x < $formLen; $x++ ) { # print "($formDataName[$x] = $formDataValue[$x])\n"; # } &wiki::saveTopic( $wikiName, $text, "" ); } print $query->redirect( &wiki::viewUrl( $wikiName ) ); # and finally display thank you page #print $query->redirect( "$wiki::urlHost$scriptUrlPath/oops$scriptSuffix/$webName/$wikiName?template=oopsregthanks¶m1=$emailAddress" ); } sub replaceInput { my ($inputString) = @_; #, @formDataName, @formDataValue, @formDataRequired) = @_; my $formLen = @formDataValue; my $inputName = ""; my $name = ""; my $test = ""; if ( $inputString =~ /type=\"submit\"/i ) # submit button { return ""; } if ( $inputString =~ /name=\"NewPageName\"/i ) #NewpageName { return ""; } if ( $inputString =~ /name=\"TemplateTopic\"/i ) #TemplateTopic { return ""; } if ( $inputString =~ /name=\"([a-zA-Z0-9]*)\"/i ) { $inputName = $1; for( $x = 0; $x < $formLen; $x++ ) { $name = $formDataName[$x]; if ( $name eq $inputName ) { return $formDataValue[$x]; } #$test .= "|$name"; } } return "*INPUT without name?($inputName$name|)($inputString)*"; }