Moving dokuwiki pages to another namespace


I adapted the perl code here: http://blog.doomicile.de/2008/08/11/moving-dokuwiki-pages-with-perl/

It originally moves pages according to a month/day/year scheme.

I just wanted to move all the pages to a subnamespace. Here is my script:

#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use WWW::Mechanize::FormFiller;
use URI::URL;
# list with page names
my @urls = `cat liste.txt`;
my $agent = WWW::Mechanize->new( autocheck => 1 );
my $formfiller = WWW::Mechanize::FormFiller->new();
$agent->env_proxy();
print "Logging in ... \n";
$agent->get('http://myurl/wiki/doku.php?do=login');
$agent->form_number(7) if $agent->forms and scalar @{ $agent->forms };
$formfiller->add_filler( 'u' => Fixed => 'myadmin' );
$formfiller->add_filler( 'p' => Fixed => 'mypassword' );
$formfiller->fill_form( $agent->current_form );
$agent->submit();
print "Logging in done.\n";
my $n, my $o, my $p;
foreach (@urls) {
print $_;
( $n, $o ) = m/(.*):([^:]*)/;
$p = 'myprefix:';
if (length($n) == 0) {
$p = 'myprefix';
( $o ) = m/(.*)/;
}
print '=> ' . $p . '|' . $n . '|' . $o . "\n";
$agent->get( "http://myurl/wiki/doku.php?id=" . $_ . "&do=admin&page=pagemove" );
$agent->form_number(6) if $agent->forms and scalar @{ $agent->forms };
$formfiller->fill_form( $agent->current_form );
$formfiller->fill_form( $agent->current_form );
if (length($n) == 0) {
$formfiller->add_filler( 'nsr' => Fixed => '' );
$formfiller->add_filler( 'newns' => Fixed => $p );
$formfiller->add_filler( 'ns' => Fixed => $p );
} else {
$formfiller->add_filler( 'nsr' => Fixed => '<new>' );
$formfiller->add_filler( 'newns' => Fixed => $p . $n );
$formfiller->add_filler( 'ns' => Fixed => ':' );
}
$formfiller->add_filler( 'pagename' => Fixed => $o );
$formfiller->fill_form( $agent->current_form );
$agent->save_content("/tmp/mydump.txt");
$agent->submit();
$agent->save_content("/tmp/mydump-response.txt");
}

PS: Apparently, I can write perl. I did not know.

  1. No comments yet.
(will not be published)

  1. No trackbacks yet.