]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - ikiwiki
preserve ctimes across rebuilds
[git.ikiwiki.info.git] / ikiwiki
diff --git a/ikiwiki b/ikiwiki
index 42724331255fcc4ecc4b2c3d906493efd7ac8d40..87414ab5b8e03ea479d34f2830f60e94b2c376b4 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -8,7 +8,8 @@ use File::Spec;
 use HTML::Template;
 use lib '.'; # For use without installation, removed by Makefile.
 
 use HTML::Template;
 use lib '.'; # For use without installation, removed by Makefile.
 
-use vars qw{%config %links %oldlinks %oldpagemtime %renderedfiles %pagesources};
+use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
+            %renderedfiles %pagesources};
 
 sub usage () { #{{{
        die "usage: ikiwiki [options] source dest\n";
 
 sub usage () { #{{{
        die "usage: ikiwiki [options] source dest\n";
@@ -19,7 +20,7 @@ sub getconfig () { #{{{
                %config=(
                        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
                        wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/,
                %config=(
                        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
                        wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/,
-                       wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
+                       wiki_file_regexp => qr/(^[-A-Za-z0-9_.\&;:\/+]+$)/,
                        verbose => 0,
                        wikiname => "wiki",
                        default_pageext => ".mdwn",
                        verbose => 0,
                        wikiname => "wiki",
                        default_pageext => ".mdwn",
@@ -30,6 +31,7 @@ sub getconfig () { #{{{
                        historyurl => '',
                        diffurl => '',
                        anonok => 0,
                        historyurl => '',
                        diffurl => '',
                        anonok => 0,
+                       rss => 0,
                        rebuild => 0,
                        wrapper => undef,
                        wrappermode => undef,
                        rebuild => 0,
                        wrapper => undef,
                        wrappermode => undef,
@@ -49,6 +51,7 @@ sub getconfig () { #{{{
                        "wrappermode=i" => \$config{wrappermode},
                        "svn!" => \$config{svn},
                        "anonok!" => \$config{anonok},
                        "wrappermode=i" => \$config{wrappermode},
                        "svn!" => \$config{svn},
                        "anonok!" => \$config{anonok},
+                       "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
                        "url=s" => \$config{url},
                        "cgiurl=s" => \$config{cgiurl},
                        "cgi!" => \$config{cgi},
                        "url=s" => \$config{url},
                        "cgiurl=s" => \$config{cgiurl},
@@ -70,8 +73,8 @@ sub getconfig () { #{{{
 
                if (! $config{setup}) {
                        usage() unless @ARGV == 2;
 
                if (! $config{setup}) {
                        usage() unless @ARGV == 2;
-                       $config{srcdir} = possibly_foolish_untaint(shift);
-                       $config{destdir} = possibly_foolish_untaint(shift);
+                       $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
+                       $config{destdir} = possibly_foolish_untaint(shift @ARGV);
                        checkconfig();
                }
        }
                        checkconfig();
                }
        }
@@ -85,18 +88,21 @@ sub getconfig () { #{{{
 
 sub checkconfig () { #{{{
        if ($config{cgi} && ! length $config{url}) {
 
 sub checkconfig () { #{{{
        if ($config{cgi} && ! length $config{url}) {
-               error("Must specify url to wiki with --url when using --cgi");
+               error("Must specify url to wiki with --url when using --cgi\n");
+       }
+       if ($config{rss} && ! length $config{url}) {
+               error("Must specify url to wiki with --url when using --rss\n");
        }
        
        $config{wikistatedir}="$config{srcdir}/.ikiwiki"
                unless exists $config{wikistatedir};
        
        if ($config{svn}) {
        }
        
        $config{wikistatedir}="$config{srcdir}/.ikiwiki"
                unless exists $config{wikistatedir};
        
        if ($config{svn}) {
-               require IkiWiki::RCS::SVN;
+               require IkiWiki::Rcs::SVN;
                $config{rcs}=1;
        }
        else {
                $config{rcs}=1;
        }
        else {
-               require IkiWiki::RCS::Stub;
+               require IkiWiki::Rcs::Stub;
                $config{rcs}=0;
        }
 } #}}}
                $config{rcs}=0;
        }
 } #}}}
@@ -234,6 +240,13 @@ sub isinlinableimage ($) { #{{{
        $file=~/\.(png|gif|jpg|jpeg)$/;
 } #}}}
 
        $file=~/\.(png|gif|jpg|jpeg)$/;
 } #}}}
 
+sub pagetitle ($) { #{{{
+       my $page=shift;
+       $page=~s/__(\d+)__/&#$1;/g;
+       $page=~y/_/ /;
+       return $page;
+} #}}}
+
 sub htmllink ($$;$$) { #{{{
        my $page=shift;
        my $link=shift;
 sub htmllink ($$;$$) { #{{{
        my $page=shift;
        my $link=shift;
@@ -248,7 +261,9 @@ sub htmllink ($$;$$) { #{{{
                $bestlink="$page/".lc($link);
        }
 
                $bestlink="$page/".lc($link);
        }
 
-       return $link if length $bestlink && $page eq $bestlink;
+       my $linktext=pagetitle($link);
+       
+       return $linktext if length $bestlink && $page eq $bestlink;
        
        # TODO BUG: %renderedfiles may not have it, if the linked to page
        # was also added and isn't yet rendered! Note that this bug is
        
        # TODO BUG: %renderedfiles may not have it, if the linked to page
        # was also added and isn't yet rendered! Note that this bug is
@@ -258,7 +273,7 @@ sub htmllink ($$;$$) { #{{{
                $bestlink=htmlpage($bestlink);
        }
        if (! grep { $_ eq $bestlink } values %renderedfiles) {
                $bestlink=htmlpage($bestlink);
        }
        if (! grep { $_ eq $bestlink } values %renderedfiles) {
-               return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
+               return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$linktext"
        }
        
        $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
        }
        
        $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
@@ -266,7 +281,7 @@ sub htmllink ($$;$$) { #{{{
        if (! $noimageinline && isinlinableimage($bestlink)) {
                return "<img src=\"$bestlink\">";
        }
        if (! $noimageinline && isinlinableimage($bestlink)) {
                return "<img src=\"$bestlink\">";
        }
-       return "<a href=\"$bestlink\">$link</a>";
+       return "<a href=\"$bestlink\">$linktext</a>";
 } #}}}
 
 sub indexlink () { #{{{
 } #}}}
 
 sub indexlink () { #{{{
@@ -302,13 +317,22 @@ sub loadindex () { #{{{
        while (<IN>) {
                $_=possibly_foolish_untaint($_);
                chomp;
        while (<IN>) {
                $_=possibly_foolish_untaint($_);
                chomp;
-               my ($mtime, $file, $rendered, @links)=split(' ', $_);
-               my $page=pagename($file);
-               $pagesources{$page}=$file;
-               $oldpagemtime{$page}=$mtime;
-               $oldlinks{$page}=[@links];
-               $links{$page}=[@links];
-               $renderedfiles{$page}=$rendered;
+               my %items;
+               $items{link}=[];
+               foreach my $i (split(/ /, $_)) {
+                       my ($item, $val)=split(/=/, $i, 2);
+                       push @{$items{$item}}, $val;
+               }
+
+               my $page=pagename($items{src}[0]);
+               if (! $config{rebuild}) {
+                       $pagesources{$page}=$items{src}[0];
+                       $oldpagemtime{$page}=$items{mtime}[0];
+                       $oldlinks{$page}=[@{$items{link}}];
+                       $links{$page}=[@{$items{link}}];
+                       $renderedfiles{$page}=$items{dest}[0];
+               }
+               $pagectime{$page}=$items{ctime}[0];
        }
        close IN;
 } #}}}
        }
        close IN;
 } #}}}
@@ -320,9 +344,14 @@ sub saveindex () { #{{{
        open (OUT, ">$config{wikistatedir}/index") || 
                error("cannot write to $config{wikistatedir}/index: $!");
        foreach my $page (keys %oldpagemtime) {
        open (OUT, ">$config{wikistatedir}/index") || 
                error("cannot write to $config{wikistatedir}/index: $!");
        foreach my $page (keys %oldpagemtime) {
-               print OUT "$oldpagemtime{$page} $pagesources{$page} $renderedfiles{$page} ".
-                       join(" ", @{$links{$page}})."\n"
-                               if $oldpagemtime{$page};
+               my $line="mtime=$oldpagemtime{$page} ".
+                       "ctime=$pagectime{$page} ".
+                       "src=$pagesources{$page} ".
+                       "dest=$renderedfiles{$page}";
+               if ($oldpagemtime{$page}) {
+                       $line.=" link=$_" foreach @{$links{$page}};
+               }
+               print OUT $line."\n";
        }
        close OUT;
 } #}}}
        }
        close OUT;
 } #}}}
@@ -446,7 +475,7 @@ sub main () { #{{{
        }
        else {
                lockwiki();
        }
        else {
                lockwiki();
-               loadindex() unless $config{rebuild};
+               loadindex();
                require IkiWiki::Render;
                rcs_update();
                refresh();
                require IkiWiki::Render;
                rcs_update();
                refresh();