#!/usr/bin/perl -wT # # TWiki WikiClone (see TWiki.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-2000 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 # A thought on design. Information is passed to the preview script via various form variables. # Much of the meta data could have been passed by an extra hidden field, instead individual items such # as parent information is passed by individual form variables, hopefully giving a clear "API". use CGI::Carp qw(fatalsToBrowser); use CGI; use lib ( '.' ); use lib ( '../lib' ); use TWiki; use strict; use vars qw( $query ); $query = new CGI; my $TopicWeb = "Support"; my $TopicPrefix = "Call"; &main(); sub main { my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ) || ""; my $theUrl = $query->url; #SVEN $TopicPrefix = $query->param( 'topicprefix' ) || "MissingPrefix"; $theTopic = $TopicPrefix; my ($bugCount) = 0; $theTopic = $TopicPrefix.$bugCount; my( $lockUser, $lockTime ) = &TWiki::Store::topicIsLockedBy( $TopicWeb, $theTopic ); while ( (&TWiki::Store::topicExists( $TopicWeb, $theTopic )) || ( $lockUser ) ) { $bugCount = $bugCount + 1; $theTopic = $TopicPrefix.$bugCount; ( $lockUser, $lockTime ) = &TWiki::Store::topicIsLockedBy( $TopicWeb, $theTopic ); } #end SVEN my( $topic, $webName, $dummy, $userName ) = &TWiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl, $query ); $dummy = ""; # to suppress warning my $saveCmd = $query->param( 'cmd' ) || ""; my $breakLock = $query->param( 'breaklock' ) || ""; my $onlyWikiName = $query->param( 'onlywikiname' ) || ""; my $tmpl = ""; my $text = ""; my $meta = ""; my $extra = ""; my $wikiUserName = &TWiki::userToWikiName( $userName ); if( ! &TWiki::Store::webExists( $webName ) ) { my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsnoweb" ); TWiki::redirect( $query, $url ); return; } my( $mirrorSiteName, $mirrorViewURL ) = &TWiki::readOnlyMirrorWeb( $webName ); if( $mirrorSiteName ) { my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsmirror", $mirrorSiteName, $mirrorViewURL ); print $query->redirect( $url ); return; } # prevent non-Wiki names? if( ( $onlyWikiName ) && ( ! &TWiki::isWikiName( $topic ) ) && ( ! &TWiki::Store::topicExists( $webName, $topic ) ) ) { # do not allow non-wikinames, redirect to view topic TWiki::redirect( $query, &TWiki::getViewUrl( $webName, $topic ) ); return; } # read topic and check access permission if( &TWiki::Store::topicExists( $webName, $topic ) ) { ( $meta, $text ) = &TWiki::Store::readTopic( $webName, $topic ); } if( ! &TWiki::Access::checkAccessPermission( "change", $wikiUserName, $text, $topic, $webName ) ) { # user has not permission to change the topic my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsaccesschange" ); TWiki::redirect( $query, $url ); return; } if( ( $saveCmd ) && ( ! &TWiki::Access::userIsInGroup( $wikiUserName, $TWiki::superAdminGroup ) ) ) { # user has no permission to execute undocumented cmd=... parameter my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsaccessgroup", "$TWiki::mainWebname.$TWiki::superAdminGroup" ); TWiki::redirect( $query, $url ); return; } my( $lockUser, $lockTime ) = &TWiki::Store::topicIsLockedBy( $webName, $topic ); if( ( ! $breakLock ) && ( $lockUser ) ) { # warn user that other person is editing this topic $lockUser = &TWiki::userToWikiName( $lockUser ); use integer; $lockTime = ( $lockTime / 60 ) + 1; # convert to minutes my $editLock = $TWiki::editLockTime / 60; # PTh 20 Jun 2000: changed to getOopsUrl my $url = &TWiki::getOopsUrl( $webName, $topic, "oopslocked", $lockUser, $editLock, $lockTime ); TWiki::redirect( $query, $url ); return; } &TWiki::Store::lockTopic( $topic ); my $formTemplate = $query->param( "formtemplate" ) || ""; $formTemplate =~ /(.*)\//; $formTemplate = $1; # get edit template, standard or a different skin my $skin = $query->param( "skin" ) || &TWiki::Prefs::getPreferencesValue( "SKIN" ); $tmpl = &TWiki::Store::readTemplate( "edit", $skin ); if( ! &TWiki::Store::topicExists( $webName, $topic ) ) { my $templateTopic = $query->param( "templatetopic" ) || ""; if( $templateTopic ) { ( $meta, $text ) = &TWiki::Store::readTopic( $webName, $templateTopic ); } if( ! $text ) { ( $meta, $text ) = &TWiki::Store::readTemplateTopic( "WebTopicEditTemplate" ); } $extra = "(not exist)"; # If present, instantiate form if( ! $formTemplate ) { my %args = $meta->findOne( "FORM" ); $formTemplate = $args{"name"}; } my $foo = &TWiki::getLocaldate(); $text =~ s/%DATE%/$foo/go; $text =~ s/%WIKIUSERNAME%/$wikiUserName/go; } # parent setting my $theParent = $query->param( 'topicparent' ) || ""; if( $theParent ) { if( $theParent =~ /^([^.]+)\.([^.]+)$/ ) { my $parentWeb = $1; if( $1 eq $webName ) { $theParent = $2; } } $meta->put( "TOPICPARENT", ( "name" => $theParent ) ); } $tmpl =~ s/%TOPICPARENT%/$theParent/; #SVEN - want to be able to hide the textarea on FORMS. if ( $topic =~ /WebTopicEditTemplate/ ) { #allow FORM definition to be edited... } else { if (( $text =~ /HIDETEXTAREA/ )) { $tmpl =~ s/document.main.text(.*)//; $tmpl =~ s/