fix Discussion links to not take the BestLink.
[ikiwiki.git] / ikiwiki
diff --git a/ikiwiki b/ikiwiki
index 4e64e4031d0d5996f68d072d4bac06e6a3aa4da4..53a86c1edc3ef5f3d4498fa2a55d559e8887df3a 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -69,11 +69,8 @@ sub error { #{{{
        if ($config{cgi}) {
                print "Content-type: text/html\n\n";
                print misctemplate("Error", "<p>Error: @_</p>");
-               exit 1;
-       }
-       else {
-               die @_;
        }
+       die @_;
 } #}}}
 
 sub debug ($) { #{{{
@@ -172,7 +169,7 @@ sub findlinks ($) { #{{{
        my $content=shift;
 
        my @links;
-       while ($content =~ /$config{wiki_link_regexp}/g) {
+       while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
                push @links, lc($1);
        }
        return @links;
@@ -213,9 +210,15 @@ sub htmllink { #{{{
        my $page=shift;
        my $link=shift;
        my $noimageinline=shift; # don't turn links into inline html images
-       my $createsubpage=shift; # force creation of a subpage if page DNE
+       my $forcesubpage=shift; # force a link to a subpage
 
-       my $bestlink=bestlink($page, $link);
+       my $bestlink;
+       if (! $forcesubpage) {
+               $bestlink=bestlink($page, $link);
+       }
+       else {
+               $bestlink="$page/".lc($link);
+       }
 
        return $link if length $bestlink && $page eq $bestlink;
        
@@ -227,12 +230,7 @@ sub htmllink { #{{{
                $bestlink=htmlpage($bestlink);
        }
        if (! grep { $_ eq $bestlink } values %renderedfiles) {
-               if (! $createsubpage) {
-                       return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
-               }
-               else {
-                       return "<a href=\"$config{cgiurl}?do=create&page=$page/$link\">?</a>$link"
-               }
+               return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
        }
        
        $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
@@ -247,7 +245,9 @@ sub linkify ($$) { #{{{
        my $content=shift;
        my $file=shift;
 
-       $content =~ s/$config{wiki_link_regexp}/htmllink(pagename($file), $1)/eg;
+       $content =~ s{(\\?)$config{wiki_link_regexp}}{
+               $1 ? "[[$2]]" : htmllink(pagename($file), $2)
+       }eg;
        
        return $content;
 } #}}}
@@ -305,14 +305,14 @@ sub parentlinks ($) { #{{{
        my $skip=1;
        foreach my $dir (reverse split("/", $page)) {
                if (! $skip) {
+                       $path.="../";
                        unshift @ret, { url => "$path$dir.html", page => $dir };
                }
                else {
                        $skip=0;
                }
-               $path.="../";
        }
-       unshift @ret, { url => $path , page => $config{wikiname} };
+       unshift @ret, { url => length $path ? $path : ".", page => $config{wikiname} };
        return @ret;
 } #}}}
 
@@ -362,10 +362,10 @@ sub check_overwrite ($$) { #{{{
        my $src=shift;
        
        if (! exists $renderedfiles{$src} && -e $dest && ! $config{rebuild}) {
-               error("$dest exists and was rendered from ".
+               error("$dest already exists and was rendered from ".
                        join(" ",(grep { $renderedfiles{$_} eq $dest } keys
                                %renderedfiles)).
-                       ", not from $src before not overwriting");
+                       ", before, so not rendering from $src");
        }
 } #}}}
                
@@ -690,7 +690,7 @@ sub gen_wrapper (@) { #{{{
        push @params, "--cgiurl=$config{cgiurl}" if length $config{cgiurl};
        push @params, "--historyurl=$config{historyurl}" if length $config{historyurl};
        push @params, "--anonok" if $config{anonok};
-       my $params=join(" ", map { "\'$_\'" } @params);
+       my $params=join(" ", @params);
        my $call='';
        foreach my $p ($this, $this, @params) {
                $call.=qq{"$p", };
@@ -1094,7 +1094,9 @@ sub cgi_editpage ($$) { #{{{
                        rcs_commit($message);
                }
                else {
+                       loadindex();
                        refresh();
+                       saveindex();
                }
                
                # The trailing question mark tries to avoid broken
@@ -1150,14 +1152,28 @@ sub cgi () { #{{{
 
 sub setup () { # {{{
        my $setup=possibly_foolish_untaint($config{setup});
+       delete $config{setup};
        open (IN, $setup) || error("read $setup: $!\n");
        local $/=undef;
        my $code=<IN>;
        ($code)=$code=~/(.*)/s;
        close IN;
+
+       my (%setup);
        eval $code;
        error($@) if $@;
-       print "ikiwiki setup complete\n";
+       
+       gen_wrapper(%config, %setup, %{$setup{cgiwrapper}}) if $setup{cgiwrapper};
+       gen_wrapper(%config, %setup, %{$setup{svnwrapper}}) if $setup{svnwrapper};
+       
+       print "$setup{wikiname} setup complete, now forcing a rebuild\n";
+       foreach my $c (keys %setup) {
+               $config{$c}=possibly_foolish_untaint($setup{$c})
+                       if defined $setup{$c} && ! ref $setup{$c};
+       }
+       $config{rebuild}=1;
+       refresh();
+       saveindex();
        exit;
 } #}}}