#!/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 = "

Please Confirm Deletion!

\n

Are you sure you want to delete the %TOPIC% topic?\n
\n
"; # Check for refering documents my $doInline = "1"; my $webStr = "all"; my $search = $topic; my $scope = "text"; my $order = ""; my $regex = ""; my $limit = ""; my $revSort = ""; my $caseSensitive = "on"; my $nosummary = "on"; my $nosearch = "on"; my $nototal = "on"; my $bookView = ""; my $template = ""; my $refDocSearch = &wiki::searchWikiWeb( $doInline, $websStr, $search, $scope, $order, $regex, $limit, $revSort, $caseSensitive, $nosummary, $nosearch, $nototal, $bookView, $template ); # my $refDocSearch = &wiki::searchWikiWeb( "", "all", $topic, "text", "", "", "", "", "on", "on", "on", "on", "", "" ); # my $refDocSearch = '"%SEARCH{ $topic scope="text" web="all" nosummary="on" }%'; # my $refDocs = &wiki::handleCommonTags( $refDocSearch, $topic ); # unless ($refDocs eq "") # { $delText = $delText."

Warning!

The following wiki pages may have a link to the topic you are about to delete:

If only one link is listed below and it's the page you were on when you linked to the current topic you are about to delete, it is safe to continue to delete this page.
Any pages listed below that do not generate their content dynamically via in-line searches will have their links to this page replaced with $topic? links.

$refDocSearch"; # } $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; return; } else { my $tmpl = ""; my $delText = "

Topic is now deleted

\nHit your browser's 'back' button three times then click your browser's reload/refresh button to continue working or you can click %WEB% to got to this web's home page.\n

\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; } }