]> 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 62a9767b9346bbad0cc4bd8a8c1ab4c3db6f6cb9..2dbb42bc483a042d3231685fc57c9ede74bea9d0 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -18,15 +18,16 @@ sub usage () { #{{{
 sub getconfig () { #{{{
        if (! exists $ENV{WRAPPED_OPTIONS}) {
                %config=(
 sub getconfig () { #{{{
        if (! exists $ENV{WRAPPED_OPTIONS}) {
                %config=(
-                       wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
+                       wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
                        wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
                        wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/,
                        wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
                        wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/,
-                       wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
+                       wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
                        verbose => 0,
                        wikiname => "wiki",
                        default_pageext => ".mdwn",
                        cgi => 0,
                        svn => 1,
                        verbose => 0,
                        wikiname => "wiki",
                        default_pageext => ".mdwn",
                        cgi => 0,
                        svn => 1,
+                       notify => 0,
                        url => '',
                        cgiurl => '',
                        historyurl => '',
                        url => '',
                        cgiurl => '',
                        historyurl => '',
@@ -36,13 +37,18 @@ sub getconfig () { #{{{
                        rebuild => 0,
                        refresh => 0,
                        getctime => 0,
                        rebuild => 0,
                        refresh => 0,
                        getctime => 0,
+                       hyperestraier => 0,
                        wrapper => undef,
                        wrappermode => undef,
                        wrapper => undef,
                        wrappermode => undef,
+                       svnrepo => undef,
+                       svnpath => "trunk",
                        srcdir => undef,
                        destdir => undef,
                        templatedir => "/usr/share/ikiwiki/templates",
                        srcdir => undef,
                        destdir => undef,
                        templatedir => "/usr/share/ikiwiki/templates",
+                       underlaydir => "/usr/share/ikiwiki/basewiki",
                        setup => undef,
                        adminuser => undef,
                        setup => undef,
                        adminuser => undef,
+                       adminemail => undef,
                );
 
                eval q{use Getopt::Long};
                );
 
                eval q{use Getopt::Long};
@@ -56,12 +62,17 @@ sub getconfig () { #{{{
                        "wrappermode=i" => \$config{wrappermode},
                        "svn!" => \$config{svn},
                        "anonok!" => \$config{anonok},
                        "wrappermode=i" => \$config{wrappermode},
                        "svn!" => \$config{svn},
                        "anonok!" => \$config{anonok},
+                       "hyperestraier" => \$config{hyperestraier},
                        "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
                        "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
+                       "notify!" => \$config{notify},
                        "url=s" => \$config{url},
                        "cgiurl=s" => \$config{cgiurl},
                        "historyurl=s" => \$config{historyurl},
                        "diffurl=s" => \$config{diffurl},
                        "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]/;
                        },
                        "exclude=s@" => sub {
                                $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
                        },
@@ -71,6 +82,9 @@ sub getconfig () { #{{{
                        "templatedir=s" => sub {
                                $config{templatedir}=possibly_foolish_untaint($_[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"
                        },
                        "wrapper:s" => sub {
                                $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
                        },
@@ -98,6 +112,9 @@ sub checkconfig () { #{{{
        if ($config{rss} && ! length $config{url}) {
                error("Must specify url to wiki with --url when using --rss\n");
        }
        if ($config{rss} && ! length $config{url}) {
                error("Must specify url to wiki with --url when using --rss\n");
        }
+       if ($config{hyperestraier} && ! length $config{url}) {
+               error("Must specify --url when using --hyperestraier\n");
+       }
        
        $config{wikistatedir}="$config{srcdir}/.ikiwiki"
                unless exists $config{wikistatedir};
        
        $config{wikistatedir}="$config{srcdir}/.ikiwiki"
                unless exists $config{wikistatedir};
@@ -139,14 +156,14 @@ sub debug ($) { #{{{
 sub basename ($) { #{{{
        my $file=shift;
 
 sub basename ($) { #{{{
        my $file=shift;
 
-       $file=~s!.*/!!;
+       $file=~s!.*/+!!;
        return $file;
 } #}}}
 
 sub dirname ($) { #{{{
        my $file=shift;
 
        return $file;
 } #}}}
 
 sub dirname ($) { #{{{
        my $file=shift;
 
-       $file=~s!/?[^/]+$!!;
+       $file=~s!/*[^/]+$!!;
        return $file;
 } #}}}
 
        return $file;
 } #}}}
 
@@ -176,29 +193,45 @@ sub htmlpage ($) { #{{{
        return $page.".html";
 } #}}}
 
        return $page.".html";
 } #}}}
 
-sub readfile ($) { #{{{
+sub srcfile ($) { #{{{
+       my $file=shift;
+
+       return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
+       return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
+       error("internal error: $file cannot be found");
+} #}}}
+
+sub readfile ($;$) { #{{{
        my $file=shift;
        my $file=shift;
+       my $binary=shift;
 
        if (-l $file) {
                error("cannot read a symlink ($file)");
        }
        
        local $/=undef;
 
        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;
 } #}}}
 
        my $ret=<IN>;
        close IN;
        return $ret;
 } #}}}
 
-sub writefile ($$) { #{{{
-       my $file=shift;
+sub writefile ($$$;$) { #{{{
+       my $file=shift; # can include subdirs
+       my $destdir=shift; # directory to put file in
        my $content=shift;
        my $content=shift;
+       my $binary=shift;
        
        
-       if (-l $file) {
-               error("cannot write to a symlink ($file)");
+       my $test=$file;
+       while (length $test) {
+               if (-l "$destdir/$test") {
+                       error("cannot write to a symlink ($test)");
+               }
+               $test=dirname($test);
        }
 
        }
 
-       my $dir=dirname($file);
+       my $dir=dirname("$destdir/$file");
        if (! -d $dir) {
                my $d="";
                foreach my $s (split(m!/+!, $dir)) {
        if (! -d $dir) {
                my $d="";
                foreach my $s (split(m!/+!, $dir)) {
@@ -209,7 +242,8 @@ sub writefile ($$) { #{{{
                }
        }
        
                }
        }
        
-       open (OUT, ">$file") || error("failed to write $file: $!");
+       open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
+       binmode(OUT) if $binary;
        print OUT $content;
        close OUT;
 } #}}}
        print OUT $content;
        close OUT;
 } #}}}
@@ -255,7 +289,7 @@ sub pagetitle ($) { #{{{
 sub titlepage ($) { #{{{
        my $title=shift;
        $title=~y/ /_/;
 sub titlepage ($) { #{{{
        my $title=shift;
        $title=~y/ /_/;
-       $title=~s/([^-A-Za-z0-9_:+\/])/"__".ord($1)."__"/eg;
+       $title=~s/([^-[:alnum:]_:+\/.])/"__".ord($1)."__"/eg;
        return $title;
 } #}}}
 
        return $title;
 } #}}}
 
@@ -265,6 +299,16 @@ sub cgiurl (@) { #{{{
        return $config{cgiurl}."?".join("&amp;", map "$_=$params{$_}", keys %params);
 } #}}}
 
        return $config{cgiurl}."?".join("&amp;", map "$_=$params{$_}", keys %params);
 } #}}}
 
+sub styleurl (;$) { #{{{
+       my $page=shift;
+
+       return "$config{url}/style.css" if ! defined $page;
+       
+       $page=~s/[^\/]+$//;
+       $page=~s/[^\/]+\//..\//g;
+       return $page."style.css";
+} #}}}
+
 sub htmllink ($$;$$$) { #{{{
        my $page=shift;
        my $link=shift;
 sub htmllink ($$;$$$) { #{{{
        my $page=shift;
        my $link=shift;
@@ -300,7 +344,7 @@ sub htmllink ($$;$$$) { #{{{
        $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
        
        if (! $noimageinline && isinlinableimage($bestlink)) {
        $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
        
        if (! $noimageinline && isinlinableimage($bestlink)) {
-               return "<img src=\"$bestlink\" alt=\"$linktext\">";
+               return "<img src=\"$bestlink\" alt=\"$linktext\" />";
        }
        return "<a href=\"$bestlink\">$linktext</a>";
 } #}}}
        }
        return "<a href=\"$bestlink\">$linktext</a>";
 } #}}}
@@ -395,65 +439,12 @@ sub misctemplate ($$) { #{{{
                indexlink => indexlink(),
                wikiname => $config{wikiname},
                pagebody => $pagebody,
                indexlink => indexlink(),
                wikiname => $config{wikiname},
                pagebody => $pagebody,
+               styleurl => styleurl(),
+               baseurl => "$config{url}/",
        );
        return $template->output;
 }#}}}
 
        );
        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;
 sub glob_match ($$) { #{{{
        my $page=shift;
        my $glob=shift;
@@ -506,6 +497,7 @@ sub main () { #{{{
                loadindex();
                require IkiWiki::Render;
                rcs_update();
                loadindex();
                require IkiWiki::Render;
                rcs_update();
+               rcs_notify() if $config{notify};
                rcs_getctime() if $config{getctime};
                refresh();
                saveindex();
                rcs_getctime() if $config{getctime};
                refresh();
                saveindex();