]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - ikiwiki
web commit by joey
[git.ikiwiki.info.git] / ikiwiki
diff --git a/ikiwiki b/ikiwiki
index 8eebcdf77e90f48a3c6c74087408e3d836c81369..8367e9118df42901e0f18e3c0ecf4adccc24eff3 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -9,7 +9,7 @@ use HTML::Template;
 use lib '.'; # For use without installation, removed by Makefile.
 
 use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
-            %renderedfiles %pagesources %inlinepages};
+            %renderedfiles %pagesources %depends %plugins};
 
 sub usage () { #{{{
        die "usage: ikiwiki [options] source dest\n";
@@ -20,31 +20,37 @@ sub getconfig () { #{{{
                %config=(
                        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
                        wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
-                       wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/,
-                       wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
+                       wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/,
+                       wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
                        verbose => 0,
                        wikiname => "wiki",
                        default_pageext => ".mdwn",
                        cgi => 0,
                        svn => 1,
+                       notify => 0,
                        url => '',
                        cgiurl => '',
                        historyurl => '',
                        diffurl => '',
                        anonok => 0,
                        rss => 0,
+                       sanitize => 1,
                        rebuild => 0,
                        refresh => 0,
                        getctime => 0,
                        hyperestraier => 0,
                        wrapper => undef,
                        wrappermode => undef,
+                       svnrepo => undef,
+                       svnpath => "trunk",
                        srcdir => undef,
                        destdir => undef,
                        templatedir => "/usr/share/ikiwiki/templates",
                        underlaydir => "/usr/share/ikiwiki/basewiki",
                        setup => undef,
                        adminuser => undef,
+                       adminemail => undef,
+                       plugin => [qw{inline}],
                );
 
                eval q{use Getopt::Long};
@@ -61,10 +67,15 @@ sub getconfig () { #{{{
                        "hyperestraier" => \$config{hyperestraier},
                        "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
+                       "notify!" => \$config{notify},
+                       "sanitize!" => \$config{sanitize},
                        "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},
                        "exclude=s@" => sub {
                                $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
                        },
@@ -80,6 +91,9 @@ sub getconfig () { #{{{
                        "wrapper:s" => sub {
                                $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
                        },
+                       "plugin=s@" => sub {
+                               push @{$config{plugin}}, $_[1];
+                       }
                ) || usage();
 
                if (! $config{setup}) {
@@ -119,6 +133,14 @@ sub checkconfig () { #{{{
                require IkiWiki::Rcs::Stub;
                $config{rcs}=0;
        }
+
+       foreach my $plugin (@{$config{plugin}}) {
+               my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
+               eval qq{use $mod};
+               if ($@) {
+                       error("Failed to load plugin $mod: $@");
+               }
+       }
 } #}}}
 
 sub error ($) { #{{{
@@ -148,14 +170,14 @@ sub debug ($) { #{{{
 sub basename ($) { #{{{
        my $file=shift;
 
-       $file=~s!.*/!!;
+       $file=~s!.*/+!!;
        return $file;
 } #}}}
 
 sub dirname ($) { #{{{
        my $file=shift;
 
-       $file=~s!/?[^/]+$!!;
+       $file=~s!/*[^/]+$!!;
        return $file;
 } #}}}
 
@@ -193,24 +215,27 @@ sub srcfile ($) { #{{{
        error("internal error: $file cannot be found");
 } #}}}
 
-sub readfile ($) { #{{{
+sub readfile ($;$) { #{{{
        my $file=shift;
+       my $binary=shift;
 
        if (-l $file) {
                error("cannot read a symlink ($file)");
        }
        
        local $/=undef;
-       open (IN, "$file") || error("failed to read $file: $!");
+       open (IN, $file) || error("failed to read $file: $!");
+       binmode(IN) if $binary;
        my $ret=<IN>;
        close IN;
        return $ret;
 } #}}}
 
-sub writefile ($$$) { #{{{
+sub writefile ($$$;$) { #{{{
        my $file=shift; # can include subdirs
        my $destdir=shift; # directory to put file in
        my $content=shift;
+       my $binary=shift;
        
        my $test=$file;
        while (length $test) {
@@ -232,6 +257,7 @@ sub writefile ($$$) { #{{{
        }
        
        open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
+       binmode(OUT) if $binary;
        print OUT $content;
        close OUT;
 } #}}}
@@ -277,7 +303,7 @@ sub pagetitle ($) { #{{{
 sub titlepage ($) { #{{{
        my $title=shift;
        $title=~y/ /_/;
-       $title=~s/([^-A-Za-z0-9_:+\/.])/"__".ord($1)."__"/eg;
+       $title=~s/([^-[:alnum:]_:+\/.])/"__".ord($1)."__"/eg;
        return $title;
 } #}}}
 
@@ -385,8 +411,8 @@ sub loadindex () { #{{{
                        $oldpagemtime{$page}=$items{mtime}[0];
                        $oldlinks{$page}=[@{$items{link}}];
                        $links{$page}=[@{$items{link}}];
-                       $inlinepages{$page}=join(" ", @{$items{inlinepage}})
-                               if exists $items{inlinepage};
+                       $depends{$page}=join(" ", @{$items{depends}})
+                               if exists $items{depends};
                        $renderedfiles{$page}=$items{dest}[0];
                }
                $pagectime{$page}=$items{ctime}[0];
@@ -407,8 +433,8 @@ sub saveindex () { #{{{
                        "src=$pagesources{$page} ".
                        "dest=$renderedfiles{$page}";
                $line.=" link=$_" foreach @{$links{$page}};
-               if (exists $inlinepages{$page}) {
-                       $line.=" inlinepage=$_" foreach split " ", $inlinepages{$page};
+               if (exists $depends{$page}) {
+                       $line.=" depends=$_" foreach split " ", $depends{$page};
                }
                print OUT $line."\n";
        }
@@ -428,65 +454,11 @@ sub misctemplate ($$) { #{{{
                wikiname => $config{wikiname},
                pagebody => $pagebody,
                styleurl => styleurl(),
+               baseurl => "$config{url}/",
        );
        return $template->output;
 }#}}}
 
-sub userinfo_get ($$) { #{{{
-       my $user=shift;
-       my $field=shift;
-
-       eval q{use Storable};
-       my $userdata=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
-       if (! defined $userdata || ! ref $userdata || 
-           ! exists $userdata->{$user} || ! ref $userdata->{$user} ||
-            ! exists $userdata->{$user}->{$field}) {
-               return "";
-       }
-       return $userdata->{$user}->{$field};
-} #}}}
-
-sub userinfo_set ($$$) { #{{{
-       my $user=shift;
-       my $field=shift;
-       my $value=shift;
-       
-       eval q{use Storable};
-       my $userdata=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
-       if (! defined $userdata || ! ref $userdata || 
-           ! exists $userdata->{$user} || ! ref $userdata->{$user}) {
-               return "";
-       }
-       
-       $userdata->{$user}->{$field}=$value;
-       my $oldmask=umask(077);
-       my $ret=Storable::lock_store($userdata, "$config{wikistatedir}/userdb");
-       umask($oldmask);
-       return $ret;
-} #}}}
-
-sub userinfo_setall ($$) { #{{{
-       my $user=shift;
-       my $info=shift;
-       
-       eval q{use Storable};
-       my $userdata=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
-       if (! defined $userdata || ! ref $userdata) {
-               $userdata={};
-       }
-       $userdata->{$user}=$info;
-       my $oldmask=umask(077);
-       my $ret=Storable::lock_store($userdata, "$config{wikistatedir}/userdb");
-       umask($oldmask);
-       return $ret;
-} #}}}
-
-sub is_admin ($) { #{{{
-       my $user_name=shift;
-
-       return grep { $_ eq $user_name } @{$config{adminuser}};
-} #}}}
-
 sub glob_match ($$) { #{{{
        my $page=shift;
        my $glob=shift;
@@ -516,6 +488,14 @@ sub globlist_match ($$) { #{{{
        return 0;
 } #}}}
 
+sub register_plugin ($$$) { # {{{
+       my $type=shift;
+       my $command=shift;
+       my $function=shift;
+       
+       $plugins{$type}{$command}=$function;
+} # }}}
+
 sub main () { #{{{
        getconfig();
        
@@ -541,6 +521,7 @@ sub main () { #{{{
                rcs_update();
                rcs_getctime() if $config{getctime};
                refresh();
+               rcs_notify() if $config{notify};
                saveindex();
        }
 } #}}}