#!perl # # Copyright (C) 2001 Sven Dowideit, svenud@ozemail.com.au # # 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 #usage example: #
# # # #
use CGI; use wiki; print "Content-type: text/html\n\n"; $query= new CGI; &main(); sub main { my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ); my $newTopic = $query->param( 'newtopic' ); my $redoRename = $query->param( 'Redo' ); my $theUrl = $query->url; my $lockFailure = ""; ( $topic, $webName, $scriptUrlPath, $userName, $dataDir ) = &wiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl ); if( ! &wiki::webExists( $webName ) ) { $tmpl= &wiki::readTemplate( "noweb" ); $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); print $tmpl; return; } my $fileName = "$dataDir/$webName/$topic.txt"; my $newName = "$dataDir/$webName/$newTopic.txt"; #print "

Redo = $redoRename

"; if (( $redoRename eq "ON" ) || (( -e $fileName ) && !( -e $newName) && !(&wiki::topicIsLocked( $fileName )))) #need to make sure newName ia a wikiName { my $search = $newTopic; my $scope = "text"; my $caseSensitive = ""; my @result = findReferingPages($webName, $topic); my $result = ""; foreach $item (@result) { if ( &wiki::topicIsLocked( $item ) ) { $lockFailure = true; } else { my $resultText = ""; $result .= ":$item: , "; #open each file, replace $topic with $newTopic if ( &wiki::topicExists($webName, $item) ) { my $scantext = &wiki::readTopic($item); foreach( split( /\n/, $scantext ) ) { s/([_\*\>\s]*)\Q$topic\E([_\*<\s]+)/$1$newTopic$2/go; s/([_\*\>\s]*)\Q$topic\E$/$1$newTopic/go; $resultText .= "$_\n"; } } else { $result .= ";$item does not exist;" } &wiki::saveTopic($item, $resultText); } } if ( $redoRename ne "ON" ) { rename($fileName, $newName); } &wiki::revisionChangeName($topic, $newTopic); my $pubDir = "i:\\inetpub\\twiki\\pub"; #rename the pub directory my $attachments = "$pubDir\\$webName\\$topic"; #if ( -e $attachments ) { $newAttachments = "$pubDir\\$webName\\$newTopic"; # rename($attachments, $newAttachments); my $tmp = "move $attachments $newAttachments"; # print "


$tmp
"; $tmp =~ /(.*)/; $tmp = $1; # now safe, so untaint variable $tmp = `$tmp`; } my $new_url = ""; if ( $lockFailure ) { #redirect to new pagename... $new_url = &wiki::viewUrl( "RenamePage" ); $new_url .= "?TOPIC_TO_RENAME=$topic&NEW_NAME=$newTopic&Redo=ON"; print "

Failed to Rename some links "; print "

Redirecting to $new_url

"; } else { #redirect to new pagename... $new_url = &wiki::viewUrl( $newTopic ); print "

Redirecting to $new_url

"; } print $query->redirect( $new_url ); # print ""; # print ""; # print ""; # print " Rename Page "; # print ""; # print ""; # print "rename done


"; # print "
$result
"; # print ""; # print ""; } else { print ""; print ""; print ""; print " Rename page ERROR "; print ""; print ""; print "rename Not done - either the source page does not exist, or the destination page already exists :)"; print ""; print ""; } } sub findReferingPages #($webName, $topic); { my ($webName, $topic) = @_; my ( $result ) = ""; my $webDir = "$dataDir/$webName"; my $cmd = "%GREP% %SWITCHES% -l '$topic' *.txt"; my $tempVal = "-i"; $cmd =~ s/%SWITCHES%/$tempVal/go; $tempVal = $wiki::fgrepCmd; $cmd =~ s/%GREP%/$tempVal/go; my @topicList = ""; # do grep search chdir( $webDir ); $cmd =~ /(.*)/; $cmd = $1; # untaint variable (NOTE: Needs a better check!) $tempVal = `$cmd`; @result = split( /\n/, $tempVal ); # cut .txt extension @result = map { /(.*)\.txt$/; $_ = $1; } @result; return @result; }