if ($config{cgi}) {
print "Content-type: text/html\n\n";
print misctemplate("Error", "<p>Error: @_</p>");
- exit 1;
- }
- else {
- die @_;
}
+ die @_;
} #}}}
sub debug ($) { #{{{
close OUT;
} #}}}
-sub findlinks ($) { #{{{
+sub findlinks ($$) { #{{{
my $content=shift;
+ my $page=shift;
my @links;
while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
push @links, lc($1);
}
- return @links;
+ # Discussion links are a special case since they're not in the text
+ # of the page, but on its template.
+ return @links, "$page/discussion";
} #}}}
sub bestlink ($$) { #{{{
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;
$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));
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;
} #}}}
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");
}
} #}}}
if ($type ne 'unknown') {
my $page=pagename($file);
- $links{$page}=[findlinks($content)];
+ $links{$page}=[findlinks($content, $page)];
$content=linkify($content, $file);
$content=htmlize($type, $content);
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", };
}
my @page_locs;
+ my $best_loc;
my ($from)=$form->param('from')=~/$config{wiki_file_regexp}/;
if (! defined $from || ! length $from ||
$from ne $form->param('from') ||
$from=~/$config{wiki_file_prune_regexp}/ || $from=~/^\//) {
- @page_locs=$page;
+ @page_locs=$best_loc=$page;
}
else {
my $dir=$from."/";
$dir=~s![^/]+/$!!;
push @page_locs, $dir.$page;
push @page_locs, "$from/$page";
+ $best_loc="$from/$page";
while (length $dir) {
$dir=~s![^/]+/$!!;
push @page_locs, $dir.$page;
}
+
+ @page_locs = grep { ! exists
+ $pagesources{lc($_)} } @page_locs;
}
$form->tmpl_param("page_select", 1);
$form->field(name => "page", type => 'select',
- options => \@page_locs);
+ options => \@page_locs, value => $best_loc);
$form->title("creating $page");
}
elsif ($form->field("do") eq "edit") {
rcs_commit($message);
}
else {
+ loadindex();
refresh();
+ saveindex();
}
# The trailing question mark tries to avoid broken