]> sipb.mit.edu Git - ikiwiki.git/blobdiff - ikiwiki
fix
[ikiwiki.git] / ikiwiki
diff --git a/ikiwiki b/ikiwiki
index 1ac0ce9c0a0cf5880b9713236610cccef829d10e..d1173d399fe330f503c173f916dca2ff5fe1851d 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -1,5 +1,4 @@
 #!/usr/bin/perl -T
-
 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
 
 package IkiWiki;
@@ -9,13 +8,19 @@ use File::Spec;
 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 %inlinepages};
+
+sub usage () { #{{{
+       die "usage: ikiwiki [options] source dest\n";
+} #}}}
 
 sub getconfig () { #{{{
        if (! exists $ENV{WRAPPED_OPTIONS}) {
                %config=(
                        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
-                       wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/,
+                       wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
+                       wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/,
                        wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
                        verbose => 0,
                        wikiname => "wiki",
@@ -27,7 +32,10 @@ sub getconfig () { #{{{
                        historyurl => '',
                        diffurl => '',
                        anonok => 0,
+                       rss => 0,
                        rebuild => 0,
+                       refresh => 0,
+                       getctime => 0,
                        wrapper => undef,
                        wrappermode => undef,
                        srcdir => undef,
@@ -43,9 +51,12 @@ sub getconfig () { #{{{
                        "wikiname=s" => \$config{wikiname},
                        "verbose|v!" => \$config{verbose},
                        "rebuild!" => \$config{rebuild},
+                       "refresh!" => \$config{refresh},
+                       "getctime" => \$config{getctime},
                        "wrappermode=i" => \$config{wrappermode},
                        "svn!" => \$config{svn},
                        "anonok!" => \$config{anonok},
+                       "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
                        "url=s" => \$config{url},
                        "cgiurl=s" => \$config{cgiurl},
@@ -67,8 +78,8 @@ sub getconfig () { #{{{
 
                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();
                }
        }
@@ -82,18 +93,21 @@ sub getconfig () { #{{{
 
 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}) {
-               require IkiWiki::RCS::SVN;
+               require IkiWiki::Rcs::SVN;
                $config{rcs}=1;
        }
        else {
-               require IkiWiki::RCS::Stub;
+               require IkiWiki::Rcs::Stub;
                $config{rcs}=0;
        }
 } #}}}
@@ -106,10 +120,6 @@ sub error ($) { #{{{
        die @_;
 } #}}}
 
-sub usage () { #{{{
-       die "usage: ikiwiki [options] source dest\n";
-} #}}}
-
 sub possibly_foolish_untaint ($) { #{{{
        my $tainted=shift;
        my ($untainted)=$tainted=~/(.*)/;
@@ -232,14 +242,35 @@ sub bestlink ($$) { #{{{
 sub isinlinableimage ($) { #{{{
        my $file=shift;
        
-       $file=~/\.(png|gif|jpg|jpeg)$/;
+       $file=~/\.(png|gif|jpg|jpeg)$/i;
+} #}}}
+
+sub pagetitle ($) { #{{{
+       my $page=shift;
+       $page=~s/__(\d+)__/&#$1;/g;
+       $page=~y/_/ /;
+       return $page;
+} #}}}
+
+sub titlepage ($) { #{{{
+       my $title=shift;
+       $title=~y/ /_/;
+       $title=~s/([^-A-Za-z0-9_:+\/.])/"__".ord($1)."__"/eg;
+       return $title;
 } #}}}
 
-sub htmllink ($$;$$) { #{{{
+sub cgiurl (@) { #{{{
+       my %params=@_;
+
+       return $config{cgiurl}."?".join("&", map "$_=$params{$_}", keys %params);
+} #}}}
+
+sub htmllink ($$;$$$) { #{{{
        my $page=shift;
        my $link=shift;
        my $noimageinline=shift; # don't turn links into inline html images
        my $forcesubpage=shift; # force a link to a subpage
+       my $linktext=shift; # set to force the link text to something
 
        my $bestlink;
        if (! $forcesubpage) {
@@ -249,7 +280,9 @@ sub htmllink ($$;$$) { #{{{
                $bestlink="$page/".lc($link);
        }
 
-       return $link if length $bestlink && $page eq $bestlink;
+       $linktext=pagetitle(basename($link)) unless defined $linktext;
+       
+       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
@@ -259,15 +292,17 @@ sub htmllink ($$;$$) { #{{{
                $bestlink=htmlpage($bestlink);
        }
        if (! grep { $_ eq $bestlink } values %renderedfiles) {
-               return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
+               return "<span><a href=\"".
+                       cgiurl(do => "create", page => $link, from =>$page).
+                       "\">?</a>$linktext</span>"
        }
        
        $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
        
        if (! $noimageinline && isinlinableimage($bestlink)) {
-               return "<img src=\"$bestlink\">";
+               return "<img src=\"$bestlink\" alt=\"$linktext\">";
        }
-       return "<a href=\"$bestlink\">$link</a>";
+       return "<a href=\"$bestlink\">$linktext</a>";
 } #}}}
 
 sub indexlink () { #{{{
@@ -303,13 +338,26 @@ sub loadindex () { #{{{
        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;
+               }
+
+               next unless exists $items{src}; # skip bad lines for now
+
+               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}}];
+                       $inlinepages{$page}=join(" ", @{$items{inlinepage}})
+                               if exists $items{inlinepage};
+                       $renderedfiles{$page}=$items{dest}[0];
+               }
+               $pagectime{$page}=$items{ctime}[0];
        }
        close IN;
 } #}}}
@@ -321,9 +369,16 @@ sub saveindex () { #{{{
        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};
+               next unless $oldpagemtime{$page};
+               my $line="mtime=$oldpagemtime{$page} ".
+                       "ctime=$pagectime{$page} ".
+                       "src=$pagesources{$page} ".
+                       "dest=$renderedfiles{$page}";
+               $line.=" link=$_" foreach @{$links{$page}};
+               if (exists $inlinepages{$page}) {
+                       $line.=" inlinepage=$_" foreach split " ", $inlinepages{$page};
+               }
+               print OUT $line."\n";
        }
        close OUT;
 } #}}}
@@ -431,7 +486,13 @@ sub globlist_match ($$) { #{{{
 sub main () { #{{{
        getconfig();
        
-       if ($config{setup}) {
+       if ($config{cgi}) {
+               lockwiki();
+               loadindex();
+               require IkiWiki::CGI;
+               cgi();
+       }
+       elsif ($config{setup}) {
                require IkiWiki::Setup;
                setup();
        }
@@ -440,16 +501,12 @@ sub main () { #{{{
                require IkiWiki::Wrapper;
                gen_wrapper();
        }
-       elsif ($config{cgi}) {
-               lockwiki();
-               require IkiWiki::CGI;
-               cgi();
-       }
        else {
                lockwiki();
-               loadindex() unless $config{rebuild};
+               loadindex();
                require IkiWiki::Render;
                rcs_update();
+               rcs_getctime() if $config{getctime};
                refresh();
                saveindex();
        }