]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Add preprocessed 'use lib' line to ikiwiki-transition and ikiwiki-calendar if necessa...
authorJoey Hess <joey@gnu.kitenet.net>
Fri, 26 Mar 2010 17:11:02 +0000 (13:11 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Fri, 26 Mar 2010 17:11:02 +0000 (13:11 -0400)
.gitignore
Makefile.PL
debian/changelog
doc/bugs/ikiwiki-transition_does_not_set_perl_moduels_path_properly.mdwn
ikiwiki-calendar [deleted file]
ikiwiki-calendar.in [new file with mode: 0755]
ikiwiki-transition [deleted file]
ikiwiki-transition.in [new file with mode: 0755]
ikiwiki.spec

index 8de36e2c8df25ab30f7fadeffbcdf25f189863f3..e9ab152b6413d20385e317c7020406b01268f607 100644 (file)
@@ -5,9 +5,10 @@ blib/*
 doc/.ikiwiki/*
 html/*
 ikiwiki.out
+ikiwiki-transition.out
+ikiwiki-calendar.out
 pm_to_blib
 *.man
-build-stamp
 po/po2wiki_stamp
 po/underlays/*/*.mdwn
 po/underlays/basewiki/*/*.mdwn
index 52421a711d89fee2a2d82529048d26e8e263406e..5a9028b519e99b1569284eb2d62bb3857ef60ceb 100755 (executable)
@@ -28,15 +28,16 @@ W3M_CGI_BIN?=$(PREFIX)/lib/w3m/cgi-bin
 
 tflag=$(shell if [ -n "$$NOTAINT" ] && [ "$$NOTAINT" != 1 ]; then printf -- "-T"; fi)
 extramodules=$(shell if [ "$$PROFILE" = 1 ]; then printf -- "-d:NYTProf"; fi)
+outprogs=ikiwiki.out ikiwiki-transition.out ikiwiki-calendar.out
 
-ikiwiki.out: ikiwiki.in
-       ./pm_filter $(PREFIX) $(VER) $(PROBABLE_INST_LIB) < ikiwiki.in > ikiwiki.out
-       chmod +x ikiwiki.out
+%.out: %.in
+       ./pm_filter $(PREFIX) $(VER) $(PROBABLE_INST_LIB) < $< > $@
+       chmod +x $@
 
 ikiwiki.setup: ikiwiki.out
        HOME=/home/me $(PERL) -Iblib/lib $(extramodules) $(tflag) ikiwiki.out -libdir . -dumpsetup ikiwiki.setup
 
-extra_build: ikiwiki.out ikiwiki.setup docwiki
+extra_build: $(outprogs) ikiwiki.setup docwiki
        ./mdwn2man ikiwiki 1 doc/usage.mdwn > ikiwiki.man
        ./mdwn2man ikiwiki-mass-rebuild 8 doc/ikiwiki-mass-rebuild.mdwn > ikiwiki-mass-rebuild.man
        ./mdwn2man ikiwiki-makerepo 1 doc/ikiwiki-makerepo.mdwn > ikiwiki-makerepo.man
@@ -52,7 +53,7 @@ docwiki: ikiwiki.out
 
 extra_clean:
        $(PERL) -I. $(extramodules) $(tflag) ikiwiki.in -libdir . -setup docwiki.setup -clean
-       rm -f *.man ikiwiki.out ikiwiki.setup plugins/*.pyc
+       rm -f *.man $(outprogs) ikiwiki.setup plugins/*.pyc
        $(MAKE) -C po clean
 
 underlay_install:
@@ -115,8 +116,9 @@ extra_install: underlay_install
        install ikiwiki-w3m.cgi $(DESTDIR)$(W3M_CGI_BIN)
 
        install -d $(DESTDIR)$(PREFIX)/bin
-       install ikiwiki.out $(DESTDIR)$(PREFIX)/bin/ikiwiki
-       install ikiwiki-makerepo ikiwiki-transition ikiwiki-update-wikilist ikiwiki-calendar $(DESTDIR)$(PREFIX)/bin/
+       for prog in $(outprogs); do \
+               install $$prog $(DESTDIR)$(PREFIX)/bin/$$(shell echo $$prog | sed 's/\.out//'); \
+       done
 
        $(MAKE) -C po install DESTDIR=$(DESTDIR) PREFIX=$(PREFIX)
        
index b9a1055523b9d46462ffb6d29a1676faa17e0ca2..57406c6d3f739fa37ac1670c8ed371d5b6b19251 100644 (file)
@@ -19,6 +19,8 @@ ikiwiki (3.20100324) UNRELEASED; urgency=low
     not called by attachment plugin.
   * Fix incorrect influence info returned by a failing link() pagespec,
     that could lead to bad dependency handling in certian situations.
+  * Add preprocessed 'use lib' line to ikiwiki-transition and ikiwiki-calendar
+    if necessary for unusual install.
 
  -- Joey Hess <joeyh@debian.org>  Sat, 13 Mar 2010 14:48:10 -0500
 
index 5dd4bc780bc486f01d76fd298126d4c27058ea60..b3e87b529161ac9209a08efb94a2a753ea0d9910 100644 (file)
@@ -13,3 +13,5 @@ This is not true for ikiwiki-transition:
 The missing line should be added.
 
 Thanks!
+
+[[done]] --[[Joey]] 
diff --git a/ikiwiki-calendar b/ikiwiki-calendar
deleted file mode 100755 (executable)
index a9548d6..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/perl
-use warnings;
-use strict;
-use IkiWiki;
-use IkiWiki::Setup;
-use Getopt::Long;
-
-sub usage () {
-       die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
-}
-
-my $force=0;
-GetOptions(
-       "force" => \$force,
-) || usage();
-my $setup=shift                || usage();
-my $pagespec=shift     || "*";
-my $startyear=shift    || 1900+(localtime(time))[5];
-my $endyear=shift      || $startyear;
-
-%config=IkiWiki::defaultconfig();
-IkiWiki::Setup::load($setup);
-IkiWiki::loadplugins();
-IkiWiki::checkconfig();
-
-my $archivebase = 'archives';
-$archivebase = $config{archivebase} if defined $config{archivebase};
-
-sub writearchive ($$;$) {
-       my $template=template(shift);
-       my $year=shift;
-       my $month=shift;
-
-       my $page=defined $month ? "$year/$month" : $year;
-
-       my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
-       $template->param(pagespec => $pagespec);
-       $template->param(year => $year);
-       $template->param(month => $month) if defined $month;
-
-       if ($force || ! -e "$config{srcdir}/$pagefile") {
-               writefile($pagefile, $config{srcdir}, $template->output);
-               IkiWiki::rcs_add($pagefile) if $config{rcs};
-       }
-}
-
-foreach my $y ($startyear..$endyear) {
-       writearchive("calendaryear.tmpl", $y);
-       foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
-               writearchive("calendarmonth.tmpl", $y, $m);
-       }
-}
-
-IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
-       if $config{rcs};
-
-system("ikiwiki", "-setup", $setup, "-refresh");
diff --git a/ikiwiki-calendar.in b/ikiwiki-calendar.in
new file mode 100755 (executable)
index 0000000..9738ea5
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use lib '.'; # For use in nonstandard directory, munged by Makefile.
+use IkiWiki;
+use IkiWiki::Setup;
+use Getopt::Long;
+
+sub usage () {
+       die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
+}
+
+my $force=0;
+GetOptions(
+       "force" => \$force,
+) || usage();
+my $setup=shift                || usage();
+my $pagespec=shift     || "*";
+my $startyear=shift    || 1900+(localtime(time))[5];
+my $endyear=shift      || $startyear;
+
+%config=IkiWiki::defaultconfig();
+IkiWiki::Setup::load($setup);
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+
+my $archivebase = 'archives';
+$archivebase = $config{archivebase} if defined $config{archivebase};
+
+sub writearchive ($$;$) {
+       my $template=template(shift);
+       my $year=shift;
+       my $month=shift;
+
+       my $page=defined $month ? "$year/$month" : $year;
+
+       my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
+       $template->param(pagespec => $pagespec);
+       $template->param(year => $year);
+       $template->param(month => $month) if defined $month;
+
+       if ($force || ! -e "$config{srcdir}/$pagefile") {
+               writefile($pagefile, $config{srcdir}, $template->output);
+               IkiWiki::rcs_add($pagefile) if $config{rcs};
+       }
+}
+
+foreach my $y ($startyear..$endyear) {
+       writearchive("calendaryear.tmpl", $y);
+       foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
+               writearchive("calendarmonth.tmpl", $y, $m);
+       }
+}
+
+IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
+       if $config{rcs};
+
+system("ikiwiki", "-setup", $setup, "-refresh");
diff --git a/ikiwiki-transition b/ikiwiki-transition
deleted file mode 100755 (executable)
index 1bebb11..0000000
+++ /dev/null
@@ -1,348 +0,0 @@
-#!/usr/bin/perl
-use warnings;
-use strict;
-use IkiWiki;
-use HTML::Entities;
-
-my $regex = qr{
-       (\\?)           # 1: escape?
-       \[\[(!?)        # directive open; 2: optional prefix
-       ([-\w]+)        # 3: command
-       (               # 4: the parameters (including initial whitespace)
-       \s+
-               (?:
-                       (?:[-\w]+=)?            # named parameter key?
-                       (?:
-                               """.*?"""       # triple-quoted value
-                               |
-                               "[^"]+"         # single-quoted value
-                               |
-                               [^\s\]]+        # unquoted value
-                       )
-                       \s*                     # whitespace or end
-                                               # of directive
-               )
-       *)              # 0 or more parameters
-       \]\]            # directive closed
-}sx;
-
-sub handle_directive {
-       my $escape = shift;
-       my $prefix = shift;
-       my $directive = shift;
-       my $args = shift;
-
-       if (length $escape) {
-               return "${escape}[[${prefix}${directive}${args}]]"
-       }
-       if ($directive =~ m/^(if|more|table|template|toggleable)$/) {
-               $args =~ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
-       }
-       return "[[!${directive}${args}]]"
-}
-
-sub prefix_directives {
-       loadsetup(shift);
-
-       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 {
-       setstatedir(shift);
-
-       # 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 {
-       setstatedir(shift);
-
-       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 {
-       loadsetup(shift);
-       require IkiWiki::Plugin::aggregate;
-       IkiWiki::checkconfig();
-       IkiWiki::Plugin::aggregate::migrate_to_internal();
-}
-
-sub setupformat {
-       my $setup=shift;
-
-       loadsetup($setup);
-       IkiWiki::checkconfig();
-       
-       # unpack old-format wrappers setting into new fields
-       my $cgi_seen=0;
-       my $rcs_seen=0;
-       foreach my $wrapper (@{$config{wrappers}}) {
-               if ($wrapper->{cgi}) {
-                       if ($cgi_seen) {
-                               die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
-                       }
-                       $cgi_seen++;
-                       print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
-                       $config{cgi_wrapper}=$wrapper->{wrapper};
-                       $config{cgi_wrappermode}=$wrapper->{wrappermode}
-                               if exists $wrapper->{wrappermode};
-               }
-               elsif ($config{rcs}) {
-                       if ($rcs_seen) {
-                               die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
-                       }
-                       $rcs_seen++;
-                       print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
-                       $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
-                       $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
-                               if exists $wrapper->{wrappermode};
-               }
-               else {
-                       die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
-               }
-       }
-
-       IkiWiki::Setup::dump($setup);
-}
-
-sub moveprefs {
-       my $setup=shift;
-
-       loadsetup($setup);
-       IkiWiki::checkconfig();
-
-       eval q{use IkiWiki::UserInfo};
-       error $@ if $@;
-
-       foreach my $field (qw{allowed_attachments locked_pages}) {
-               my $orig=$config{$field};
-               foreach my $admin (@{$config{adminuser}}) {
-                       my $a=IkiWiki::userinfo_get($admin, $field);
-                       if (defined $a && length $a &&
-                           # might already have been moved
-                           (! defined $orig || $a ne $orig)) {
-                               if (defined $config{$field} &&
-                                   length $config{$field}) {
-                                       $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
-                               }
-                               else {
-                                       $config{$field}=$a;
-                               }
-                       }
-               }
-       }
-
-       my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
-       $config{banned_users}=[sort keys %banned];
-
-       IkiWiki::Setup::dump($setup);
-}
-
-sub deduplinks {
-       loadsetup(shift);
-       IkiWiki::loadplugins();
-       IkiWiki::checkconfig();
-       IkiWiki::loadindex();
-       foreach my $page (keys %links) {
-               my %l;
-               $l{$_}=1 foreach @{$links{$page}};
-               $links{$page}=[keys %l]
-       }
-       IkiWiki::saveindex();
-}
-
-sub setstatedir {
-       my $dirorsetup=shift;
-
-       if (! defined $dirorsetup) {
-               usage();                
-       }
-
-       if (-d $dirorsetup) {
-               $config{wikistatedir}=$dirorsetup."/.ikiwiki";
-       }
-       elsif (-f $dirorsetup) {
-               loadsetup($dirorsetup);
-       }
-       else {
-               error("ikiwiki-transition: $dirorsetup does not exist");
-       }
-
-       if (! -d $config{wikistatedir}) {
-               error("ikiwiki-transition: $config{wikistatedir} does not exist");
-       }
-}
-       
-sub loadsetup {
-       my $setup=shift;
-       if (! defined $setup) {
-               usage();
-       }
-
-       require IkiWiki::Setup;
-
-       %config = IkiWiki::defaultconfig();
-       IkiWiki::Setup::load($setup);
-}
-
-sub usage {
-       print STDERR "Usage: ikiwiki-transition type ...\n";
-       print STDERR "Currently supported transition subcommands:\n";
-       print STDERR "\tprefix_directives setupfile ...\n";
-       print STDERR "\taggregateinternal setupfile\n";
-       print STDERR "\tsetupformat setupfile\n";
-       print STDERR "\tmoveprefs setupfile\n";
-       print STDERR "\thashpassword setupfile|srcdir\n";
-       print STDERR "\tindexdb setupfile|srcdir\n";
-       print STDERR "\tdeduplinks setupfile\n";
-       exit 1;
-}
-
-usage() unless @ARGV;
-
-my $mode=shift;
-if ($mode eq 'prefix_directives') {
-       prefix_directives(@ARGV);
-}
-elsif ($mode eq 'hashpassword') {
-       hashpassword(@ARGV);
-}
-elsif ($mode eq 'indexdb') {
-       indexdb(@ARGV);
-}
-elsif ($mode eq 'aggregateinternal') {
-       aggregateinternal(@ARGV);
-}
-elsif ($mode eq 'setupformat') {
-       setupformat(@ARGV);
-}
-elsif ($mode eq 'moveprefs') {
-       moveprefs(@ARGV);
-}
-elsif ($mode eq 'deduplinks') {
-       deduplinks(@ARGV);
-}
-else {
-       usage();
-}
-
-package IkiWiki;
-
-# A slightly modified version of the old loadindex function.
-sub oldloadindex {
-       %oldrenderedfiles=%pagectime=();
-       if (! $config{rebuild}) {
-               %pagesources=%pagemtime=%oldlinks=%links=%depends=
-                       %destsources=%renderedfiles=%pagecase=%pagestate=();
-       }
-       open (my $in, "<", "$config{wikistatedir}/index") || return;
-       while (<$in>) {
-               chomp;
-               my %items;
-               $items{link}=[];
-               $items{dest}=[];
-               foreach my $i (split(/ /, $_)) {
-                       my ($item, $val)=split(/=/, $i, 2);
-                       push @{$items{$item}}, decode_entities($val);
-               }
-
-               next unless exists $items{src}; # skip bad lines for now
-
-               my $page=pagename($items{src}[0]);
-               if (! $config{rebuild}) {
-                       $pagesources{$page}=$items{src}[0];
-                       $pagemtime{$page}=$items{mtime}[0];
-                       $oldlinks{$page}=[@{$items{link}}];
-                       $links{$page}=[@{$items{link}}];
-                       $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT } if exists $items{depends};
-                       $destsources{$_}=$page foreach @{$items{dest}};
-                       $renderedfiles{$page}=[@{$items{dest}}];
-                       $pagecase{lc $page}=$page;
-                       foreach my $k (grep /_/, keys %items) {
-                               my ($id, $key)=split(/_/, $k, 2);
-                               $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
-                       }
-               }
-               $oldrenderedfiles{$page}=[@{$items{dest}}];
-               $pagectime{$page}=$items{ctime}[0];
-       }
-
-       # saveindex relies on %hooks being populated, else it won't save
-       # the page state owned by a given hook. But no plugins are loaded
-       # by this program, so populate %hooks with all hook ids that
-       # currently have page state.
-       foreach my $page (keys %pagemtime) {
-               foreach my $id (keys %{$pagestate{$page}}) {
-                       $hooks{_dummy}{$id}=1;
-               }
-       }
-       
-       return close($in);
-}
-
-# Used to be in IkiWiki/UserInfo, but only used here now.
-sub get_banned_users () {
-       my @ret;
-       my $userinfo=userinfo_retrieve();
-       foreach my $user (keys %{$userinfo}) {
-               push @ret, $user if $userinfo->{$user}->{banned};
-       }
-       return @ret;
-}
-
-# Used to be in IkiWiki, but only used here (to migrate admin prefs into the
-# setup file) now.
-sub pagespec_merge ($$) {
-       my $a=shift;
-       my $b=shift;
-
-       return $a if $a eq $b;
-       return "($a) or ($b)";
-}
-
-1
diff --git a/ikiwiki-transition.in b/ikiwiki-transition.in
new file mode 100755 (executable)
index 0000000..e3be645
--- /dev/null
@@ -0,0 +1,349 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use lib '.'; # For use in nonstandard directory, munged by Makefile.
+use IkiWiki;
+use HTML::Entities;
+
+my $regex = qr{
+       (\\?)           # 1: escape?
+       \[\[(!?)        # directive open; 2: optional prefix
+       ([-\w]+)        # 3: command
+       (               # 4: the parameters (including initial whitespace)
+       \s+
+               (?:
+                       (?:[-\w]+=)?            # named parameter key?
+                       (?:
+                               """.*?"""       # triple-quoted value
+                               |
+                               "[^"]+"         # single-quoted value
+                               |
+                               [^\s\]]+        # unquoted value
+                       )
+                       \s*                     # whitespace or end
+                                               # of directive
+               )
+       *)              # 0 or more parameters
+       \]\]            # directive closed
+}sx;
+
+sub handle_directive {
+       my $escape = shift;
+       my $prefix = shift;
+       my $directive = shift;
+       my $args = shift;
+
+       if (length $escape) {
+               return "${escape}[[${prefix}${directive}${args}]]"
+       }
+       if ($directive =~ m/^(if|more|table|template|toggleable)$/) {
+               $args =~ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
+       }
+       return "[[!${directive}${args}]]"
+}
+
+sub prefix_directives {
+       loadsetup(shift);
+
+       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 {
+       setstatedir(shift);
+
+       # 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 {
+       setstatedir(shift);
+
+       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 {
+       loadsetup(shift);
+       require IkiWiki::Plugin::aggregate;
+       IkiWiki::checkconfig();
+       IkiWiki::Plugin::aggregate::migrate_to_internal();
+}
+
+sub setupformat {
+       my $setup=shift;
+
+       loadsetup($setup);
+       IkiWiki::checkconfig();
+       
+       # unpack old-format wrappers setting into new fields
+       my $cgi_seen=0;
+       my $rcs_seen=0;
+       foreach my $wrapper (@{$config{wrappers}}) {
+               if ($wrapper->{cgi}) {
+                       if ($cgi_seen) {
+                               die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
+                       }
+                       $cgi_seen++;
+                       print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
+                       $config{cgi_wrapper}=$wrapper->{wrapper};
+                       $config{cgi_wrappermode}=$wrapper->{wrappermode}
+                               if exists $wrapper->{wrappermode};
+               }
+               elsif ($config{rcs}) {
+                       if ($rcs_seen) {
+                               die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
+                       }
+                       $rcs_seen++;
+                       print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
+                       $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
+                       $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
+                               if exists $wrapper->{wrappermode};
+               }
+               else {
+                       die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
+               }
+       }
+
+       IkiWiki::Setup::dump($setup);
+}
+
+sub moveprefs {
+       my $setup=shift;
+
+       loadsetup($setup);
+       IkiWiki::checkconfig();
+
+       eval q{use IkiWiki::UserInfo};
+       error $@ if $@;
+
+       foreach my $field (qw{allowed_attachments locked_pages}) {
+               my $orig=$config{$field};
+               foreach my $admin (@{$config{adminuser}}) {
+                       my $a=IkiWiki::userinfo_get($admin, $field);
+                       if (defined $a && length $a &&
+                           # might already have been moved
+                           (! defined $orig || $a ne $orig)) {
+                               if (defined $config{$field} &&
+                                   length $config{$field}) {
+                                       $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
+                               }
+                               else {
+                                       $config{$field}=$a;
+                               }
+                       }
+               }
+       }
+
+       my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
+       $config{banned_users}=[sort keys %banned];
+
+       IkiWiki::Setup::dump($setup);
+}
+
+sub deduplinks {
+       loadsetup(shift);
+       IkiWiki::loadplugins();
+       IkiWiki::checkconfig();
+       IkiWiki::loadindex();
+       foreach my $page (keys %links) {
+               my %l;
+               $l{$_}=1 foreach @{$links{$page}};
+               $links{$page}=[keys %l]
+       }
+       IkiWiki::saveindex();
+}
+
+sub setstatedir {
+       my $dirorsetup=shift;
+
+       if (! defined $dirorsetup) {
+               usage();                
+       }
+
+       if (-d $dirorsetup) {
+               $config{wikistatedir}=$dirorsetup."/.ikiwiki";
+       }
+       elsif (-f $dirorsetup) {
+               loadsetup($dirorsetup);
+       }
+       else {
+               error("ikiwiki-transition: $dirorsetup does not exist");
+       }
+
+       if (! -d $config{wikistatedir}) {
+               error("ikiwiki-transition: $config{wikistatedir} does not exist");
+       }
+}
+       
+sub loadsetup {
+       my $setup=shift;
+       if (! defined $setup) {
+               usage();
+       }
+
+       require IkiWiki::Setup;
+
+       %config = IkiWiki::defaultconfig();
+       IkiWiki::Setup::load($setup);
+}
+
+sub usage {
+       print STDERR "Usage: ikiwiki-transition type ...\n";
+       print STDERR "Currently supported transition subcommands:\n";
+       print STDERR "\tprefix_directives setupfile ...\n";
+       print STDERR "\taggregateinternal setupfile\n";
+       print STDERR "\tsetupformat setupfile\n";
+       print STDERR "\tmoveprefs setupfile\n";
+       print STDERR "\thashpassword setupfile|srcdir\n";
+       print STDERR "\tindexdb setupfile|srcdir\n";
+       print STDERR "\tdeduplinks setupfile\n";
+       exit 1;
+}
+
+usage() unless @ARGV;
+
+my $mode=shift;
+if ($mode eq 'prefix_directives') {
+       prefix_directives(@ARGV);
+}
+elsif ($mode eq 'hashpassword') {
+       hashpassword(@ARGV);
+}
+elsif ($mode eq 'indexdb') {
+       indexdb(@ARGV);
+}
+elsif ($mode eq 'aggregateinternal') {
+       aggregateinternal(@ARGV);
+}
+elsif ($mode eq 'setupformat') {
+       setupformat(@ARGV);
+}
+elsif ($mode eq 'moveprefs') {
+       moveprefs(@ARGV);
+}
+elsif ($mode eq 'deduplinks') {
+       deduplinks(@ARGV);
+}
+else {
+       usage();
+}
+
+package IkiWiki;
+
+# A slightly modified version of the old loadindex function.
+sub oldloadindex {
+       %oldrenderedfiles=%pagectime=();
+       if (! $config{rebuild}) {
+               %pagesources=%pagemtime=%oldlinks=%links=%depends=
+                       %destsources=%renderedfiles=%pagecase=%pagestate=();
+       }
+       open (my $in, "<", "$config{wikistatedir}/index") || return;
+       while (<$in>) {
+               chomp;
+               my %items;
+               $items{link}=[];
+               $items{dest}=[];
+               foreach my $i (split(/ /, $_)) {
+                       my ($item, $val)=split(/=/, $i, 2);
+                       push @{$items{$item}}, decode_entities($val);
+               }
+
+               next unless exists $items{src}; # skip bad lines for now
+
+               my $page=pagename($items{src}[0]);
+               if (! $config{rebuild}) {
+                       $pagesources{$page}=$items{src}[0];
+                       $pagemtime{$page}=$items{mtime}[0];
+                       $oldlinks{$page}=[@{$items{link}}];
+                       $links{$page}=[@{$items{link}}];
+                       $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT } if exists $items{depends};
+                       $destsources{$_}=$page foreach @{$items{dest}};
+                       $renderedfiles{$page}=[@{$items{dest}}];
+                       $pagecase{lc $page}=$page;
+                       foreach my $k (grep /_/, keys %items) {
+                               my ($id, $key)=split(/_/, $k, 2);
+                               $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
+                       }
+               }
+               $oldrenderedfiles{$page}=[@{$items{dest}}];
+               $pagectime{$page}=$items{ctime}[0];
+       }
+
+       # saveindex relies on %hooks being populated, else it won't save
+       # the page state owned by a given hook. But no plugins are loaded
+       # by this program, so populate %hooks with all hook ids that
+       # currently have page state.
+       foreach my $page (keys %pagemtime) {
+               foreach my $id (keys %{$pagestate{$page}}) {
+                       $hooks{_dummy}{$id}=1;
+               }
+       }
+       
+       return close($in);
+}
+
+# Used to be in IkiWiki/UserInfo, but only used here now.
+sub get_banned_users () {
+       my @ret;
+       my $userinfo=userinfo_retrieve();
+       foreach my $user (keys %{$userinfo}) {
+               push @ret, $user if $userinfo->{$user}->{banned};
+       }
+       return @ret;
+}
+
+# Used to be in IkiWiki, but only used here (to migrate admin prefs into the
+# setup file) now.
+sub pagespec_merge ($$) {
+       my $a=shift;
+       my $b=shift;
+
+       return $a if $a eq $b;
+       return "($a) or ($b)";
+}
+
+1
index 2bb87724d8deb34df1cd13c49c6f38d2e1750c75..532a9188544df7f070f5994e9cb8bec78d647358 100644 (file)
@@ -1,5 +1,5 @@
 Name:           ikiwiki
-Version: 3.20100312
+Version: 3.20100324
 Release:        1%{?dist}
 Summary:        A wiki compiler