-}
-
-my $link=qr/\[\[([^\s]+)\]\]/;
-my $verbose=0;
-my $rebuild=0;
-my $wikiname="wiki";
-if (grep /^-/, @ARGV) {
- eval {use Getopt::Long};
- GetOptions(
- "wikiname=s" => \$wikiname,
- "verbose|v" => \$verbose,
- "rebuild" => \$rebuild,
- ) || usage();
-}
-usage() unless @ARGV == 2;
-my ($srcdir) = shift =~ /(.*)/; # untaint
-my ($destdir) = shift =~ /(.*)/; # untaint
-
-my %links;
-my %oldlinks;
-my %oldpagemtime;
-my %renderedfiles;
-my %pagesources;
-
-sub error ($) {
- die @_;
-}
-
-sub debug ($) {
- print "@_\n" if $verbose;
-}
-
-sub mtime ($) {
- my $page=shift;
-
- return (stat($page))[9];
-}
-
-sub basename {
- my $file=shift;
-
- $file=~s!.*/!!;
- return $file;
-}
-
-sub dirname {
- my $file=shift;
-
- $file=~s!/?[^/]+$!!;
- return $file;
-}
-
-sub pagetype ($) {
- my $page=shift;
-
- if ($page =~ /\.mdwn$/) {
- return ".mdwn";
- }
- else {
- return "unknown";
- }
-}
-
-sub pagename ($) {
- my $file=shift;
-
- my $type=pagetype($file);
- my $page=$file;
- $page=~s/\Q$type\E*$// unless $type eq 'unknown';
- return $page;
-}
-
-sub htmlpage ($) {
- my $page=shift;
-
- return $page.".html";
-}
-
-sub readpage ($) {
- my $page=shift;
-
- local $/=undef;
- open (PAGE, "$srcdir/$page") || error("failed to read $page: $!");
- my $ret=<PAGE>;
- close PAGE;
- return $ret;
-}
-
-sub writepage ($$) {
- my $page=shift;
- my $content=shift;
-
- my $dir=dirname("$destdir/$page");
- if (! -d $dir) {
- my $d="";
- foreach my $s (split(m!/+!, $dir)) {
- $d.="$s/";
- if (! -d $d) {
- mkdir($d) || error("failed to create directory $d: $!");
+} #}}}
+
+sub getconfig () { #{{{
+ if (! exists $ENV{WRAPPED_OPTIONS}) {
+ %config=defaultconfig();
+ eval q{use Getopt::Long};
+ GetOptions(
+ "setup|s=s" => \$config{setup},
+ "wikiname=s" => \$config{wikiname},
+ "verbose|v!" => \$config{verbose},
+ "rebuild!" => \$config{rebuild},
+ "refresh!" => \$config{refresh},
+ "getctime" => \$config{getctime},
+ "wrappermode=i" => \$config{wrappermode},
+ "rcs=s" => \$config{rcs},
+ "no-rcs" => sub { $config{rcs}="" },
+ "anonok!" => \$config{anonok},
+ "rss!" => \$config{rss},
+ "cgi!" => \$config{cgi},
+ "discussion!" => \$config{discussion},
+ "notify!" => \$config{notify},
+ "url=s" => \$config{url},
+ "cgiurl=s" => \$config{cgiurl},
+ "historyurl=s" => \$config{historyurl},
+ "diffurl=s" => \$config{diffurl},
+ "svnrepo" => \$config{svnrepo},
+ "svnpath" => \$config{svnpath},
+ "adminemail=s" => \$config{adminemail},
+ "timeformat=s" => \$config{timeformat},
+ "exclude=s@" => sub {
+ $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
+ },
+ "adminuser=s@" => sub {
+ push @{$config{adminuser}}, $_[1]
+ },
+ "templatedir=s" => sub {
+ $config{templatedir}=possibly_foolish_untaint($_[1])
+ },
+ "underlaydir=s" => sub {
+ $config{underlaydir}=possibly_foolish_untaint($_[1])
+ },
+ "wrapper:s" => sub {
+ $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
+ },
+ "plugin=s@" => sub {
+ push @{$config{plugin}}, $_[1];
+ },
+ "disable-plugin=s@" => sub {
+ $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
+ },
+ "pingurl" => sub {
+ push @{$config{pingurl}}, $_[1];