#!/usr/bin/perl -w # ## Foswiki WikiWord replacer # If you are migrating from kwiki this tool might be # usefull for you. kwiki allows any word to be a wikiword # where foswiki has stricter rules. If you have kwiki # pages starting with lowercase or without camelcase # this tool helps you to resolve this issue # # place the script in the data/yourweb directory of your foswiki # installation and fill out the hash %map below. # # The rule is simple: # # 'oldname.txt' => 'NewName.txt', # # The scripts renames the file (if not already done) and # searches in all pages of this web for the term. On # success the user is asked if the the term oldname should # be replaced by NewName or [[NewName]] or the term shall # be skipped at all. # # By typing 'q' (quit) just the actual found pattern is skipped. # # The script replaces on changes the file. Be sure that # you have a 'BACKUP' ## ## Copyright (c) 2009 Herbert Liechti, herbert.liechti@thinx.ch ## ## Acknowledgements: ## Thanks to http://www.thinx.ch/ for giving me ## permission to distribute this. ## ## 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 ## # ## # use Term::Clui; use File::Copy; use strict; my %map = ( # old name # new name 'artikelButtonHowto.txt' => 'ArtikelButtonHowto.txt' , 'eGovernment.txt' => 'EGovernment.txt', 'heiseNews20031104.txt' => 'HeiseNews20031104.txt', 'heisePress20040210.txt' => 'HeisePress20040210.txt', 'slideshow.txt' => 'SlideShow.txt', 'tabellenReiter.txt' => 'TabellenReiter.txt', ); for my $k (sort keys %map) { next if ( $k =~ /,v$/ ); if (-f $k) { # rename old file unless (-f $map{$k}) { move( $k, $map{$k} ) or die $!; } else { die "both files $k and $map{$k} are here. this is an error"; } } my $grep = (split /\./, $k)[0]; my $replace = (split /\./, $map{$k})[0]; print "-------------------------------------Searching $grep\n"; my $skipPattern = 0; for my $f (<*.txt>) { if ( $f eq $map{$k} ) { print " --->Skipping own file $f \n"; next; } open F, "<$f" or die $!; my $change = 0; my @out = (); while () { if (/$grep/) { print "pattern «$grep» found in file $f. Replace by $replace?\n"; print "...........................................................................\n"; print $_; print "...........................................................................\n"; my $what = &choose( "replace $grep?", 'go to next topic', $replace, "[[$replace]]" ); if ($what) { if ($what eq 'go to next topic') { $skipPattern = 1; last; } print "yes replacing with $what\n"; s/$grep/$what/g; $change = 1; } } push @out, $_; } close F; if ($change) { open OUT, ">$f" or die $!; print OUT @out; close OUT; } last if ($skipPattern) } }