#!/usr/bin/perl -wTI. # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # # Copyright (C) 1999-2000 Peter Thoeny, peter@thoeny.com # # attach perl code was canablized for this code use CGI; use wiki; use Time::Local; $query = new CGI; #open(STDERR,'>&STDOUT'); # redirect error to browser $| = 1; # no buffering &main(); sub main { # check whether we need to present confirmation page # or final page by checking for form data my $delRequest = $query->param( 'delreq' ); my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ); my $theUrl = $query->url; my $tmpl = ""; ( $topic, $webName, $dummy, $userName ) = &wiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl ); $dummy = ""; # to suppress warning if ($delRequest eq "conf") { my $delText = "
\nNote: The deleted page and refering page may still be cached by your browser and may display when hitting the 'back' button. This will be addressed soon.\n
\nThe delete feature is currently undergoing additional work to improve its usability and safety."; 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; } # check access permission if( ! &wiki::checkAccessPermission( "change", $wikiUserName, "", $topic, $webName ) ) { my $url = &wiki::getOopsUrl( $webName, $topic, "oopsaccesschange" ); print $query->redirect( $url ); return; } # ------------------------------------------------ # test to see if appropriate directory structure exists for storing # deleted topics for the current web my $delDir = &wiki::getDelDir(); if ( ! -e "$delDir/$webName" ) # no topic from this web ever deleted # create base directories { # better make sure that the $deletedPath is set right... if ( ! -e $delDir ) { $tmpl= &wiki::readTemplate( "oopsdeltopic" ); $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); $tmpl =~ s/%DP%/$delDir/go; print "Content-type: text/html\n\n"; print $tmpl; return; } else { # need to set up directory structure for this web # Create $deletedPath/%WEB% my $delDir = &wiki::getDelDir(); my $tempPath = "$delDir/$webName"; if( ! -e "$tempPath" ) { umask( 0 ); mkdir( $tempPath, 0777 ); } # Create $deletedPath/%WEB%/pub # for any attachments that went with %TOPIC% $tempPath = "$tempPath/pub"; if( ! -e "$tempPath" ) { umask( 0 ); mkdir( $tempPath, 0777 ); } } } # Move topic and add '.yyyymmddhhmm' extension to .txt and .txt,v filenames # Get time my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime( time() ); $year = sprintf( "%.4u", $year + 1900 ); # Y2K fix my $deldate = sprintf( "%.4u%.2u%.2u%.2u%.2u", $year, $mon+1, $mday, $hour, $min); my $delext = "$deldate$userName"; # to the minute granularity avoids multiple intra-hour deletion collision my $newtxt = "$delDir/$webName/$topic.txt.$delext"; my $newtxtv = "$delDir/$webName/$topic.txt,v.$delext"; my $delDataDir = &wiki::getDataDir(); my $sourcetxt = "$topic.txt$delext"; my $sourcetxtv = "$topic.txt,v$delext"; my $sourcedir = "$delDataDir/$webName"; my $tempval = "$topic.txt"; chdir $sourcedir; system ("mv", $tempval, $newtxt); system ("mv", "$tempval,v", $newtxtv); # Create attachment dir with '.yyyymmddhhmm'+UserName ext and move attachments # code... my $pubsearch = &wiki::getPubDir(); # check if pub topic dir exists - no check for actual files though... if ( -e "$pubsearch/$webName/$topic") { if ( ! -e "$delDir/$webName/pub/$topic") { umask( 0 ); mkdir( "$delDir/$webName/pub/$topic", 0777 ); } # get list of all files to move opendir DIR, "$pubsearch/$webName/$topic"; my @tmpList = readdir(DIR); closedir(DIR); # take the file list, filter out the dot files. Assumes no dirs exist. @fileList = grep { ! /^\.\.?$/ } @tmpList; my $attfile = ""; foreach $attfile (@fileList) { system ("mv", "$pubsearch/$webName/$topic/$attfile", "$delDir/$webName/pub/$topic/"); } system ("rmdir", "$pubsearch/$webName/$topic"); } # ------------------------------------------------- if( $wiki::doLogTopicDelete ) { # write log entry &wiki::writeLog( "delete", "$webName.$topic", "", $userName ); } $tmpl = &wiki::readTemplate( "deletetopic" ); $tmpl =~ s/%DELETETEXT%/$delText/g; $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); print "Content-type: text/html\n"; print "Cache-Control: no-cache\n\n"; print $tmpl; } }