+ my $setup=shift;
+ if (! defined $setup) {
+ usage();
+ }
+
+ require IkiWiki::Setup;
+ require IkiWiki::Plugin::aggregate;
+
+ %config = IkiWiki::defaultconfig();
+ IkiWiki::Setup::load($setup);
+ IkiWiki::loadplugins();
+ IkiWiki::checkconfig();
+ IkiWiki::loadindex();
+
+ if (! %pagesources) {
+ error "ikiwiki has not built this wiki yet, cannot transition";
+ }
+
+ foreach my $page (values %pagesources) {
+ next unless defined pagetype($page) &&
+ -f $config{srcdir}."/".$page;
+ my $content=readfile($config{srcdir}."/".$page);
+ my $oldcontent=$content;
+ $content=~s{$regex}{handle_directive($1, $2, $3, $4)}eg;
+ if ($oldcontent ne $content) {
+ writefile($page, $config{srcdir}, $content);
+ }
+ }
+}
+
+sub indexdb {
+ my $dir=shift;
+ if (! defined $dir) {
+ usage();
+ }
+ $config{wikistatedir}=$dir."/.ikiwiki";
+
+ # Note: No lockwiki here because ikiwiki already locks it
+ # before calling this.
+ if (! IkiWiki::oldloadindex()) {
+ die "failed to load index\n";
+ }
+ if (! IkiWiki::saveindex()) {
+ die "failed to save indexdb\n"
+ }
+ if (! IkiWiki::loadindex()) {
+ die "transition failed, cannot load new indexdb\n";
+ }
+ if (! unlink("$config{wikistatedir}/index")) {
+ die "unlink failed: $!\n";
+ }
+}
+
+sub hashpassword {
+ my $dir=shift;
+ if (! defined $dir) {
+ usage();
+ }
+ $config{wikistatedir}=$dir."/.ikiwiki";
+
+ eval q{use IkiWiki::UserInfo};
+ eval q{use Authen::Passphrase::BlowfishCrypt};
+ if ($@) {
+ error("ikiwiki-transition hashpassword: failed to load Authen::Passphrase, passwords not hashed");
+ }
+
+ IkiWiki::lockwiki();
+ IkiWiki::loadplugin("passwordauth");
+ my $userinfo = IkiWiki::userinfo_retrieve();
+ foreach my $user (keys %{$userinfo}) {
+ if (ref $userinfo->{$user} &&
+ exists $userinfo->{$user}->{password} &&
+ length $userinfo->{$user}->{password} &&
+ ! exists $userinfo->{$user}->{cryptpassword}) {
+ IkiWiki::Plugin::passwordauth::setpassword($user, $userinfo->{$user}->{password});
+ }
+ }
+}
+
+sub aggregateinternal {
+ my $setup=shift;
+ if (! defined $setup) {
+ usage();
+ }
+
+ require IkiWiki::Setup;
+ require IkiWiki::Plugin::aggregate;
+
+ %config = IkiWiki::defaultconfig();
+ IkiWiki::Setup::load($setup);
+ IkiWiki::checkconfig();
+
+ IkiWiki::Plugin::aggregate::migrate_to_internal();
+}
+
+sub setupformat {
+ my $setup=shift;
+ if (! defined $setup) {
+ usage();
+ }
+
+ require IkiWiki::Setup;
+
+ %config = IkiWiki::defaultconfig();
+ IkiWiki::Setup::load($setup);
+ IkiWiki::checkconfig();