make ikiwiki-transition prefix_directives take a setup file
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 25 Dec 2008 00:43:07 +0000 (19:43 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 25 Dec 2008 00:48:42 +0000 (19:48 -0500)
This is easier to remeber, and less error-prone than passing it all the
pages in the wiki.

debian/NEWS
doc/ikiwiki-transition.mdwn
doc/plugins/write.mdwn
doc/tips/upgrade_to_3.0.mdwn
ikiwiki-transition

index 1c9763d1a9b28cb89077a3eeb1ae69d08ea761ab..f9dfc3770e6e3d484cd6b07e241328d910e083b4 100644 (file)
@@ -110,10 +110,7 @@ ikiwiki (2.40) unstable; urgency=low
   in their setup files.
 
   To convert your wiki to the new syntax, ikiwiki provides a new script
-  ikiwiki-transition.  It will convert preprocessor directives in
-  all files given on the command line.  To convert an entire wiki:
-
-  find wikidir/ -type f -name '*.mdwn' -print0 | xargs -0 ikiwiki-transition prefix_directives
+  ikiwiki-transition.
 
   Even with prefix_directives disabled, ikiwiki now allows an optional '!'
   prefix on preprocessor directives (but still requires a space).  Thus, a
index 3a3529454690ad251ab69db007ac27cbe2c98609..18836d5f5745dc3f4184b857c9fdca124b92ead2 100644 (file)
@@ -12,16 +12,15 @@ ikiwiki-transition type ...
 change in ikiwiki syntax. It also handles other transitions not involving
 wiki pages.
 
-# prefix_directives file ...
+# prefix_directives your.setup
 
-The `prefix_directives` mode converts the specified ikiwiki page from
-the old preprocessor directive syntax, requiring a space, to the new
-syntax, prefixed by '!'.
+The `prefix_directives` mode converts all pages from the old preprocessor
+directive syntax, requiring a space, to the new syntax, prefixed by '!'.
 
 Preprocessor directives which already use the new syntax will remain
 unchanged.
 
-Note that if the page contains wiki links with spaces, which some
+Note that if a page contains wiki links with spaces, which some
 older versions of ikiwiki accepted, the prefix_directives transition will
 treat these as preprocessor directives and convert them.
 
index cb7571289f208f029c8129822406a4f07fdf7105..8992fad0142ec91c4ff4345722423e3c9972b203 100644 (file)
@@ -486,7 +486,7 @@ use the following hashes, using a page name as the key:
   destination file.
 * `%pagesources` contains the name of the source file for each page.
 
-Also, the %IkiWiki::version variable contains the version number for the
+Also, the `%IkiWiki::version` variable contains the version number for the
 ikiwiki program.
 
 ### Library functions
index 50c4201030511b2aa2de752b48d8e8b54d0e885c..3a515a61f6e0a20672d501e89459e448749dbbd0 100644 (file)
@@ -23,7 +23,7 @@ your wiki is upgraded to 3.0.
 You can move these preferences into the setup file by running
 `ikiwiki-transition moveprefs your.setup`
 
-(Make sure you have converted the setuop file to the new format first.)
+(Make sure you have converted the setup file to the new format first.)
 
 ## prefix directives
 
@@ -37,15 +37,10 @@ following to your setup file:
        
        prefix_directives => 0,
 
-But it's not hard to convert your wiki to the new syntax. You can use
-[[ikiwiki-transition]]. It will convert preprocessor directives in all
-files given on the command line. To convert an entire wiki:
+To convert to the new syntax, run 
+`ikiwiki-transition prefix_directives your.setup`
 
-       find wikidir/ -type f -name '*.mdwn' -print0 | xargs -0 ikiwiki-transition prefix_directives
-
-Be sure to modify the find to list all pages in the wiki if you're using
-other markup than markdown. You will probably want to commit the changes
-when you're done too.
+(And then commit the changes it makes to pages in your srcdir.)
 
 ## GlobLists
 
index 9a5dd1362b6ec936758bf8e1f904d5d90787d5cf..b15d9f46b825a50ddd47bacff59ceb85c33edf2e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -i
+#!/usr/bin/perl
 use warnings;
 use strict;
 use IkiWiki;
@@ -42,11 +42,33 @@ sub handle_directive {
 }
 
 sub prefix_directives {
-       $/=undef; # process whole files at once
-       
-       while (<>) {
-               s{$regex}{handle_directive($1, $2, $3, $4)}eg;
-               print;
+       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);
+               }
        }
 }
 
@@ -109,7 +131,7 @@ sub aggregateinternal {
        require IkiWiki::Plugin::aggregate;
 
        %config = IkiWiki::defaultconfig();
-       IkiWiki::Setup::load();
+       IkiWiki::Setup::load($setup);
        IkiWiki::checkconfig();
 
        IkiWiki::Plugin::aggregate::migrate_to_internal();
@@ -196,12 +218,12 @@ sub moveprefs {
 sub usage {
        print STDERR "Usage: ikiwiki-transition type ...\n";
        print STDERR "Currently supported transition subcommands:\n";
-       print STDERR "\tprefix_directives file ...\n";
-       print STDERR "\tindexdb srcdir\n";
-       print STDERR "\thashpassword srcdir\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 srcdir\n";
+       print STDERR "\tindexdb srcdir\n";
        exit 1;
 }